PatentImage.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <div class="patent-image">
  3. <div class="block">
  4. <div class="demonstration">图片大小:</div>
  5. <el-slider v-model="value" @change="changeWidth" :min="25" :max="100" style="padding-left:90px"></el-slider>
  6. </div>
  7. <div class="imageCard">
  8. <el-card class="preview" v-for="(item, index) in patent.image" :key="index" shadow="hover" :style="{width:width}">
  9. <div slot="header" class="card-header" v-if="projectId">
  10. <span></span>
  11. <el-button :disabled="!$permission('/workspace/details/figureDelete')" class="delete" type="text" @click="handleDelete(item)">删除</el-button>
  12. <el-button :disabled="!$permission('/workspace/details/figuremodify')" class="edit" type="text" @click="handleEdit(item)">编辑</el-button>
  13. </div>
  14. <div class="text-align_center">
  15. <el-image :src="!projectId?item.url:getImagePath(item.url)" :preview-src-list="srcList" style="height: 100%; min-height:125px;"></el-image>
  16. </div>
  17. </el-card>
  18. </div>
  19. <div type="primary" class="up" v-if="$permission('/workspace/details/figureUpdata')&& projectId && $r(projectId,[1,2])" @click="handleAdd">上传图片</div>
  20. <el-dialog :title="title" :visible.sync="visible" width="500px" append-to-body destroy-on-close :before-close="close" top="22vh">
  21. <el-form :model="form">
  22. <el-form-item label="是否设置为摘要附图">
  23. <el-radio-group v-model="form.status">
  24. <el-radio :label="1">是</el-radio>
  25. <el-radio :label="0">否</el-radio>
  26. </el-radio-group>
  27. </el-form-item>
  28. <el-form-item label="上传图片">
  29. <el-upload class="upload-file" drag action="#" :auto-upload="false" :show-file-list="false" :on-change="onChange">
  30. <i :class="!file ? 'el-icon-upload' : 'el-icon-refresh'"></i>
  31. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  32. <div class="el-upload__tip" slot="tip"></div>
  33. </el-upload>
  34. </el-form-item>
  35. </el-form>
  36. <div slot="footer" class="dialog-footer">
  37. <el-button @click="close">取 消</el-button>
  38. <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
  39. </div>
  40. </el-dialog>
  41. </div>
  42. </template>
  43. <script>
  44. import { patentDetails } from './mixins';
  45. export default {
  46. mixins: [patentDetails],
  47. data() {
  48. return {
  49. value:25,
  50. width:"25%",
  51. srcList: [],
  52. url: '',
  53. title: '',
  54. visible: false,
  55. form: {},
  56. file: null,
  57. btnLoading: false
  58. }
  59. },
  60. watch: {
  61. patentId() {
  62. this.srcList = this.patent.image.map(item => this.getImagePath(item.url))
  63. },
  64. 'patent'(){
  65. },
  66. patentNo(){
  67. if(!this.projectId){
  68. this.getData()
  69. }
  70. }
  71. },
  72. mounted() {
  73. if(this.patent.image){
  74. this.srcList = this.patent.image.map(item => this.getImagePath(item.url))
  75. }else{
  76. if(!this.projectId){
  77. this.getData()
  78. }
  79. }
  80. // console.log(this.patent)
  81. },
  82. methods: {
  83. getData(){
  84. var params = {
  85. patentCell:4,
  86. patentNo:this.patent.publicNo,
  87. appNo:this.patent.applicationNo,
  88. }
  89. this.$api.getPatentPart(params).then(response=>{
  90. if(response.code == 200){
  91. if(Object.keys(response.data).length>0 && response.data.image.length>0){
  92. this.$set(this.patent,'image',response.data.image)
  93. }else{
  94. this.$set(this.patent,'image',[])
  95. }
  96. this.srcList = this.patent.image.map(item=>item.url)
  97. }
  98. })
  99. },
  100. changeWidth(){
  101. this.width=this.value+'%'
  102. },
  103. close() {
  104. this.visible = false
  105. },
  106. onChange(file, fileList) {
  107. this.file = file.raw
  108. },
  109. handleAdd() {
  110. this.visible = true
  111. this.title = '新增附图'
  112. this.form = {
  113. patentId: this.patent.id,
  114. status: 0,
  115. url: ''
  116. }
  117. },
  118. handleEdit(row) {
  119. this.visible = true
  120. this.title = '编辑附图'
  121. this.form = { ...row }
  122. },
  123. handleDelete(row) {
  124. this.$confirm('确认删除本条数据吗?', '提示', {
  125. confirmButtonText: '确定',
  126. cancelButtonText: '取消',
  127. type: 'warning'
  128. }).then(() => {
  129. this.$api.deletePatentImage({ id: row.id }).then(response => {
  130. this.$message.success('删除成功')
  131. this.refreshPatent()
  132. }).catch(error => {
  133. })
  134. })
  135. },
  136. refreshPatent() {
  137. this.$emit('refresh')
  138. },
  139. submit() {
  140. let formData = new FormData()
  141. formData.append('patentId', this.form.patentId)
  142. formData.append('status', this.form.status)
  143. formData.append('url', this.form.url)
  144. if (this.file) {
  145. formData.append('file', this.file)
  146. }
  147. if (this.form.id) {
  148. this.btnLoading = true
  149. formData.append('id', this.form.id)
  150. this.$api.editPatentImage(formData).then(response => {
  151. this.btnLoading = false
  152. this.$message.success('操作成功')
  153. this.visible = false
  154. this.file = null
  155. this.refreshPatent()
  156. }).catch(error => {
  157. this.btnLoading = false
  158. })
  159. } else {
  160. if (!this.file) {
  161. this.$message.error('请选择文件')
  162. return false
  163. }
  164. this.btnLoading = true
  165. this.$api.uploadPatentImage(formData).then(response => {
  166. this.btnLoading = false
  167. this.$message.success('操作成功')
  168. this.visible = false
  169. this.file = null
  170. this.refreshPatent()
  171. }).catch(error => {
  172. this.btnLoading = false
  173. })
  174. }
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss">
  180. .up{
  181. width: 70px;
  182. height:30px;
  183. line-height: 30px;
  184. color: rgb(65, 65, 224);
  185. cursor: pointer;
  186. position: absolute;
  187. right: 20px;
  188. top: 0px;
  189. }
  190. .up:hover{
  191. border-bottom: 1px solid rgb(45, 45, 235);
  192. }
  193. .block{
  194. width: 60%;
  195. margin: 0 auto;
  196. }
  197. .imageCard{
  198. display: flex;
  199. flex-direction: row;
  200. flex-wrap: wrap;
  201. justify-content: center;
  202. }
  203. .demonstration{
  204. float: left;
  205. line-height: 38px;
  206. text-align: center;
  207. }
  208. .patent-image {
  209. position: relative;
  210. .delete {
  211. float: right;
  212. padding: 3px 0;
  213. color: red;
  214. padding-left: 10px;
  215. }
  216. .edit {
  217. float: right;
  218. padding: 3px 0;
  219. }
  220. .add {
  221. font-size: 80px;
  222. color: #6b6868;
  223. margin-top: 60px;
  224. }
  225. .preview {
  226. // height: 300px;
  227. margin-right: 20px;
  228. cursor: pointer;
  229. text-align: center;
  230. .card-header {
  231. height: 20px;
  232. }
  233. .el-card__header {
  234. border-bottom: 1px solid #EBEEF5;
  235. font-weight: normal;
  236. }
  237. }
  238. .el-image {
  239. width: 100%;
  240. }
  241. }
  242. </style>