MrShi
2025-01-24 d1f08bfc65d459b893fb6d5134927e0c078d32e5
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
<template>
  <GlobalWindow title="选择物料" :visible.sync="isShowModal" :confirm-working="isLoading" width="1000px" @close="close"
    @confirm="confirm">
    <el-form ref="searchForm" :model="searchForm" label-width="100px" inline>
      <el-form-item prop="code" label="物料信息">
        <el-input v-model="searchForm.code" placeholder="请输入物料编码/名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item prop="areaIds" label="物料分类">
        <el-cascader v-model="searchForm.areaIds" @change="changeSel" placeholder="请选择物料分类" clearable
          :options="cateList" :props="{
            label: 'name',
            value: 'id',
            children: 'childCategoryList',
            checkStrictly: true
          }"></el-cascader>
      </el-form-item>
      <span>
        <el-button type="primary" @click="getList(1)">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </span>
    </el-form>
    <!--  -->
    <el-table @selection-change="handleSelectionChange" :data="list" stripe>
      <el-table-column type="selection"  width="55" />
      <el-table-column prop="code" label="物料编码" min-width="100px"></el-table-column>
      <el-table-column prop="name" label="物料名称" min-width="80px"></el-table-column>
      <el-table-column prop="qrcode" label="条码" min-width="100px"></el-table-column>
      <el-table-column prop="brand" label="品牌" min-width="80px"></el-table-column>
      <el-table-column prop="attr" label="规格型号" min-width="80px"></el-table-column>
      <el-table-column prop="unitName" label="单位" min-width="80px"></el-table-column>
      <el-table-column prop="maxStock" label="库存" min-width="80px"></el-table-column>
    </el-table>
    <Pagination class="mt10" @size-change="handleSizeChange" @current-change="getList" :pagination="pagination">
    </Pagination>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import Pagination from '@/components/common/Pagination'
import { fetchList } from '@/api/ywMaterial'
import { ywStockPage } from '@/api/store/index'
import { fetchList as getCateList } from '@/api/business/category.js'
export default {
  name: 'OperaCategoryWindow',
  components: { GlobalWindow, Pagination },
  data() {
    return {
      // 表单数据
      searchForm: {},
      pagination: {
        pageSize: 10,
        page: 1,
        total: 0
      },
      isOut: false,
      list: [],
      selList: [],
      cateList: [],
      isShowModal: false,
      isLoading: false,
      // 验证规则
      rules: {
        name: [{ required: true, message: '请输入二级分类名称', trigger: 'blur' }],
      },
      dataList: []
    }
  },
  created() {
    this.getCate()
  },
  methods: {
    confirm() {
      this.$emit('change', this.selList)
      this.close()
    },
    handleSelectionChange(val) {
      this.selList = val
    },
    getList(page) {
      const { pagination, searchForm, isOut } = this
      this.listLoading = true
      if(page){pagination.page = page}
      console.log('isOut', isOut);
      
      let fn = isOut ? ywStockPage : fetchList
      fn({
        capacity: pagination.pageSize,
        page: pagination.page,
        model: {...searchForm,status: 0}
      }).then((res) => {
        this.listLoading = false
        this.list = res.records
        this.pagination.total = res.total || 0
        if(isOut){
          this.list.forEach(item => {
            item.brand = item.materialBrand
            item.attr = item.materialAttr
            item.name = item.materialName
            item.id = item.materialId
            item.code = item.materialCode
            item.qrcode = item.materialQrcode
            item.unitName = item.materialUnitName
            item.maxStock = item.stock
          })
        }
      }, () => {
        this.listLoading = false
      })
    },
    getCate() {
      getCateList({
        model: { type: 7 },
        capacity: 1000,
        page: 1,
      }).then(res => {
        this.cateList = res.records || []
      })
    },
    changeSel(e) {
      if (e && e.length == 2) {
        this.$set(this.searchForm, 'cateId', e[1])
        this.$set(this.searchForm, 'parentCateId', '')
      }else if((e && e.length == 1)){
        this.$set(this.searchForm, 'parentCateId', e[0])
        this.$set(this.searchForm, 'cateId', '')
      } else {
        this.$set(this.searchForm, 'cateId', '')
      }
    },
    reset() {
      this.searchForm = {}
      this.pagination.pageSize = 10
      this.pagination.page = 1
      this.getList()
    },
    handleSizeChange(capacity) {
      this.pagination.pageSize = capacity
      this.getList()
    },
    close() {
      this.isShowModal = false
      this.$emit('close')
    },
  }
}
</script>