郑永安
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
<template>
  <div class="container">
    <el-breadcrumb style="padding-top: 10px;padding-bottom: 10px" >
      <el-breadcrumb-item :to="{ path: '/stock/enterpriseSale' }">进销存</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-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 class="filter-item" style="margin-left: 15px;" type="primary" icon="el-icon-refresh-right"
                     @click="resetQueryForm">重置
          </el-button>
      </el-row>
 
 
    </div>
    <div class="table_content">
      <el-table
        v-loading="listLoading"
        :key="tableKey"
        :data="stockData"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        @sort-change="sortChange"
      >
        <el-table-column type="index" label="序号" align="center" width="80"/>
        <el-table-column label="产品名称" prop="name" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.name }}</span>
          </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.entryNum }}</span>
          </template>
        </el-table-column>
        <el-table-column label="退货入库数(箱)" prop="manufacturer" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.returnNum }}</span>
          </template>
        </el-table-column>
        <el-table-column label="出库数(箱)" prop="manufacturer" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.deliveryNum }}</span>
          </template>
        </el-table-column>
        <el-table-column label="退库数(箱)" prop="manufacturer" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.returnDeliveryNum }}</span>
          </template>
        </el-table-column>
        <el-table-column label="销售数(箱)" prop="manufacturer" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.saleNum }}</span>
          </template>
        </el-table-column>
          <el-table-column label="每箱数量(挂、个)" prop="boxnumber" align="center" sortable="custom">
          <template slot-scope="scope">
              <span>{{ scope.row.boxnumber}}</span>
          </template>
      </el-table-column>
        <el-table-column label="生产厂家" prop="manufacturer" align="center" sortable="custom">
          <template slot-scope="scope">
            <span>{{ scope.row.manufacturer }}</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"
      />
    </div>
  </div>
 
</template>
 
<script>
  import {getManufacturerTree} from "../../api/product";
  import {computePageCount, parseTime} from "../../utils";
  import {parseError} from "../../utils/messageDialog";
  import {saleList, stockList} from "../../api/stock";
  import Cookies from 'js-cookie'
 
  export default {
    name: "saleInfo",
    data(){
      return{
        pageSize: 20,
        recordTotal: 0,
        currentPage: 1,
        pageTotal: 0,
        tableKey: 0,
        stockData:[],
        listLoading: true,
        manufacturerTree:[],
        queryForm: {
          name: '',
          manufacturer:'',
          directionCode:'',
          beginDate:'',
          endDate:'',
          type:'',
        },
        owner:'',
      }
    },
    created(){
      this.queryForm.beginDate = this.$route.query.beginDate;
      this.queryForm.endDate = this.$route.query.endDate;
    },
    mounted(){
      getManufacturerTree().then(res=>{
        this.manufacturerTree=(res.data) ;
      });
      this.enterpriseNumber = this.$route.query.enterpriseNumber;
      this.getSaleList(this.$route.query.enterpriseNumber);
    },
    methods:{
      getSaleList(enterpriseNumber){
        const _this = this;
        const params = {};
        params['pageIndex'] = _this.currentPage;
        params['pageSize'] = _this.pageSize;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        if (enterpriseNumber == null){
            enterpriseNumber = _this.enterpriseNumber;
        }
        params['enterpriseNumber'] = enterpriseNumber;
        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
        saleList(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.getSaleList()
      },
      queryHandle: function () {
        this.currentPage = 1
        this.getSaleList()
      },
      resetQueryForm(){
        this.queryForm.name = '';
        this.queryForm.manufacturer = '';
        this.queryForm.directionCode = '';
      },
      handleSizeChange: function (val) {
        this.pageSize = val
        this.currentPage = 1
        this.getSaleList()
      },
      handleCurrentChange: function (val) {
        this.currentPage = val
        this.getSaleList()
      },
      sortChange(param){
        this.sort = param.prop;
        this.order = param.order;
        this.getSaleList();
      },
      exportAllHandle () {
        const _this = this;
        const params = {};
        let enterpriseNumber = _this.enterpriseNumber;
        params['pageIndex'] = _this.currentPage;
        params['pageSize'] = _this.pageSize;
        params['sort'] = _this.sort;
        params['order'] = _this.order;
        params['enterpriseNumber'] = enterpriseNumber;
        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]
          }
        }
        saleList(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', 'entryNum', 'returnNum', 'deliveryNum', 'returnDeliveryNum', 'saleNum','boxnumber','manufacturer'];
              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>