郑永安
2023-06-19 2befd4a5d3733520b69ed97da88e675b6b086a3c
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
<template>
  <div class="container">
    <el-breadcrumb style="padding-top: 10px;padding-bottom: 10px" >
      <el-breadcrumb-item :to="{ path: '/stock/enterprise' }">库存监管</el-breadcrumb-item>
      <el-breadcrumb-item>库存详情</el-breadcrumb-item>
    </el-breadcrumb>
 
    <div class="filter-container">
      <el-row>
        <el-input v-model="queryForm.name" class="filter-item" placeholder="产品名称" style="width: 30%; float: left;"
                  @keyup.enter.native="queryHandle"/>
        <el-select v-model="queryForm.manufacturer" filterable placeholder="请选择生产厂家" style="float: left;padding-left: 15px">
          <el-option
            v-for="item in manufacturerTree"
            :key="item.attributes"
            :label="item.text"
            :value="item.text">
          </el-option>
        </el-select>
          <el-select v-model="queryForm.type" clearable placeholder="请选择产品大类" style="float: left;margin-left: 10px"
                     @change="getProductSecondaryCategory">
              <el-option
                  class="filter-item"
                  v-for="item in typeOptions"
                  :key="item.attributes"
                  :label="item.text"
                  :value="item.attributes">{{item.text}}
              </el-option>
          </el-select>
          <el-select v-model="queryForm.secondaryType" clearable placeholder="请选择产品小类" style="float: left;margin-left: 10px">
              <el-option
                  v-for="item in secondaryOptions"
                  :key="item.attributes"
                  :label="item.text"
                  :value="item.attributes">
              </el-option>
          </el-select>
      </el-row>
 
      <el-row>
        <el-input v-model="queryForm.directionCode" class="filter-item" placeholder="流向码" style="width: 30%;float: left" @keyup.enter.native="queryHandle"/>
 
        <el-button class="filter-item" style="margin-left: 15px;" type="primary" icon="el-icon-refresh"
                   @click="refreshHandle">刷新
        </el-button>
        <el-button class="filter-item" style="margin-left: 15px;" type="primary" icon="el-icon-download"
                   @click="exportAllHandle">导出
        </el-button>
        <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-search"
                   @click="queryHandle"/>
          <el-button v-if="userType === 1" class="filter-item" style="margin-left: 10px; background-color: #f56c6c" type="danger" icon="el-icon-delete"
                     @click="clearHandle">清空库存
          </el-button>
      </el-row>
 
 
    </div>
    <div class="table_content">
      <el-table
        v-loading="listLoading"
        :key="tableKey"
        :data="stockData"
        ref="multipleTable"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        @sort-change="sortChange"
      >
          <el-table-column
              type="selection"
              width="55"/>
        <el-table-column type="index" label="序号" align="center" width="80"/>
        <el-table-column label="产品名称" prop="name" align="center" sortable="custom">
          <template slot-scope="scope">
              <el-link type="primary" @click="showDetail(scope.row)">{{ scope.row.name }}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="产品编码" prop="directionCode" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.directioncode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="库存总数(箱)" prop="directionCode" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.countNum }}</span>
          </template>
        </el-table-column>
          <el-table-column label="每箱数量(挂、个)" prop="directionCode" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.boxnumber }}</span>
              </template>
          </el-table-column>
          <el-table-column label="产品大类" prop="productType" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.productType }}</span>
              </template>
          </el-table-column>
          <el-table-column label="产品小类" prop="secondaryType" align="center" sortable="custom">
              <template slot-scope="scope">
                  <span>{{ scope.row.secondaryType }}</span>
              </template>
          </el-table-column>
        <el-table-column label="规格" prop="specification" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.specification }}</span>
          </template>
        </el-table-column>
        <el-table-column label="含药量" prop="explosiveContent" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.explosiveContent }}</span>
          </template>
        </el-table-column>
        <el-table-column label="生产日期" prop="createdDate" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.createddate | parseTime('{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>
      <br>
      <el-pagination
        v-show="recordTotal>0"
        :current-page="currentPage"
        :page-sizes="[20, 50, 100,200]"
        :page-size="pageSize"
        :total="recordTotal"
        layout="total, sizes, prev, pager, next, jumper"
        background
        style="float:right;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
        <StockDetail ref="stockDetail" :itemCode = "itemCode" @getinfo = "getStockList"></StockDetail>
    </div>
  </div>
 
</template>
 
<script>
    import {getMajorCategoryTree, getManufacturerTree, getSecondaryCategoryTree} from "../../api/product";
  import {computePageCount, parseTime} from "../../utils";
  import {parseError} from "../../utils/messageDialog";
    import {clearStockByItem, stockList} from "../../api/stock";
  import Cookies from 'js-cookie'
  import StockDetail from "./components/stockDetail";
  import {mapGetters} from "vuex";
    import {dictionaryAllItems} from "../../api/dictionary";
 
  export default {
    name: "stockInfo",
      components: {StockDetail},
      data(){
      return{
        pageSize: 20,
        recordTotal: 0,
        currentPage: 1,
        pageTotal: 0,
        tableKey: 0,
        stockData:[],
        listLoading: true,
        manufacturerTree:[],
        itemCode:"",
        queryForm: {
          name: '',
          manufacturer:'',
          directionCode:'',
          beginDate:'',
          endDate:'',
          type:'',
          secondaryType:'',
        },
          typeOptions: [],
          secondaryOptions:[],
        owner:'',
      }
    },
    computed:{
      ...mapGetters([
          'userType',
          'username',
          'userId'
      ])
    },
    created(){
      this.queryForm.beginDate = this.$route.query.beginDate;
      this.queryForm.endDate = this.$route.query.endDate;
    },
    mounted(){
      getManufacturerTree().then(res=>{
        this.manufacturerTree=(res.data) ;
      });
        this.getDictionaryItemLevelList();
        this.getProductMajorCategory();
      this.owner = this.$route.query.owner;
      this.getStockList(this.$route.query.owner);
    },
    methods:{
      getStockList(owner){
        const _this = this;
        const params = {};
        params['pageIndex'] = _this.currentPage;
        params['pageSize'] = _this.pageSize;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        if (owner == null){
          owner = Cookies.get("userId");
        }
        params['owner'] = owner;
        const userName = Cookies.get('userName');
        const name = Cookies.get('name');
        params['operator'] = name + '(' + userName + ')';
        for (const i in _this.queryForm) {
          if (_this.queryForm[i] != undefined && _this.queryForm[i].toString() != '') {
            params[i] = _this.queryForm[i]
          }
        }
        _this.listLoading = true
        stockList(params).then(response => {
          const res = response.data;
          if (res.code === "200") {
            const result = res.result;
            _this.recordTotal = result.totalCount;
            _this.pageSize = result.pageSize;
            _this.pageTotal = computePageCount(result.totalCount, result.pageSize);
            _this.currentPage = result.pageIndex;
            _this.stockData = result.result
          } else {
            parseError({error: res.message, vm: _this})
          }
          _this.listLoading = false
        }).catch(error => {
          _this.listLoading = false
          parseError({error: error, vm: _this})
        })
      },
      refreshHandle: function () {
        this.getStockList(this.owner)
      },
      queryHandle: function () {
        this.currentPage = 1
        this.getStockList(this.owner)
      },
      handleSizeChange: function (val) {
        this.pageSize = val
        this.currentPage = 1
        this.getStockList(this.owner)
      },
      handleCurrentChange: function (val) {
        this.currentPage = val
        this.getStockList(this.owner)
      },
      sortChange(param){
        this.sort = param.prop;
        this.order = param.order;
        this.getStockList(this.owner);
      },
      showDetail(param){
          this.$refs.stockDetail.open(param.directioncode,param.enterpriseNumber)
      },
        getProductSecondaryCategory(major){
            this.secondaryOptions = [];
            this.queryForm.secondaryType = '';
            getSecondaryCategoryTree(major).then(res=>{
                this.secondaryOptions = res.data;
            })
        },
        getDictionaryItemLevelList() {
            const _this = this
            if (_this.levelOptions && _this.levelOptions.length > 0) {
                return
            }
            const params = {}
            params['dictionaryType'] = '产品级别';
            dictionaryAllItems(params).then(response => {
                const res = response.data
                if (res.code == 200) {
                    _this.levelOptions = res.result
                } else {
                    parseError({error: res.message, vm: _this})
                }
            }).catch(error => {
                parseError({error: error, vm: _this})
            })
        },
        getProductMajorCategory(){
            getMajorCategoryTree().then(res=>{
                this.typeOptions = res.data;
            })
        },
        clearHandle(){
            const _selectData = this.$refs.multipleTable.selection;
            let directionCodes = "";
            let count = 0;
            if (_selectData == null || _selectData.length < 1){
                parseError({ error: "未选中产品信息", vm: this })
            }
            _selectData.forEach(item =>{
                if (item.name !== '总计'){
                    directionCodes += item.directioncode;
                    directionCodes += ",";
                    count++;
                }
            });
            this.$confirm('此操作将永久清除选中的 '+count+' 种产品库存, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                const params = {}
                params['owner'] = this.owner;
                params['directionCodes'] = directionCodes;
                clearStockByItem(params).then(response =>{
                    const res = response.data;
                    if (res.code === "200") {
                        const result = res.result;
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.refreshHandle();
                    }
                });
 
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });
        },
      exportAllHandle () {
        const _this = this;
        const params = {};
        let owner = _this.owner;
        params['pageIndex'] = _this.currentPage;
        params['pageSize'] = _this.pageSize;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        if (owner == null){
          owner = Cookies.get("userId");
        }
        params['owner'] = owner;
        const userName = Cookies.get('userName');
        const name = Cookies.get('name');
        params['operator'] = name + '(' + userName + ')';
        for (const i in _this.queryForm) {
          if (_this.queryForm[i] != undefined && _this.queryForm[i].toString() != '') {
            params[i] = _this.queryForm[i]
          }
        }
        stockList(params).then(response => {
          const res = response.data;
          if (res.code === "200") {
            const allData = res.result.result;
            if (allData.length == 0) {
              parseError({ error: '当前没有数据', vm: _this });
              return
            }
 
            import('@/vendor/Export2Excel').then(excel => {
              const tHeader = ['产品名称','产品编码', '库存总数(箱)', '每箱数量(挂、个)', '产品大类', '产品小类', '规格', '含药量', '生产日期'];
              const filterVal = ['name','directioncode', 'countNum', 'boxnumber', 'productType', 'secondaryType', 'specification', 'explosiveContent', 'createddate'];
              const data = _this.formatJson(filterVal, allData);
              excel.export_json_to_excel({
                header: tHeader,
                data,
                filename: '库存详情'
              })
            })
          } else {
            parseError({ error: res.message, vm: _this })
          }
        }).catch(error => {
          parseError({ error: error, vm: _this })
        })
      },
      formatJson(filterVal, jsonData) {
        return jsonData.map((v) =>
          filterVal.map((j) => {
            if (j === 'createddate') {
              return parseTime(v[j], '{y}-{m}-{d}')
            }else {
              return v[j]
            }
          })
        )
      },
    },
  }
</script>
 
<style scoped>
 
</style>