黎星凯
2024-05-08 b4adff68a07b783fc90da1c9370d8be5f383e700
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
  <win-md class="stock-detail" title="导入分发单文件" @close="close" :width="'800px'" :loading="loading">
 
    <upload ref="uploadRef" :values="fileList" :settings="uploadSettings" @on-change="uploadChange"></upload>
 
 
    <el-button name="确定分发" style="float: right;margin-right: 50px;margin-top: 20px" site="form" type="primary" size="mini" @click="distribute()">
      确定分发
    </el-button>
 
  </win-md>
</template>
<script>
import winMd from '@/components/win/win-md';
import * as DateFormatter from '@/utils/DateFormatter';
import {getDownUrl, getUploadUrl} from '@/utils/base';
import Viewer from 'viewerjs';
import 'viewerjs/dist/viewer.css';
import de from "element-ui/src/locale/lang/de";
import upload from '@/components/upload/index';
let viewer = null;
 
 
import {transferAdd, transferImport} from '@/api/stock/transfer';
 
export default {
  computed: {
    de() {
      return de
    }
  },
  components: {winMd,upload},
  props: {
    setting: {
      type: Object,
      default: () => {
      },
    },
  },
  data() {
    return {
      procureDoc:"",
 
      uploadSettings: {
        title: '上传',
        max: 20, // 最大大小,单位M
        num: 10, // 支持上传图片个数
        tip: '', // 提示 默认:`只能上传${this.defaultSettings.num}个${this.defaultSettings.accept}文件,且不超过${this.defaultSettings.max}kb`
        uploadUrl: getUploadUrl(), // 上传路径
        multiple: true, // 是否支持批量上传
        disabled: false, // 是否禁用
      },
 
 
      loading: true,
      fileList: [],
      detail: {
        baseCategoryName: '',
        businessFormCode: '',
        goodsTemplateName: '',
        procureDoc: '',
        agencyId: '',
        agencyName: '',
        states: '',
        createName: '',
        time: '',
        procureGoods: [{}, {}],
        fileKey: Math.random(),
      },
    };
  },
  filters: {
    formatTime(time) {
      if (!time) return '-';
      return DateFormatter.LongToDateTime(time);
    },
    formatPrice(price) {
      return price / 100
    }
  },
  created() {
    this.loading = false
    this.fileList = []
  },
  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++;
        }
      }
      // this.fileList.forEach((f, i) => {
      //   if (file.uid == f.uid) {
      //     index = i
      //   }
      // })
      // document.querySelector('#uploadPreviewImages').children[0].click()
      viewer.view(index);
    },
    checkImg(name) {
      const suffix = name.substring(name.lastIndexOf('.'), name.length);
      const imgArray = ['.jpg', '.jpeg', '.png', '.bmp'];
      if (imgArray.indexOf(suffix) < 0) {
        return false;
      }
      return true;
    },
    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');
    },
 
    // 上传
    uploadChange() {
      let arr = this.$refs.uploadRef.fileList;
      let procureDoc = JSON.stringify(arr);
      console.log(procureDoc)
      this.procureDoc = procureDoc;
 
      let pro = this.setting.id
      console.log(pro)
    },
    /**
     * 确定分发
     */
    distribute(){
      let id = this.setting.id
      let procureDoc = this.procureDoc
      if(id == null || procureDoc === ''){
        this.$message.error('请上传图片!');
        return
      }
      let opTime = DateFormatter.formatDate(new Date(), 'yyyyMMddhhmmss');
 
      transferImport({"idStr":id,"procureDoc":procureDoc,"opTime":opTime,"type":"1"})
        .then((res) => {
          this.loading = false
          this.$message.success('保存成功!');
          this.close();
          this.$emit('search');
        })
        .catch((err) => {
          this.loading = false
          console.log('edit err', err);
          this.$message.error('保存失败');
        });
 
 
    }
 
 
  },
};
</script>
<style lang="scss" scoped>
@import url(../../../../styles/store.scss);
 
.card3 {
  padding: 10px;
  margin-top: 10px;
  border-radius: 2px;
  background: #ffffff;
}
</style>