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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
<template>
  <div class="add-common">
    <el-dialog
      :title="addCommonConfig.title + '供应商'"
      :visible.sync="editConfig.visible"
      :width="dialogWidth"
      :before-close="handleClose"
      :close-on-click-modal="false"
      append-to-body
      custom-class="iframe-dialog"
    >
      <el-form
        ref="form"
        :model="editConfig.infomation"
        :rules="rules"
        label-position="right"
        label-width="150px"
        size="mini"
      >
        <!-- 信息 -->
        <div class="basic-info">
          <!-- 基本信息 -->
          <div class="basic-info-title">基本信息</div>
          <div class="basic-info-view">
            <el-row>
              <el-col :span="12">
                <el-form-item label="供应商编号" prop="number">
                  <!-- <el-input v-model="editConfig.infomation.number"></el-input> -->
                  <el-input
                    style="width: 85%"
                    v-if="
                      editConfig.title == '修改' ||
                      (editConfig.title == '新建' && codenumer && (explain != '' || isIdDisabled))
                    "
                    :disabled="editConfig.title != '新建'"
                    v-model="editConfig.infomation.number"
                    placeholder="请输入编码"
                  >
                  </el-input>
                  <span v-else-if="editConfig.title == '新建'" style="color: #f56c6c; width: 85%"
                    >请优先配置编码规范 <el-button type="text" @click="numberClick"> 配置规范 </el-button></span
                  >
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="供应商名称" prop="name">
                  <el-input v-model="editConfig.infomation.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="供应商类型" prop="supplierType">
                  <div class="custom-name">
                    <el-select
                      v-model="editConfig.infomation.supplierType"
                      placeholder="请选择供应商类型"
                      class="common-select-sel"
                      size="mini"
                    >
                      <el-option
                        v-for="(item, index) in supplierTypeOptions"
                        :key="index"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                    <div class="common-select-btn" @click="setSupplierType"><i class="el-icon-setting"></i></div>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="所属行业" prop="industry">
                  <div class="custom-name">
                    <el-select
                      v-model="editConfig.infomation.industry"
                      placeholder="请选择供应商行业"
                      class="common-select-sel"
                      size="mini"
                    >
                      <el-option
                        v-for="(item, index) in industryOptions"
                        :key="index"
                        :label="item.name"
                        :value="item.name"
                      >
                      </el-option>
                    </el-select>
                    <div class="common-select-btn" @click="setIndustry"><i class="el-icon-setting"></i></div>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系人" prop="contact">
                  <el-input v-model="editConfig.infomation.contact"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="联系电话" prop="phone">
                  <el-input
                    v-model="editConfig.infomation.phone"
                    maxlength="11"
                    show-word-limit
                    oninput="value=value.replace(/[^\d]/g,'')"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="销售负责人" prop="responsiblePersonName">
                  <!-- <el-input v-model="editConfig.infomation.responsiblePersonId"></el-input> -->
                  <el-select
                    v-model="editConfig.infomation.responsiblePersonName"
                    placeholder="请选择"
                    size="mini"
                    style="width: 63%"
                  >
                    <el-option
                      v-for="(item, index) in memberOptions"
                      :key="index"
                      :label="item.username"
                      :value="item.userName"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="邮箱" prop="email">
                  <el-input v-model="editConfig.infomation.email"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="详细地址" prop="detailAddress">
                  <el-input
                    type="textarea"
                    :autosize="{ minRows: 2 }"
                    placeholder="请输入内容"
                    v-model="editConfig.infomation.detailAddress"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="网址" prop="url">
                  <el-input v-model="editConfig.infomation.url"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <!-- 入驻信息 -->
          <div class="basic-info-title">入驻信息</div>
          <div class="basic-info-view">
            <el-row>
              <el-col :span="12">
                <el-form-item label="户名" prop="accountName">
                  <el-input v-model="editConfig.infomation.accountName"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="开户行" prop="bank">
                  <el-input v-model="editConfig.infomation.bank"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="账号" prop="account">
                  <el-input v-model="editConfig.infomation.account"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="附件" prop="">
                  <template slot="label">
                    <div style="display: flex; float: right">
                      <div style="font-size: 16px">
                        <i class="el-icon-warning-outline" title="最多上传20个附件,最大限制5MB"></i>
                      </div>
                      <span style="margin-left: 5px">合同附件</span>
                    </div>
                  </template>
                  <div v-if="file_id === 0" class="annex-view">
                    <div @click="addAnnexClick">
                      <el-upload
                        class="upload-demo"
                        :headers="headers"
                        action=""
                        :limit="1"
                        :before-upload="beforeAvatarUpload"
                        :on-exceed="handleExceed"
                        :file-list="fileList"
                        :show-file-list="false"
                      >
                        <div style="display: flex; float: right">
                          <div style="font-size: 16px"><i class="el-icon-paperclip"></i></div>
                          <span>添加附件</span>
                        </div>
                      </el-upload>
                    </div>
                  </div>
                  <!-- v-if="file_name && file_name.length > 0" -->
                  <div v-else class="file-content">
                    <div>{{ file_name }}</div>
                    <div>
                      <el-button type="text" @click="previewClick" style="margin-left: 10px">预览</el-button>
                      <el-button type="text" @click="downloadClick">下载</el-button>
                      <el-button type="text" @click="delContractClick">删除</el-button>
                    </div>
                    <div ref="file"></div>
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="saveClick('form')">保 存</el-button>
        <el-button size="small" @click="editConfig.visible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 编辑下拉框 -->
    <EditDropdownDialog v-if="editDropdownConfig.editVisible" :edit-dropdown-config="editDropdownConfig" />
  </div>
</template>
 
<script>
import {
  createSupplier,
  createContract,
  updateSupplier,
  getIndustryList,
  getSupplierTypeList
  // downloadContract
  // previewContract
} from "@/api/supplierManage/supplier"
import EditDropdownDialog from "@/views/other/commonDialog/EditDropdownDialog"
import { getMemberListFromGrpc } from "@/api/common/other"
import download from "downloadjs"
// import { renderAsync } from "docx-preview"
import axios from "axios"
import codeMixin from "@/components/mixin/codeMixin"
export default {
  name: "AddSupplierDialog",
  mixins: [codeMixin],
  props: {
    addCommonConfig: {
      type: Object,
      default: () => {
        return {
          visible: false,
          title: "新建",
          infomation: {}
        }
      }
    }
  },
  components: { EditDropdownDialog },
  computed: {
    headers() {
      const authorization =
        "Bearer " + document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1") || ""
      return { authorization }
    }
  },
  data() {
    return {
      dialogWidth: "50%",
      editConfig: this.addCommonConfig,
      rules: {
        name: [{ required: true, message: "请输入", trigger: "blur" }],
        responsiblePersonName: [{ required: true, message: "请选择", trigger: "change" }],
        phone: [
          { required: false, message: "", trigger: "blur" },
          { len: 11, message: "长度在11个字符", trigger: "blur" },
          {
            pattern: /^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/,
            message: "请输入正确的手机号",
            trigger: "blur"
          }
        ],
        email: [
          { required: false, message: "", trigger: "blur" },
          {
            pattern: /^[a-zA-Z0-9_\\.]+@[a-zA-Z0-9-]+[\\.a-zA-Z]+$/,
            message: "请输入正确的邮箱格式",
            trigger: "blur"
          }
        ],
        number: [{ required: true, validator: this.validateCheckCode, trigger: ["change", "blur"] }]
      },
      supplierTypeOptions: [{ id: 1, name: "供应商类型1" }], // 供应商类型
      industryOptions: [{ id: 1, name: "所属行业1" }], // 所属行业
      memberOptions: [{ id: 1, username: "admin" }],
      editDropdownConfig: {
        editVisible: false,
        title: "",
        infomation: {}
      },
      fileList: [],
      file_name: this.addCommonConfig.infomation.file_name,
      file_id: this.addCommonConfig.infomation.fileId,
      previewUrl: "",
      loading: false
    }
  },
  created() {
    this.getSupplierTypeList()
    this.getIndustryList()
    this.getMemberList()
    if (this.editConfig.title === "修改") {
      // this.previewContract()
    }
    this.formInfo()
  },
  methods: {
    formInfo() {
      this.objCode.type = "供应商编码"
      this.objCode.codeStandID = ""
      if (this.editConfig.infomation.codeStandardID) {
        this.objCode.codeStandID = this.editConfig.infomation.codeStandardID
      }
      this.getRCodeStandardList()
    },
    // 销售负责人
    async getMemberList() {
      await getMemberListFromGrpc({
        page: 1,
        pageSize: 100
      }).then((res) => {
        console.log(res)
        this.memberOptions = res.data.list
      })
    },
    // 供应商类型
    async getSupplierTypeList() {
      await getSupplierTypeList({
        page: 1,
        pageSize: 100
      }).then((res) => {
        this.supplierTypeOptions = res.data.list
      })
    },
    // 所属行业
    async getIndustryList() {
      await getIndustryList({
        page: 1,
        pageSize: 100
      }).then((res) => {
        this.industryOptions = res.data.list
      })
    },
    handleClose() {
      this.editConfig.visible = false
    },
    // 保存
    saveClick(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.editConfig.infomation)
          const params = this.saveParams()
          if (this.editConfig.title === "新建") {
            createSupplier(params)
              .then((res) => {
                console.log(res)
                this.editConfig.visible = false
                if (res.code === 200) {
                  this.$message.success("添加成功")
                  this.$parent.getData()
                }
              })
              .catch((err) => {
                console.log(err)
              })
          } else {
            params.id=this.editConfig.infomation.id
            updateSupplier(params).then((res) => {
              this.editConfig.visible = false
              if (res.code === 200) {
                this.$message.success("编辑成功")
                this.$parent.getData()
              }
            })
          }
        } else {
          console.log("error submit")
          return false
        }
      })
    },
    saveParams() {
      let data = this.editConfig.infomation
      let params = {
        account: data.account || "",
        accountName: data.accountName || "",
        bank: data.bank || "",
        contact: data.contact || "",
        detailAddress: data.detailAddress || "",
        email: data.email || "",
        fileId: this.file_id || 0,
        // id: data.id || 0,
        industry: data.industry || "",
        name: data.name || "",
        number: data.number || "",
        phone: data.phone || "",
        responsiblePersonName:
        data.responsiblePersonName || document.cookie.replace(/(?:(?:^|.*;\s*)username\s*=\s*([^;]*).*$)|^.*$/, "$1"),
        status: data.status || 0,
        supplierType: data.supplierType || "",
        url: data.url || ""
      }
      return params
    },
    // 添加附件
    addAnnexClick() {},
    // 设置供应商类型
    setSupplierType() {
      this.editDropdownConfig.editVisible = true
      this.editDropdownConfig.title = "供应商类型"
    },
    // 设置所属行业
    setIndustry() {
      this.editDropdownConfig.editVisible = true
      this.editDropdownConfig.title = "所属行业"
    },
    //  文件上传--start
    beforeAvatarUpload(file) {
      // 文件类型判断
      var testmsg = file.name.substring(file.name.lastIndexOf(".") + 1)
      const extension = testmsg === "doc"
      const extension2 = testmsg === "pdf"
      const extension3 = testmsg === "docx"
      if (!extension && !extension2 && !extension3) {
        this.$message({
          message: "上传文件只能是 word、pdf格式!",
          type: "warning"
        })
        this.fileList = []
      } else {
        // 参数拼接
        console.log(file)
        let fd = new FormData()
        fd.append("file", file)
        fd.append("name", file.name)
        // 调用接口
        createContract(fd).then((res) => {
          if (res.code == 200) {
            this.file_name = file.name
            this.file_id = res.data.id
          }
        })
      }
    },
    // 文件超出个数限制时的钩子
    handleExceed(files, fileList) {
      console.log(fileList)
      this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件`)
    },
    // 下载合同
    downloadClick() {
      let url = "/api/downloadContract?id=" + this.file_id
      download(url, "", "")
    },
    // 删除合同
    delContractClick() {
      // deleteContract({
      //   id: this.file_id
      // }).then((res) => {
      //   console.log(res)
      //   this.$message.success(res.msg)
      this.file_id = 0
      // })
    },
    // 预览合同
    // async previewClick() {
    //   this.previewUrl = "/api/con/previewContract?id=" + this.file_id
    //   if (this.file_name.includes("pdf")) {
    //     window.open(this.previewUrl, "_blank")
    //   } else {
    //     let routeUrl = this.$router.resolve({
    //       path: "/PreviewFile",
    //       query: {
    //         //要传的参数
    //         previewUrl: this.previewUrl
    //       }
    //     })
    //     window.open(routeUrl.href, "_blank")
    //   }
    // }
    async previewClick() {
      this.previewUrl = "/api/previewContract?id=" + this.file_id
      if (this.file_name.includes("pdf")) {
        console.log("是pdf文件")
        await axios
          .get(this.previewUrl, {
            headers: {
              Authorization: "Bearer " + document.cookie.replace(/(?:(?:^|.*;\s*)token\s*=\s*([^;]*).*$)|^.*$/, "$1")
            }
          })
          .then((response) => {
            window.open(this.previewUrl, "_blank")
            console.log("response", response, this.previewUrl)
          })
          .catch((error) => {
            console.error(error)
          })
      } else {
        console.log(this.previewUrl, "看看是啥子")
        let routeUrl = this.$router.resolve({
          path: "/PreviewFile",
          query: {
            //要传的参数
            previewUrl: this.previewUrl
          }
        })
        window.open(routeUrl.href, "_blank")
      }
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
::v-deep {
  .iframe-dialog .el-dialog__body {
    .basic-info {
      .basic-info-title {
        background-color: #f4f8fe;
        padding-left: 10px;
        font-size: 15px;
        font-weight: bold;
        color: #666;
        height: 42px;
        line-height: 42px;
      }
      .basic-info-view {
        margin-top: 10px;
        padding-right: 40px;
        .custom-name,
        .common-select {
          display: flex;
          .common-select-btn {
            margin-left: 5px;
            font-size: 18px;
            cursor: pointer;
          }
        }
        .common-select {
          .common-select-sel {
            width: 270px;
          }
        }
      }
      .annex-view {
        display: flex;
        color: #6166d3;
        .setFormat {
          margin-left: 10px;
        }
      }
      .file-content {
        display: flex;
      }
    }
  }
}
</style>