prescriptionPicture.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <!-- 处方图片上传阅览 -->
  3. <div>
  4. <div class="prescription">
  5. <el-dialog title="上传处方图片" :visible.sync="prescriptionVisible" width="700px" :close-on-click-modal="false"
  6. @close="closeDialog">
  7. <div class="card_prescription">
  8. <div class="title_prescription">处方图片:</div>
  9. <el-upload action="#" list-type="picture-card" :file-list="fileList" :http-request="UploadImage">
  10. <i slot="default" class="el-icon-plus"></i>
  11. <div slot="file" slot-scope="{file}">
  12. <img class="el-upload-list__item-thumbnail" :src="file.url" alt=""
  13. @error="onUploadImgError($event, file)">
  14. <span class="el-upload-list__item-actions">
  15. <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
  16. <i class="el-icon-zoom-in"></i>
  17. </span>
  18. <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
  19. <i class="el-icon-delete"></i>
  20. </span>
  21. </span>
  22. </div>
  23. </el-upload>
  24. <div class="title_prescription">已有处方图片:</div>
  25. <div class="card_prescription_picture">
  26. <!-- <div class="img_prescription_picture" v-for="(item,index) in srcList" :key="index">
  27. <el-image class="image_picture" :src="item" :preview-src-list="srcList" :initial-index="urlIndex"
  28. @click="prescriptionLook(item,index)">
  29. </el-image>
  30. <div @click.stop="delPicture(item,index)">
  31. <i class="el-icon-error del_picture"></i>
  32. </div>
  33. </div> -->
  34. <!-- <div class="img_prescription_picture" v-for="(item, index) in srcList" :key="index">
  35. <img v-if="isImg(item)" :src="item" style="max-width: 210px;max-height: 170px;display: block;cursor: pointer;"
  36. @click="prescriptionLook(item)">
  37. <div v-else
  38. style="width:210px;height:100px;display:flex;align-items:center;justify-content:center;background:#f5f7fa;border:1px solid #d9d9d9;border-radius:4px;cursor:pointer;"
  39. @click="openFile(item)">
  40. <i class="el-icon-document" style="font-size:36px;color:#409EFF;"></i>
  41. <span style="font-size:11px;color:#999;margin-left:4px;">{{ getFileName(item) }}</span>
  42. </div>
  43. </div> -->
  44. <div class="card_prescription_picture">
  45. <div class="img_prescription_picture" v-for="(item, index) in srcList" :key="index" style="width: 100px; height: 100px; border: 1px solid #d9d9d9; border-radius: 4px;
  46. overflow: hidden; display: flex; flex-direction: column; align-items: center;
  47. justify-content: center; background: #f5f7fa; cursor: pointer; position: relative;"
  48. @click="openFile(item)">
  49. <!-- 删除按钮(右上角) -->
  50. <span class="del_picture_btn" @click.stop="delPicture(item, index)">
  51. <i class="el-icon-error"></i>
  52. </span>
  53. <template v-if="isImg(item)">
  54. <img :src="item" style="width: 100%; height: 100%; object-fit: cover;"
  55. @click.stop="prescriptionLook(item)">
  56. </template>
  57. <template v-else>
  58. <i class="el-icon-document" style="font-size: 36px; color: #409EFF;"></i>
  59. <span style="font-size: 12px; color: #666; margin-top: 4px; max-width: 90px;
  60. overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
  61. {{ getFileName(item) }}
  62. </span>
  63. </template>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. <span slot="footer" class="dialog-footer">
  69. <el-button plain @click="prescriptionVisible = false">取 消</el-button>
  70. <el-button type="primary" :loading="sendConfirmLoading" @click.stop="sendHandleAdd">确 定</el-button>
  71. </span>
  72. </el-dialog>
  73. </div>
  74. <!-- // 图片查看器 -->
  75. <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="urlList" :z-index="2100" />
  76. </div>
  77. </template>
  78. <script>
  79. import {
  80. putWaybill
  81. } from '@/api/waybill'
  82. import {
  83. getFileToken,
  84. } from '@/api/login'
  85. import ElImageViewer from "element-ui/packages/image/src/image-viewer";
  86. export default {
  87. props: {
  88. fileList: {
  89. type: Array,
  90. default: () => [],
  91. },
  92. srcList: {
  93. type: Array,
  94. default: () => [],
  95. },
  96. orderID: {
  97. type: Number,
  98. default: () => null,
  99. },
  100. },
  101. components: {
  102. ElImageViewer
  103. },
  104. data() {
  105. return {
  106. prescriptionVisible: false,
  107. disabled: false,
  108. showViewer: false, // 显示查看器
  109. urlList: [], // 图片的url
  110. urlIndex: 0,
  111. sendConfirmLoading: false,
  112. }
  113. },
  114. methods: {
  115. sendHandleAdd() {
  116. this.sendConfirmLoading = true
  117. let arrImg = [...this.srcList]
  118. this.fileList.forEach(item => {
  119. arrImg.push(item.url)
  120. })
  121. if (arrImg.length > 0) {
  122. putWaybill({
  123. id: this.orderID,
  124. prescription: arrImg,
  125. }).then(res => {
  126. if (res.code == 200) {
  127. this.$message({
  128. message: '操作成功',
  129. type: 'success'
  130. });
  131. this.sendConfirmLoading = false
  132. this.prescriptionVisible = false
  133. this.$emit('prescription')
  134. }
  135. })
  136. } else {
  137. this.$message.error('请先上传处方');
  138. }
  139. },
  140. // 查看图片
  141. handlePictureCardPreview(file) {
  142. if (!this.isImg(file.url)) {
  143. window.open(file.url, '_blank')
  144. return
  145. }
  146. this.urlList = this.fileList.filter(e => e.url !== file.url && this.isImg(e.url)).map(e => e.url);
  147. this.urlList.unshift(file.url)
  148. this.showViewer = true
  149. },
  150. // 删除图片
  151. handleRemove(file) {
  152. const filteredArr = this.fileList.filter(obj => obj.uid !== file.uid);
  153. this.fileList = filteredArr
  154. console.log('handleRemove', file)
  155. },
  156. prescriptionLook(file) {
  157. var imgList = this.srcList.filter(u => this.isImg(u))
  158. this.urlList = imgList
  159. this.showViewer = true
  160. },
  161. // 删除处方
  162. delPicture(event, index) {
  163. this.srcList.splice(index, 1)
  164. },
  165. closeViewer() {
  166. this.showViewer = false
  167. },
  168. isImg(url) {
  169. var name = (url || '').split('/').pop().split('?')[0].toLowerCase()
  170. return !/\.(pdf|doc|docx|xls|xlsx|ppt|pptx|zip|rar|txt|csv)$/i.test(name)
  171. },
  172. getFileName(url) {
  173. return (url || '').split('/').pop().split('?')[0] || '文件'
  174. },
  175. openFile(url) {
  176. window.open(url, '_blank')
  177. },
  178. // 上传文件
  179. UploadImage(file) {
  180. const loading = this.$loading({
  181. lock: true,
  182. text: 'Loading',
  183. spinner: 'el-icon-loading',
  184. background: 'rgba(0, 0, 0, 0.7)'
  185. });
  186. this.file = file.file;
  187. let formData = new FormData();
  188. formData.append('file', this.file);
  189. getFileToken(formData).then(res => {
  190. if (res.code == 200) {
  191. let arr1 = {
  192. uid: this.file.uid,
  193. url: res.data,
  194. }
  195. this.fileList.push(arr1)
  196. }
  197. loading.close();
  198. }).catch(e => {
  199. console.log(e, 23)
  200. loading.close();
  201. this.$message.error('上传失败');
  202. })
  203. },
  204. onUploadImgError(e, file) {
  205. var el = e.target
  206. var name = file.name || (file.url || '').split('/').pop().split('?')[0] || '文件'
  207. el.outerHTML = '<div style="width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#f5f7fa;">' +
  208. '<i class="el-icon-document" style="font-size:36px;color:#409EFF;"></i>' +
  209. '<span style="font-size:11px;color:#999;max-width:130px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px;">' + name + '</span>' +
  210. '</div>'
  211. },
  212. closeDialog() {
  213. this.$emit('closeDialog')
  214. }
  215. }
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .prescription ::v-deep .el-dialog__header {
  220. border-bottom: 1px solid #EBEEF5;
  221. }
  222. .prescription ::v-deep .el-dialog__body {
  223. padding: 20px;
  224. }
  225. .title_prescription {
  226. font-size: 16px;
  227. margin: 6px 0px;
  228. }
  229. .card_prescription_picture {
  230. display: flex;
  231. flex-direction: row;
  232. flex-wrap: wrap;
  233. }
  234. .img_prescription_picture {
  235. position: relative;
  236. width: 148px;
  237. height: 148px;
  238. margin: 0 8px 8px 0;
  239. }
  240. .image_picture {
  241. cursor: pointer;
  242. width: 100%;
  243. height: 100%;
  244. border-radius: 6px;
  245. }
  246. .del_picture {
  247. position: absolute;
  248. top: 5px;
  249. right: 5px;
  250. color: #F56C6C;
  251. font-size: 20px;
  252. cursor: pointer;
  253. z-index: 2;
  254. }
  255. .del_picture_btn {
  256. position: absolute;
  257. top: 2px;
  258. right: 2px;
  259. color: #F56C6C;
  260. font-size: 20px;
  261. cursor: pointer;
  262. z-index: 2;
  263. background: rgba(255,255,255,0.8);
  264. border-radius: 50%;
  265. line-height: 1;
  266. display: flex;
  267. align-items: center;
  268. justify-content: center;
  269. width: 22px;
  270. height: 22px;
  271. transition: all 0.2s;
  272. &:hover {
  273. transform: scale(1.15);
  274. background: rgba(255,255,255,1);
  275. }
  276. }
  277. </style>