From 87f07e589fb1c8103513a5fcc8febe3b14f5535f Mon Sep 17 00:00:00 2001
From: 石广澎 <shiguangpeng@163.com>
Date: 星期五, 01 十二月 2023 17:30:46 +0800
Subject: [PATCH] feat: 1、图片预览使用半路径 2、部门物品退回详情

---
 admin-web/src/views/stock/accessStock/outbound/detail.vue |   74 ++++++++++++++++++++++++++++++++++--
 1 files changed, 69 insertions(+), 5 deletions(-)

diff --git a/admin-web/src/views/stock/accessStock/outbound/detail.vue b/admin-web/src/views/stock/accessStock/outbound/detail.vue
index 0e6994e..ff58e36 100644
--- a/admin-web/src/views/stock/accessStock/outbound/detail.vue
+++ b/admin-web/src/views/stock/accessStock/outbound/detail.vue
@@ -1,5 +1,5 @@
 <template>
-  <win-md class="stock-detail" :title="setting.title" @close="close" :width="'800px'">
+  <win-md class="stock-detail" :title="setting.title" @close="close" :width="'800px'" :loading="loading">
     <el-row :gutter="20">
       <el-col :span="8">
         <span>鍑哄簱鍗曞彿锛�</span>
@@ -24,10 +24,12 @@
         <span>{{ detail.dealTime | formatTime }}</span>
       </el-col>
     </el-row>
-    <el-row v-if="detail.procureDoc" :gutter="20" style="margin-top: 20px">
+    <el-row v-if="fileList && fileList.length" :gutter="20" style="margin-top: 20px">
       <el-col class="img-row" :span="24">
         <span>鍑哄簱鎵嬬画锛�</span>
-        <div class="img-box"></div>
+        <div class="img-box" v-for="(item, index) in fileList" :key="index" @click="handlePreview(item)">
+          <img class="img" :src="getUrl(item.path)" alt=""/>
+        </div>
       </el-col>
     </el-row>
     <div class="goods-card" v-for="(goodsItem, goodsIndex) in detail.fromOutputGoods" :key="goodsIndex">
@@ -59,18 +61,34 @@
         </el-table-column>
         <el-table-column prop="counts" label="閲戦" align="center">
           <template slot-scope="scope">
-            {{ (scope.row.price * scope.row.counts).toFixed(2) }}
+            {{ scope.row.price * scope.row.counts | formatPrice}}
           </template>
         </el-table-column>
       </el-table>
     </div>
+    <div id="uploadPreviewImages" style="display: none">
+      <span v-for="(src, index) in fileList" :key="index">
+        <img
+            v-if="checkImg(src.name)"
+            class="v-img"
+            :src="getUrl(src.path)"
+            :alt="src.name"
+            style="width: 100px; height: 100px"
+        />
+      </span>
+    </div>
   </win-md>
 </template>
 <script>
-import { outputDetail } from '@/api/stock/accessStock';
+import {outputDetail} from '@/api/stock/accessStock';
 import winMd from '@/components/win/win-md';
 import * as DateFormatter from '@/utils/DateFormatter';
 
+import {getDownUrl} from "@/utils/base";
+import Viewer from 'viewerjs';
+import 'viewerjs/dist/viewer.css';
+
+let viewer = null;
 export default {
   components: { winMd },
 
@@ -82,6 +100,8 @@
   },
   data() {
     return {
+      loading:true,
+      fileList: [],
       detail: {
         categoryName: '',
         businessFormCode: '',
@@ -99,13 +119,57 @@
       if (!time) return;
       return DateFormatter.LongToDateTime(time);
     },
+    formatPrice(price) {
+      return price / 100
+    }
   },
   created() {
     outputDetail({ id: this.setting.id }).then((res) => {
       this.detail = res;
+      this.fileList = this.detail.doc ? JSON.parse(this.detail.doc) : [];
+      this.loading = false;
+      this.$nextTick(() => {
+        this.initPreviewImg();
+      });
     });
   },
   methods: {
+    initPreviewImg() {
+      if (viewer != null) {
+        viewer.destroy();
+      }
+      const ViewerDom = document.querySelector('#uploadPreviewImages');
+      viewer = new Viewer(ViewerDom, {});
+    },
+    handlePreview(file) {
+      if (!this.checkImg(file.name)) {
+        return false;
+      }
+      let index = 0;
+      for (let i = 0; i < this.fileList.length; i++) {
+        const f = this.fileList[i];
+        if (this.checkImg(f.name)) {
+          if (file.id == f.id) {
+            break;
+          }
+          index++;
+        }
+      }
+      viewer.view(index);
+    },
+    checkImg(name) {
+      const suffix = name.substring(name.lastIndexOf('.'), name.length);
+      const imgArray = ['.jpg', '.jpeg', '.png', '.bmp'];
+      return imgArray.indexOf(suffix) >= 0;
+
+    },
+    getUrl(path) {
+      if (path.substr(0, 7).toLowerCase() == 'http://' || path.substr(0, 8).toLowerCase() == 'https://') {
+        return path;
+      } else {
+        return getDownUrl() + path;
+      }
+    },
     close() {
       this.$emit('close')
     },

--
Gitblit v1.9.1