zuozhengqing
2023-11-21 0712b49e5538589dac4859ca8cebf196caa954ab
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
<template>
  <div class="purchase"  v-loading="tableLoading">
    <div class="filter">
      <div class="filter-card">
        <CommonSearch
            :show-add="true"
            add-title="新建"
            @addCommonClick="addBtnClick"
            :show-download="false"
            :amount-view="false"
            :show-action-btn="false"
            :placeholder="'请输入供应商/物料/采购单等'"
            @searchClick="onFilterSearch"
        />
      </div>
    </div>
 
    <div class="body">
      <div class="body-card">
        <div class="list-view">
          <TableCommonView
              ref="tableListRef"
              :table-list="tableList"
              @selCommonClick="selCommonClick"
              @selTableCol="selTableCol"
          >
            <template slot="tableButton">
              <el-table-column  label="状态" width="120">
                <template slot-scope="scope">
                  {{ getpurchaseStatus(scope.row.status) }}
                </template>
              </el-table-column>
              <el-table-column label="操作" width="220" fixed="right">
                <template slot-scope="scope">
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnConfirm(scope.row)" style="margin-right: 5px"
                  >确认</el-button
                  >
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnEdit(scope.row)" style="margin-right: 5px"
                  >编辑</el-button
                  >
                  <el-button type="text" size="small" @click="btnLook(scope.row)" style="margin-right: 5px"
                  >查看</el-button
                  >
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnCancel(scope.row)" style="margin-right: 5px"
                  >取消</el-button
                  >
                  <el-button v-if="scope.row.status===1" type="text" size="small" @click="btnDelete(scope.row)" style="margin-right: 5px"
                  >删除</el-button
                  >
                  <!-- <el-button v-if="scope.row.status< 4" @click="submitClick(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>
      </div>
    </div>
 
 
    <!-- 新建/编辑销售线索 -->
    <!-- <AddSalesLeadDialog v-if="editSalesLeadConfig.visible" :edit-rightContent-config="editSalesLeadConfig" /> -->
    <!-- 详情 -->
    <DetailSupplier v-if="commonDetail.visible" :common-detail="commonDetail" />
    <!-- 新建/编辑 -->
    <AddPurchase ref="addDialog" v-if="editConfig.visible" :edit-common-config="editConfig" />
  </div>
</template>
 
<script>
import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
import { getPurchaseList, getPurchaseInfo, submitPurchase,deletePurchase } from "@/api/purchaseManage/purchase"
import DetailSupplier from "@/views/purchaseManage/purchase/DetailSupplier"
import AddPurchase from "@/views/purchaseManage/purchase/components/AddPurchase"
import { getSupplierList } from "@/api/supplierManage/supplier"
export default {
  name: "SupplierManage",
  props: {},
  components: { DetailSupplier, AddPurchase },
  mixins: [pageMixin],
  computed: {},
  data() {
    return {
      tableLoading: false,
      tableList: {}, // 列表
      selValueList: [],
      commonDetail: {
        visible: false,
        infomation: {}
      },
      search: "",
      editRow: {},
      editConfig: {
        visible: false,
        title: "创建",
        isDisabled:false,
        infomation: {
          supplierList:[]
        }
      },
      tableColumn: [
        { label: "单据类型", prop: "orderType", min: 130 },
        { label: "采购单号", prop: "number", min: 150, isCommonClick: true ,default:true},
        { label: "采购单名称", prop: "name", min: 130, isCommonClick: true },
        { label: "供应商名称", prop: "supplierName", min: 130 },
        { label: "采购数量", prop: "quantity", min: 130 },
        { label: "收货仓库", prop: "warehouse", min: 130 },
        { label: "经办人", prop: "handledBy", min: 130 },
        { label: "制单人", prop: "creator", min: 130 }
      ],
      showCol: ['采购单号', '采购单名称', '单据类型', '供应商名称', '采购数量', '收货仓库','经办人','制单人']
    }
  },
  created() {
    this.setTable()
    this.getData()
    this.getSupplierData()
  },
  methods: {
    getpurchaseStatus(val) {
      let statusList=[
        {id:1,name:"待确认"},
        {id:2,name:"待入库"},
        {id:3,name:"已入库"},
        {id:4,name:"已完成"},
        {id:5,name:"已取消"}
      ]
      if (val) {
        for (let i in statusList) {
          if (statusList[i].id == val) {
            return statusList[i].name
          }
        }
      } else {
        return "--"
      }
    },
    setColumnVisible(showCol){
      return  this.tableColumn.map(ele=>{
        return {
          ...ele,
          isShowColumn:showCol.includes(ele.label)
        }
      })
    },
    setTable() {
      this.tableList = {
        tableInfomation: [],
        selectIndex: true,
        showcol: this.showCol,
        allcol: [],
        tableColumn:this.setColumnVisible(this.showCol)
      }
      this.tableList.allcol = this.tableList.tableColumn.filter(ele=>!ele.default).map(ele=>ele.label);
    },
    selTableCol(val) {
      this.showcol = val;
      this.tableList.tableColumn = this.setColumnVisible(val);
    },
    // 请求数据
    async getData() {
      await getPurchaseList({
        keyword: this.search,
        page: this.pagerOptions.currPage,
        pageSize: this.pagerOptions.pageSize
      })
      .then((res) => {
        if (res.data.code === 200) {
          let list = res.data.data.list
          list.map((item)=>{
            item.supplierName=item.supplier.name
          })
          this.tableList.tableInfomation = list || []
          this.pagerOptions.totalCount = res.data.data.total
        }
      })
      .catch((err) => {
        console.log(err)
      })
    },
    // 获取供应商数据
    async getSupplierData() {
      await getSupplierList({
        // [val]: content,
        page:1,
        pageSize: 10
      })
      .then((res) => {
        if (res.data.code == 200) {
          this.editConfig.infomation.supplierList=res.data.data.list
          
        }
      })
    },
    // 搜索
    onFilterSearch(searchText){
      this.search = searchText ?? ''
      this.pagerOptions.currPage = 1
      this.getData()
    },
    // 新建
    addBtnClick() {
      this.editConfig.isDisabled=false
      // this.editRow = {};
      // this.$refs.add.islook = true;
      this.editConfig.visible = true
      this.editConfig.title = "创建"
      this.editConfig.infomation = {
        productList: [],
        purchaseTypeId: "",
        supplierId: "",
        supplierName: "",
        orderSource: "手动创建",
        name: "",
        contact: "",
        phone: "",
        signingDate: "",
        deliveryDate: "",
        remark: "",
        wholeDiscountType: null,
        wholeDiscount: 0,
        priceAdjustmentType: null,
        priceAdjustment: 0,
        realTotalPrice: 0
      }
    },
 
    // 编辑
    btnEdit(row) {
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          this.tableLoading = false
          this.editConfig.visible = true
          this.editConfig.title = "编辑"
          this.editConfig.infomation = {
            productList: res.data.productList,
            supplierName: res.data.purchase.supplier.name,
            ...res.data.purchase
          }
        } else {
          this.$message.error(res.msg ? res.msg + "," : "" + "获取信息失败!")
        }
      })
      setTimeout(() => {
        this.tableLoading = false
      }, 3000)
      // this.editRow = row;
      // this.$refs.add.islook = true;
    },
    // 确认发货
    btnConfirm(row) {
      this.$confirm("是否提交?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          submitPurchase({ id: row.ID,status:2 }).then((response) => {
            if (response.code === 200) {
              this.$message.success("提交成功")
              this.getData()
            } else {
              this.$message.warning("提交失败")
            }
          })
        },(e)=>{
          console.error(e)
        })
    },
    // 取消
    btnCancel(row){
      this.$confirm("是否取消?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
      .then(() => {
        submitPurchase({ id: row.ID,status:5 }).then((response) => {
          if (response.code === 200) {
            this.$message.success("已取消")
            this.getData()
          } else {
            // this.$message.warning("提交失败")
          }
        })
      },(e)=>{
        console.error(e)
      })
    },
    // 删除
    btnDelete(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deletePurchase({ id: row.ID }).then((response) => {
            if (response.code === 200) {
              this.$message.success("删除成功")
              this.getData()
            } else {
              this.$message.warning("删除失败")
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    },
    // 查看
    btnLook(row){
      this.editConfig.isDisabled=true
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          this.tableLoading = false
          this.editConfig.visible = true
          this.editConfig.title = "查看"
          this.editConfig.infomation = {
            productList: res.data.productList,
            supplierName: res.data.purchase.supplier.name,
            ...res.data.purchase
          }
        } else {
          this.$message.error(res.msg ? res.msg + "," : "" + "获取信息失败!")
        }
      })
      setTimeout(() => {
        this.tableLoading = false
      }, 3000)
    },
    // 详情
    selCommonClick(row) {
      this.tableLoading = true
      getPurchaseInfo({ id: row.ID }).then((res) => {
        if (res.code == 200) {
          console.log(res,"产品详情")
          this.tableLoading = false
          this.commonDetail.visible = true
          this.commonDetail.infomation = {
            productList: res.data.productList,
            ...res.data.purchase
          }
        } else {
          this.$message.error(res.msg ? res.msg + "," : "" + "获取信息失败!")
        }
      })
      setTimeout(() => {
        this.tableLoading = false
      }, 3000)
    }
  }
}
</script>
 
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.purchase{
  height: 100%;
  overflow: hidden;
  background-color: transparent;
  .filter{
    height: 80px;
    display: flex;
    align-items: center;
    padding: 12px 20px 0 20px;
    &-card{
      height: 80px;
      display: flex;
      align-items: center;
      box-sizing: border-box;
      padding: 10px 20px;
      flex: 1;
      border-radius: 12px;
      background-color: #fff;
    }
  }
  .body{
    box-sizing: border-box;
    padding: 10px 20px;
    border-radius: 12px;
    height: calc(100% - 92px);
    &-card {
      background-color: #fff;
      border-radius: 12px;
      height: 100%;
      overflow: hidden;
    }
    .list-view {
      height: calc(100% - 60px);
      overflow: hidden;
    }
    .btn-pager {
      display: flex;
      .page {
        margin-left: auto;
      }
    }
  }
}
</style>