yangfeng
2023-09-06 29b5ffe318b8ab32865ebebedd865ea2aa3f6c7e
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
<template>
  <div class="rightContent">
    <div class="top">
      <div class="supplier-search">
        <SearchCommonView
          ref="searchCommonView"
          :search-options="searchOptions"
          @searchClick="searchClick"
          @resetClick="resetClick"
        />
        <div class="add-view">
          <el-button type="primary" size="mini" @click="addBtnClick">新建</el-button>
        </div>
      </div>
      <template>
        <div class="list-view">
          <TableCommonView
            ref="tableSupplier"
            :table-list="tableList"
            @selCommonClick="selCommonClick"
            @tableRowClick="tableRowClick"
          >
            <template slot="tableButton">
              <el-table-column label="操作" width="100">
                <template slot-scope="scope">
                  <el-button
                    v-if="scope.row.status === 0"
                    @click="enableClick(scope.row, '启用')"
                    type="text"
                    size="small"
                    >启用</el-button
                  >
                  <el-button v-else @click="enableClick(scope.row, '停用')" type="text" size="small">停用</el-button>
                  <el-button @click="modifyClick(scope.row)" type="text" size="small">修改</el-button>
                </template>
              </el-table-column>
            </template>
          </TableCommonView>
        </div>
        <div class="btn-pager">
          <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
        </div>
      </template>
    </div>
    <div class="bottom">
      <div class="product-search">
        <div style="margin-left: 10px">可提供的产品</div>
        <div style="margin-left: 20px">
          <el-button type="primary" size="mini">创建采购单</el-button>
        </div>
        <SearchCommonView
          class="search"
          ref="searchCommonView"
          :search-options="searchProductOptions"
          @searchClick="searchProductClick"
          @resetClick="resetProductClick"
        />
        <div class="add-view">
          <el-button type="primary" size="mini" @click="addNewProductClick">添加新产品</el-button>
        </div>
      </div>
      <template>
        <div class="list-view">
          <TableCommonView
            ref="tableListProduct"
            :table-list="productTableList"
            @selCommonClick="selCommonClick"
            @getSelectArray="getSelectArray"
          >
            <template slot="tableButton">
              <el-table-column label="操作" width="170">
                <template slot-scope="scope">
                  <el-button @click="raleteClick(scope.row)" type="text" size="small">相关供应商</el-button>
                  <el-button @click="editClick(scope.row)" type="text" size="small">修改</el-button>
                  <el-button @click="delClick(scope.row)" type="text" size="small">删除</el-button>
                </template>
              </el-table-column>
            </template>
          </TableCommonView>
        </div>
        <div class="btn-pager">
          <PagerView class="page" :pager-options="productPagerOptions" v-on="pagerEvents" />
        </div>
      </template>
    </div>
    <!-- 新建/编辑销售线索 -->
    <AddSupplier v-if="editConfig.visible" :add-common-config="editConfig" />
    <!-- 详情 -->
    <DetailSupplier v-if="commonDetail.visible" :common-detail="commonDetail" />
    <!-- 相关供应商 -->
    <RaleteSupplierList v-if="raleteSupplierConfig.visible" :common-config="raleteSupplierConfig" />
    <!-- 添加新产品 -->
    <AddNewProduct v-if="newProductConfig.visible" :add-common-config="newProductConfig" />
  </div>
</template>
 
<script>
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import { getSupplierList, changeSupplierStatus } from "@/api/supplierManage/supplier"
import DetailSupplier from "@/views/supplierManage/supplier/DetailSupplier"
import AddSupplier from "@/views/supplierManage/supplier/AddSupplier"
import RaleteSupplierList from "@/views/supplierManage/supplier/RaleteSupplierList"
import AddNewProduct from "@/views/supplierManage/supplier/AddNewProduct"
import { getProductList, deleteProduct } from "@/api/productManage/product"
 
export default {
  name: "SupplierManage",
  props: {},
  components: { DetailSupplier, AddSupplier, RaleteSupplierList, AddNewProduct },
  mixins: [pageMixin],
  computed: {},
  data() {
    return {
      tableList: {}, // 供应商列表
      productTableList: {}, // 产品列表
      selValueList: [],
      searchOptions: [],
      searchProductOptions: [], // 产品查询
      commonDetail: {
        visible: false,
        infomation: {}
      },
      editConfig: {
        visible: false,
        title: "新建",
        infomation: {}
      },
      raleteSupplierConfig: {
        visible: false,
        infomation: {}
      },
      newProductConfig: {
        visible: false,
        title: "添加",
        infomation: {}
      },
      productPagerOptions: {
        currPage: 1,
        pageSize: 10,
        totalCount: 0
      },
      supplierId: 0
    }
  },
  created() {
    this.setTable()
    this.setProductTable()
    this.getData()
  },
  methods: {
    setTable() {
      this.tableList = {
        tableInfomation: [],
        selectIndex: true,
        highlight: true,
        ref: "tableListRef",
        tableColumn: [
          { label: "供应商编号", prop: "number", min: 190, isCommonClick: true },
          { label: "供应商名称", prop: "name", min: 130 },
          { label: "供应商类型", prop: "supplierType", min: 130 },
          { label: "所属行业", prop: "industry", min: 130 },
          { label: "联系人", prop: "contact", min: 130 },
          { label: "联系电话", prop: "phone", min: 130 },
          { label: "状态", prop: "status_name", min: 130 },
          { label: "创建时间", prop: "created_at", min: 130 }
        ]
      }
      this.searchOptions = []
      for (let i = 0; i < this.tableList.tableColumn.length; i++) {
        const label = this.tableList.tableColumn[i].label
        const value = this.tableList.tableColumn[i].prop
        this.searchOptions.push({ value: value, label: label })
      }
    },
    setProductTable() {
      this.productTableList = {
        tableInfomation: [],
        selectBox: true,
        selectIndex: true,
        tableColumn: [
          { label: "产品编码", prop: "number", min: 190 },
          { label: "产品名称", prop: "name", min: 130 },
          { label: "产品规格", prop: "specifications", min: 130 },
          { label: "单位", prop: "unit", min: 130 },
          { label: "采购价格", prop: "purchasePrice", min: 130 },
          { label: "供货时长(天)", prop: "deliveryTime", min: 130 },
          { label: "物流时长(天)", prop: "shippingDuration", min: 130 }
        ]
      }
      this.searchProductOptions = []
      for (let i = 0; i < this.productTableList.tableColumn.length; i++) {
        const label = this.productTableList.tableColumn[i].label
        const value = this.productTableList.tableColumn[i].prop
        this.searchProductOptions.push({ value: value, label: label })
      }
    },
    // 请求数据
    async getData(val, content) {
      this.getSupplierList(val, content)
    },
    // 供应商列表
    async getSupplierList(val, content) {
      await getSupplierList({
        [val]: content,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      }).then((res) => {
        console.log(res.data)
        if (res.data.code === 200) {
          const list = res.data.data.list.map((item) => {
            return {
              ...item,
              status_name: item.status === 0 ? "未启用" : "启用"
            }
          })
          this.tableList.tableInfomation = list || []
          this.pagerOptions.totalCount = res.data.data.total
          if (list && list.length > 0) {
            this.supplierId = this.tableList.tableInfomation[0].ID
          } else {
            this.supplierId = 0
          }
          this.$nextTick(() => {
            this.$refs.tableSupplier.$refs.table.setCurrentRow(this.tableList.tableInfomation[0])
          })
          this.getProductList()
        }
      })
    },
    // 产品列表
    async getProductList(val, content) {
      console.log(val, content)
      await getProductList({
        [val]: content,
        supplierId: this.supplierId,
        page: this.productPagerOptions.currPage,
        pageSize: this.productPagerOptions.pageSize
      }).then((res) => {
        console.log(res.data)
        const list = res.data.data.list.map((item) => {
          return {
            ...item
          }
        })
        this.productTableList.tableInfomation = list || []
        this.productPagerOptions.totalCount = res.data.data.total
      })
    },
    // 搜索供应商
    searchClick(val, content) {
      console.log(val, content)
      this.getSupplierList(val.value, content)
    },
    resetClick() {
      this.getSupplierList()
    },
    // 搜索产品
    searchProductClick(val, content) {
      console.log(val, content)
      this.getProductList(val.value, content)
    },
    resetProductClick() {
      this.getProductList()
    },
    // 新建供应商
    addBtnClick() {
      this.editConfig.visible = true
      this.editConfig.title = "新建"
      this.editConfig.infomation = { fileId: 0 }
    },
    // 启用供应商
    async enableClick(row, value) {
      let status = value === "启用" ? 1 : 0
      await changeSupplierStatus({
        id: row.ID,
        status: status
      }).then((res) => {
        if (res.code === 200) {
          this.$message.success("状态修改成功")
          this.getData()
        }
      })
    },
    // 修改供应商
    modifyClick(row) {
      this.editConfig.visible = true
      this.editConfig.title = "修改"
      this.editConfig.infomation = { ...row, file_name: row.contract.fileName }
    },
    // 相关供应商
    raleteClick(row) {
      console.log(row)
      this.raleteSupplierConfig.visible = true
      this.raleteSupplierConfig.infomation = { ...row }
    },
    // 添加新产品
    addNewProductClick() {
      this.newProductConfig.visible = true
      this.newProductConfig.title = "添加"
      this.newProductConfig.infomation = { supplierId: this.supplierId }
    },
    // 修改产品
    editClick(row) {
      console.log(row)
      this.newProductConfig.visible = true
      this.newProductConfig.title = "修改"
      this.newProductConfig.infomation = { ...row }
    },
    // 删除
    delClick(row) {
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteProduct({ id: row.ID }).then((response) => {
            if (response.code === 200) {
              this.$message.success("删除成功")
              this.getProductList()
            } else {
              this.$message.warning("删除失败")
            }
          })
        })
        .catch(() => {})
    },
    getSelectArray(val) {
      console.log(val)
      this.selValueList = []
      const list = val.map((item) => {
        return item.id
      })
      this.selValueList = list
    },
    tableRowClick(row) {
      console.log(row)
      this.supplierId = row.ID
      this.getProductList()
    },
    // 详情
    selCommonClick(row) {
      console.log(row)
      this.commonDetail.visible = true
      this.commonDetail.infomation = { ...row }
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.rightContent {
  height: 100%;
  background: #f0f2f5;
  padding: 10px;
  .top {
    margin-bottom: 20px;
    height: 55%;
    background: #fff;
    .list-view {
      height: calc(100% - 120px);
    }
    .supplier-search {
      display: flex;
      align-items: center;
      .add-view {
        margin-left: auto;
        margin-right: 20px;
      }
    }
    .sel-name {
      color: $color-primary;
      cursor: pointer;
    }
    // .btn-pager {
    //   display: flex;
    //   .page {
    //     margin-left: auto;
    //   }
    // }
  }
  .bottom {
    margin-top: 20px;
    height: calc(40% - 0px);
    background: #fff;
    .list-view {
      height: calc(100% - 120px);
    }
    .product-search {
      display: flex;
      align-items: center;
      .search {
        margin-left: auto;
      }
      .add-view {
        margin-left: 20px;
        margin-right: 20px;
      }
    }
  }
}
</style>