Mr.Shi
2023-08-11 5a7fb4358eb902ce139096f20ef3c0625adcd7f4
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
<template>
  <TableLayout v-permissions="['ext:wstockext:query']">
    <!-- 搜索表单 -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" label-suffix=":" inline>
      <el-form-item label="汇总依据" prop="groupType">
         <el-select v-model="searchForm.groupType" clearable placeholder="请选择" @change="search">
            <el-option
              v-for="(item, index) in groupTypes"
              :key="index"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="质量属性" prop="qualityType">
         <el-select v-model="searchForm.qualityType" clearable placeholder="请选择" @change="search">
            <el-option
              v-for="(item, index) in qualityTypes"
              :key="index"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
      </el-form-item>
      <!-- <el-form-item label="物料编码" prop="code">
        <el-input v-model="searchForm.code" placeholder="请输入物料编码" @keypress.enter.native="search"></el-input>
      </el-form-item> -->
      <el-form-item label="物料信息" prop="materialName">
        <el-input v-model="searchForm.materialName" placeholder="请输入物料名称/编码" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="批次号" prop="batch">
        <el-input v-model="searchForm.batch" placeholder="请输入批次号" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="工序名称" prop="procedureName">
        <el-input v-model="searchForm.procedureName" placeholder="请输入工序名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="所属仓库" prop="materialOrBatch">
        <el-input v-model="searchForm.materialOrBatch" placeholder="请输入仓库名称" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- 表格和分页 -->
    <template v-slot:table-wrap>
      <ul class="toolbar">
        <!-- <li v-permissions="['ext:plansext:importExcel']">
          <ImportButton
            text="导入"
            template-name="stock_import_template.xlsx"
            template-path="template/stock_import_template.xlsx"
            action="/ext/wStockExt/importBatch"
            @success="search"
          />
        </li> -->
        <li v-permissions="['ext:wstockext:exportExcel']"><el-button type="primary" @click="exportExcel">导出</el-button></li>
      </ul>
      <div style="display: flex;">
        <div class="tree-scroll">
          <!-- <Tree
            :list="data"
            :defaultProps="defaultProps"
            @callback="callback"
          ></Tree> -->
          <el-tree 
            :props="defaultProps"
            :load="loadNode"
            highlight-current
            lazy
            :accordion="true"
            @node-click="handleNodeClick"
          >
            <template slot-scope="{ data }">
              <span class="long-title-style tree_item_label" :class="{'activeColor':isSelect(data)}" :title="data.name">{{ data.name }}</span>
            </template>
          </el-tree>
        </div>
        <!-- <div style="width: 1%; background-color: #f9f9f9;"></div> -->
        <!-- v-loading="isWorking.search" -->
        <div style="width: 80%;">
          <el-table
            :data="tableData.list"
            stripe
            border
            :summary-method="getSummaries"
            show-summary
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="materialCode" fixed="left" label="物料编码" min-width="160px">
              <template slot-scope="{row}">
                {{ row.materialCode }}
              </template>
            </el-table-column>
            <el-table-column prop="materialName" label="物料名称" show-overflow-tooltip min-width="100px">
              <template slot-scope="{row}">
                <span class="long-title-style">{{ row.materialName }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="attr" label="规格" min-width="100px"></el-table-column>
            <el-table-column v-if="searchForm.groupType == 3" prop="batch" label="批次号" min-width="100px"></el-table-column>
            <el-table-column prop="procedureName" label="工序" min-width="100px">
              <template slot-scope="{row}">
                <span >{{ row.procedureName || '-' }}</span>
              </template>
            </el-table-column>
            <el-table-column label="质量属性" min-width="100px">
              <template slot-scope="{row}">
                <span v-if="row.qualityType==0" class="valid-style">合格</span>
                <span v-else-if="row.qualityType==1" class="unvalid-style">不良</span>
                <span v-else-if="row.qualityType==2" class="scrap-style">报废</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column v-if="searchForm.groupType != 1" prop="wareHouseName" label="仓库" show-overflow-tooltip min-width="100px">
              <template slot-scope="{row}">
                <span class="long-title-style">{{ row.wareHouseName }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="searchForm.groupType != 1" prop="locationName" label="货位" show-overflow-tooltip min-width="100px">
              <template slot-scope="{row}">
                <span class="long-title-style">{{ row.locationName }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="num" fixed="right" label="库存数量" min-width="100px">
               <template slot-scope="{row}">
                {{ row. num + row.unitName}}
               </template>
            </el-table-column>
            <!-- <el-table-column prop="unitName" label="单位" min-width="100px"></el-table-column> -->
          </el-table>
          <pagination
            @size-change="handleSizeChange"
            @current-change="handlePageChange"
            :pagination="tableData.pagination"
          ></pagination>
        </div>
      </div>
    </template>
  </TableLayout>
</template>
 
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import Tree from '@/components/common/Tree'
import ImportButton from '@/components/common/ImportButton'
import { queryWareHouserAndLocaltion } from '@/api/ext/warehouseExt'
import { getListByWarehouseId } from '@/api/ext/warehouseLocationExt'
// import { queryWarehouseAllData } from '@/api/ext/warehouseExt'
import { addPrecision } from '@/utils/util'
export default {
  name: 'WStockExt',
  extends: BaseTable,
  components: { TableLayout, Pagination, Tree, ImportButton },
  data () {
    return {
      // 搜索
      searchForm: {
        groupType: 3,
        materialName: null,
        warehouseId: null,
        qualityType: null,
        materialOrBatch: null,
        locationId: null,
        greaterZero: 1,
        batch: null,
        procedureName: null,
      },
      tempWarehouseId: null,
      tempLocaltionId: null,
      groupTypes: [
        { name: '物料+仓库+批次号', id: 3 },
        { name: '物料+仓库', id: 2 },
        { name: '物料', id: 1 }
      ],
      warehouseType: [
        // 0原材料库 1半成品库 2成品库 3不良品库 4线边库
        { name: '原材料库', id: 0 },
        { name: '半成品库', id: 1 },
        { name: '成品库', id: 2 },
        { name: '不良品库', id: 3 },
        { name: '线边库', id: 4 }
      ],
      qualityTypes: [
        { name: '合格', id: 0 },
        { name: '不良', id: 1 },
        { name: '报废', id: 2 },
      ],
      data: [],
      defaultProps: {
        children: 'warehouseLocationList',
        label: 'name',
        isLeaf: 'isLeaf',
        id: 'id'
      }
    }
  },
  created () {
    this.config({
      module: '物料库存余额信息',
      api: '/ext/wStockExt',
      'field.id': 'id',
      'field.main': 'name',
      sorts: [{ direction: 'DESC', property: 'CREATE_TIME' }]
    })
    this.search()
  },
  methods: {
    loadNode (node, resolve) {
      console.log(node);
      if (node.level === 0) {
        queryWareHouserAndLocaltion({ status: 1 })
          .then(res => {
            let wareHouse = this.tree(res, false)
            return resolve(wareHouse)
          })
          .catch(err => {
            console.log(err)
          })
      } else {
        getListByWarehouseId(node.data.id, null)
          .then(res => {
            let houseLocation = this.tree(res, true)
            return resolve(houseLocation)
          })
          .catch(err => {
 
          })
        
      }
    },
    handleNodeClick (data) {
      // debugger
      if (data.isLeaf) {
        this.searchForm.locationId = data.id
      } else {
        if (this.searchForm.warehouseId === data.id) {
          this.searchForm.warehouseId = null
        } else {
          this.searchForm.warehouseId = data.id
        }
        this.searchForm.locationId = null
      }
      this.search()
    },
    // callback (data, item) {
    //   // console.log(data, item)
    //   if (item.warehouseLocationList) {
    //     // 点击的是仓库
    //     if (this.searchForm.warehouseId === data.id) {
    //       this.searchForm.warehouseId = null
    //     } else {
    //       this.searchForm.warehouseId = data.id
    //     }
    //     this.searchForm.locationId = null
    //   } else {
    //     this.searchForm.locationId = data.id
    //   }
    //   // console.log(this.searchForm.warehouseId, this.searchForm.locationId);
    //   this.search()
    // },
    // 树数据处理
    tree (treeArray, isLeaf) {
      const array = []
      for (const item of treeArray) {
        if (!item.name) {
          item.name = item.unionName
        }
        item.isLeaf = isLeaf
        array.push(item)
      }
      // console.log(array)
      return array
    },
    typeToStr (type) {
      for (const item of this.warehouseType) {
        if (item.id === type) return item.name
      }
    },
    getNanme (row) {
      // console.log('row', row);
      return 'test'
    },
    isSelect (data) {
      // console.log('data',data.isLeaf, data.id);
      // console.log('this.searchForm',this.searchForm.locationId, this.searchForm.warehouseId);
      if (data.isLeaf) {
        return data.id === this.searchForm.locationId
      } else {
        return data.id === this.searchForm.warehouseId && !this.searchForm.locationId
      }
    },
    add(num1, num2) {
      const num1Digits = (num1.toString().split('.')[1] || '').length;
      const num2Digits = (num2.toString().split('.')[1] || '').length;
      const baseNum = Math.pow(10, Math.max(num1Digits, num2Digits));
      return (num1 * baseNum + num2 * baseNum) / baseNum;
    },
    getSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        } else if (index === 2 || index === 3 || index === 4 || index === 5 || index === 7) {
          sums[index] = '-';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = 0
          values.forEach(item => {
            sums[index] = addPrecision(item, sums[index])
          })
          
        } else {
          sums[index] = '-';
        }
      });
      return sums
    }
  }
}
</script>
 
<style lang="scss" scoped>
.tree-scroll {
  width: 15%;
  max-height: 560px;
  overflow-y: scroll;
}
 
// .tree-scroll::-webkit-scrollbar {
//   // 滚动条整体部分,可以设置宽度等
//   width: 2px;
//   height: 10px;
//   // display: none;
// }
// .tree-scroll::-webkit-scrollbar-thumb {
//   // 滚动条里面的滑块
//   border-radius: 5px;
//   // display: none;
// }
// .tree-scroll::-webkit-scrollbar-button {
//   // 滚动条轨道两端的按钮,允许通过点击以微调滑块的位置
//   width: 10px;
//   border-radius: 50%;
//   display: none;
// }
// .tree-scroll::-webkit-scrollbar-track {
//   // 滚动条的轨道(里面装有thumb)
//   box-shadow: inset 0 0 2px #333;
//   border-radius: 5px;
//   display: none;
// }
// .tree-scroll::-webkit-scrollbar-corner {
//   // 当同时有垂直滚动条和水平滚动条时的交汇处
//   // background: springgreen;
//   display: none;
// }
.tree_item_label {
    font-size: 14px;
    font-weight: 400;
    color: #333333;
    white-space: nowrap;
}
.activeColor {
    color: #305ED5 !important;
}
</style>