222
schangxiang@126.com
2025-06-13 6a8393408d8cefcea02b7a598967de8dc1e565c2
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
<template>
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>面单上传</span>
    </div>
    <el-form v-model="formData" label-width="120px">
      <el-form-item label="选择口岸">
        <el-select v-model="formData.port_Id" placeholder="请选择" @change="getExpressCorp(formData.port_Id)">
          <el-option v-for="item in portOptions" :key="item.port_Id" :label="item.portName" :value="item.port_Id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="快递类别">
        <el-select v-model="formData.expressCorpType" filterable clearable placeholder="请选择快递类别" @change="changCorpType">
          <el-option v-for="(item, index) in expressCorpTypeList" :key="index" :label="item.expressCorpName" :value="item.expressCorpType">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="快递名称">
        <el-select v-model="formData.expressCorp_Id" filterable clearable placeholder="请选择快递名称">
          <el-option v-for="(item, index) in expressCorpNameList" :key="index" :label="item.expressCorpName" :value="item.expressCorp_Id">
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
 
    <el-upload ref="upload" :http-request="uploadHttp" :before-upload="beforeAvatarUpload" :show-file-list="false" class="upload-bill" action="" multiple>
      <el-button slot="trigger" size="small" type="primary">选取图片</el-button>
      <el-button style="margin-left: 10px;" size="small" type="success" @click="submitImgUrl">开始导入</el-button>
      <div slot="tip" class="el-upload__tip">只能上传常见格式图片文件</div>
    </el-upload>
    <div class="padding-20 line-height-1_5">
      <ul>
        <li v-for="(item, index) in fileList" :key="index">
          {{ item.imageName }} 已上传
        </li>
      </ul>
    </div>
    <div class="padding-20 line-height-1_5" v-html="uploadMsg">
      {{ uploadMsg }}
    </div>
  </el-card>
</template>
 
<script>
import ossClient from "@/utils/aliyun.oss.client";
 
export default {
  name: "tms-way-upload",
  data() {
    return {
      formData: {
        port_Id: null,
        expressCorp_Id: null
        // Storage_Id: null
      },
      portOptions: null,
      expressCorpoptions: null,
      // 文件列表
      fileList: [],
      fullFileRote: null,
      // StorageNames: [],
      // 快递类别下拉框数据列表
      expressCorpTypeList: [],
      // 快递名称下拉框数据列表
      expressCorpNameList: [],
      // 返回消息
      uploadMsg: null,
      uploadConf: this.common.uploadConf
    };
  },
  mounted() {
    // this.multiDistributionExpress();
    this.getPortList();
    this.getExpressCorpList();
    // this.getStorageList();
  },
  methods: {
    // 获取口岸下拉框
    getPortList() {
      const url = "/api/tms/base/port/getList";
      const params = {};
      var callback = res => {
        if (res.result) {
          this.portOptions = res.data;
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    // 获快递下拉框
    getExpressCorpList() {
      const url = "/api/basicInfo/base/expressCorp/getList";
      const params = {};
      var callback = res => {
        if (res.result) {
          this.expressCorpoptions = res.data;
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    // 选择口岸之后获取快递类别下拉框值
    getExpressCorp(port_Id) {
      const url = "/api/basicInfo/base/expressCorp/getWayBillExpressCorpType";
      const params = { port_Id: port_Id };
      var callback = res => {
        this.common.showMsg(res);
        if (res.result) {
          this.formData.expressCorpType = null;
          this.formData.expressCorp_Id = null;
          this.expressCorpTypeList = res.data;
        }
      };
      this.common.ajax(url, params, callback, true);
      // 弹出框
      this.dialogFormVisible = true;
    },
    // 选择快递单号后加载快递名称
    changCorpType(value) {
      const expressCorpType = value;
      const url = "/api/basicInfo/base/expressCorp/getList";
      const params = {
        expressCorpType: expressCorpType
      };
      this.formData.expressCorp_Id = "";
      this.common.ajax(url, params, res => {
        this.common.showMsg(res);
        if (res.result) {
          this.expressCorpNameList = res.data;
          this.formData.expressCorp_Id = this.expressCorpNameList[0].expressCorp_Id;
        } else {
          this.expressCorpNameList = [];
        }
      });
    },
 
    // 上传至阿里云
    /**
     * 阿里云OSS上传
     */
    uploadHttp({ file }) {
      this.common.loading(true);
      const fileName = `Upload/waybill/${this.common.formatDate(
        new Date(),
        "YYYY-MM-DD"
      )}/${file.name}`; // 定义唯一的文件名
      ossClient(this.uploadConf)
        .put(fileName, file, {
          ContentType: "image/jpeg"
        })
        .then(({ res, url, name }) => {
          if (res && res.status === 200) {
            this.fileList.push({
              imageName: file.name,
              imageUrl: name, // 本地相对地址
              aliUrl: res.requestUrls[0] // 阿里云完整地址
            });
          }
          this.common.loaded(true);
        })
        .catch(err => {
          this.$message.error(`上传图片失败` + err.message);
          this.common.loaded(true);
        });
    },
    /**
     * 图片限制
     */
    beforeAvatarUpload(file) {
      const fileSplit = file.name.split(".");
      const isJPEG = fileSplit[fileSplit.length - 1] === "jpeg";
      const isJPG = fileSplit[fileSplit.length - 1] === "jpg";
      const isPNG = fileSplit[fileSplit.length - 1] === "png";
      const isLt5MB = file.size / 1024 / 1024 < 5;
      if (!isJPG && !isJPEG && !isPNG) {
        this.$message.error("上传图片只能是 JPEG/JPG/PNG 格式!");
      }
      if (!isLt5MB) {
        this.$message.error("单张图片大小不能超过 5MB!");
      }
      return (isJPEG || isJPG || isPNG) && isLt5MB;
    },
    // 开始导入
    submitImgUrl() {
      if (this.fileList.length === 0) {
        this.$message.error("请上传图片!");
        return;
      }
      const url = "/api/tms/waybillUpload/importWayBillUpload";
 
      var portName = "";
      var expressCorpName = "";
      var portOptions = this.portOptions;
      var expressCorpoptions = this.expressCorpoptions;
      // 口岸
      for (var index in portOptions) {
        if (portOptions[index].port_Id === this.formData.port_Id) {
          portName = portOptions[index].portName;
        }
      }
      // 快递
      for (var index2 in expressCorpoptions) {
        if (
          expressCorpoptions[index2].expressCorp_Id ===
          this.formData.expressCorp_Id
        ) {
          expressCorpName = expressCorpoptions[index2].expressCorpName;
        }
      }
 
      if (!this.formData.port_Id) {
        this.$message.error("请选择口岸!");
        return;
      }
 
      if (!this.formData.expressCorp_Id) {
        this.$message.error("请选择快递!");
        return;
      }
 
      var userInfo = this.common.getUserInfo();
      const params = {
        imageList: this.fileList,
        expressCorp_Id: this.formData.expressCorp_Id,
        expressCorpName: expressCorpName,
        expressCorpType: this.formData.expressCorpType,
        port_Id: this.formData.port_Id,
        portName: portName,
        consignor_Id: userInfo.user_Id,
        consignorCode: userInfo.userName,
        consignorName: userInfo.userTrueName
      };
      var callback = res => {
        this.uploadMsg = res.msg;
        if (res.result) {
          this.fileList = [];
        }
      };
      this.common.ajax(url, params, callback, true);
    }
  }
};
</script>
 
<style lang="scss" scoped>
.box-card {
  .upload-bill {
    width: 480px;
    .el-upload__tip {
      margin-top: 20px;
    }
  }
}
</style>