| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287 |
- <template>
- <!-- 处方图片上传阅览 -->
- <div>
- <div class="prescription">
- <el-dialog title="上传处方图片" :visible.sync="prescriptionVisible" width="700px" :close-on-click-modal="false"
- @close="closeDialog">
- <div class="card_prescription">
- <div class="title_prescription">处方图片:</div>
- <el-upload action="#" list-type="picture-card" :file-list="fileList" :http-request="UploadImage">
- <i slot="default" class="el-icon-plus"></i>
- <div slot="file" slot-scope="{file}">
- <img class="el-upload-list__item-thumbnail" :src="file.url" alt=""
- @error="onUploadImgError($event, file)">
- <span class="el-upload-list__item-actions">
- <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
- <i class="el-icon-zoom-in"></i>
- </span>
- <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
- <i class="el-icon-delete"></i>
- </span>
- </span>
- </div>
- </el-upload>
- <div class="title_prescription">已有处方图片:</div>
- <div class="card_prescription_picture">
- <!-- <div class="img_prescription_picture" v-for="(item,index) in srcList" :key="index">
- <el-image class="image_picture" :src="item" :preview-src-list="srcList" :initial-index="urlIndex"
- @click="prescriptionLook(item,index)">
- </el-image>
- <div @click.stop="delPicture(item,index)">
- <i class="el-icon-error del_picture"></i>
- </div>
- </div> -->
- <!-- <div class="img_prescription_picture" v-for="(item, index) in srcList" :key="index">
- <img v-if="isImg(item)" :src="item" style="max-width: 210px;max-height: 170px;display: block;cursor: pointer;"
- @click="prescriptionLook(item)">
- <div v-else
- style="width:210px;height:100px;display:flex;align-items:center;justify-content:center;background:#f5f7fa;border:1px solid #d9d9d9;border-radius:4px;cursor:pointer;"
- @click="openFile(item)">
- <i class="el-icon-document" style="font-size:36px;color:#409EFF;"></i>
- <span style="font-size:11px;color:#999;margin-left:4px;">{{ getFileName(item) }}</span>
- </div>
- </div> -->
- <div class="card_prescription_picture">
- <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;
- overflow: hidden; display: flex; flex-direction: column; align-items: center;
- justify-content: center; background: #f5f7fa; cursor: pointer; position: relative;"
- @click="openFile(item)">
- <!-- 删除按钮(右上角) -->
- <span class="del_picture_btn" @click.stop="delPicture(item, index)">
- <i class="el-icon-error"></i>
- </span>
- <template v-if="isImg(item)">
- <img :src="item" style="width: 100%; height: 100%; object-fit: cover;"
- @click.stop="prescriptionLook(item)">
- </template>
- <template v-else>
- <i class="el-icon-document" style="font-size: 36px; color: #409EFF;"></i>
- <span style="font-size: 12px; color: #666; margin-top: 4px; max-width: 90px;
- overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
- {{ getFileName(item) }}
- </span>
- </template>
- </div>
- </div>
- </div>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button plain @click="prescriptionVisible = false">取 消</el-button>
- <el-button type="primary" :loading="sendConfirmLoading" @click.stop="sendHandleAdd">确 定</el-button>
- </span>
- </el-dialog>
- </div>
- <!-- // 图片查看器 -->
- <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="urlList" :z-index="2100" />
- </div>
- </template>
- <script>
- import {
- putWaybill
- } from '@/api/waybill'
- import {
- getFileToken,
- } from '@/api/login'
- import ElImageViewer from "element-ui/packages/image/src/image-viewer";
- export default {
- props: {
- fileList: {
- type: Array,
- default: () => [],
- },
- srcList: {
- type: Array,
- default: () => [],
- },
- orderID: {
- type: Number,
- default: () => null,
- },
- },
- components: {
- ElImageViewer
- },
- data() {
- return {
- prescriptionVisible: false,
- disabled: false,
- showViewer: false, // 显示查看器
- urlList: [], // 图片的url
- urlIndex: 0,
- sendConfirmLoading: false,
- }
- },
- methods: {
- sendHandleAdd() {
- this.sendConfirmLoading = true
- let arrImg = [...this.srcList]
- this.fileList.forEach(item => {
- arrImg.push(item.url)
- })
- if (arrImg.length > 0) {
- putWaybill({
- id: this.orderID,
- prescription: arrImg,
- }).then(res => {
- if (res.code == 200) {
- this.$message({
- message: '操作成功',
- type: 'success'
- });
- this.sendConfirmLoading = false
- this.prescriptionVisible = false
- this.$emit('prescription')
- }
- })
- } else {
- this.$message.error('请先上传处方');
- }
- },
- // 查看图片
- handlePictureCardPreview(file) {
- if (!this.isImg(file.url)) {
- window.open(file.url, '_blank')
- return
- }
- this.urlList = this.fileList.filter(e => e.url !== file.url && this.isImg(e.url)).map(e => e.url);
- this.urlList.unshift(file.url)
- this.showViewer = true
- },
- // 删除图片
- handleRemove(file) {
- const filteredArr = this.fileList.filter(obj => obj.uid !== file.uid);
- this.fileList = filteredArr
- console.log('handleRemove', file)
- },
- prescriptionLook(file) {
- var imgList = this.srcList.filter(u => this.isImg(u))
- this.urlList = imgList
- this.showViewer = true
- },
- // 删除处方
- delPicture(event, index) {
- this.srcList.splice(index, 1)
- },
- closeViewer() {
- this.showViewer = false
- },
- isImg(url) {
- var name = (url || '').split('/').pop().split('?')[0].toLowerCase()
- return !/\.(pdf|doc|docx|xls|xlsx|ppt|pptx|zip|rar|txt|csv)$/i.test(name)
- },
- getFileName(url) {
- return (url || '').split('/').pop().split('?')[0] || '文件'
- },
- openFile(url) {
- window.open(url, '_blank')
- },
- // 上传文件
- UploadImage(file) {
- const loading = this.$loading({
- lock: true,
- text: 'Loading',
- spinner: 'el-icon-loading',
- background: 'rgba(0, 0, 0, 0.7)'
- });
- this.file = file.file;
- let formData = new FormData();
- formData.append('file', this.file);
- getFileToken(formData).then(res => {
- if (res.code == 200) {
- let arr1 = {
- uid: this.file.uid,
- url: res.data,
- }
- this.fileList.push(arr1)
- }
- loading.close();
- }).catch(e => {
- console.log(e, 23)
- loading.close();
- this.$message.error('上传失败');
- })
- },
- onUploadImgError(e, file) {
- var el = e.target
- var name = file.name || (file.url || '').split('/').pop().split('?')[0] || '文件'
- el.outerHTML = '<div style="width:100%;height:100%;display:flex;flex-direction:column;align-items:center;justify-content:center;background:#f5f7fa;">' +
- '<i class="el-icon-document" style="font-size:36px;color:#409EFF;"></i>' +
- '<span style="font-size:11px;color:#999;max-width:130px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-top:2px;">' + name + '</span>' +
- '</div>'
- },
- closeDialog() {
- this.$emit('closeDialog')
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .prescription ::v-deep .el-dialog__header {
- border-bottom: 1px solid #EBEEF5;
- }
- .prescription ::v-deep .el-dialog__body {
- padding: 20px;
- }
- .title_prescription {
- font-size: 16px;
- margin: 6px 0px;
- }
- .card_prescription_picture {
- display: flex;
- flex-direction: row;
- flex-wrap: wrap;
- }
- .img_prescription_picture {
- position: relative;
- width: 148px;
- height: 148px;
- margin: 0 8px 8px 0;
- }
- .image_picture {
- cursor: pointer;
- width: 100%;
- height: 100%;
- border-radius: 6px;
- }
- .del_picture {
- position: absolute;
- top: 5px;
- right: 5px;
- color: #F56C6C;
- font-size: 20px;
- cursor: pointer;
- z-index: 2;
- }
- .del_picture_btn {
- position: absolute;
- top: 2px;
- right: 2px;
- color: #F56C6C;
- font-size: 20px;
- cursor: pointer;
- z-index: 2;
- background: rgba(255,255,255,0.8);
- border-radius: 50%;
- line-height: 1;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 22px;
- height: 22px;
- transition: all 0.2s;
- &:hover {
- transform: scale(1.15);
- background: rgba(255,255,255,1);
- }
- }
- </style>
|