333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
<template>
  <!-- 面包屑导航区 -->   
  <div class="indexs">
    <el-card>
      <!-- 搜索与添加   clearable "toggleSelection([tableData[1], tableData[2]])"    &nbsp; &nbsp; -->
      <el-row>
        <el-button type="success" plain @click="exportExcel" >导出Excel</el-button>
        <el-button type="info" plain @click="addMaterial" >新建物料</el-button>
          <el-input v-model="searchParam" placeholder="物料名称/物料编号" class="searchParamClass"></el-input>
            <el-button type="success" plain @click="find" >查询</el-button>
             <el-button type="info" plain @click="reset" >重置</el-button>
      </el-row>
      <!-- 显示人员列表 -->
      <el-table ref= "table"  :data="TakeStocklist"  border stripe  show-summary :summary-method="getSummaries"  >
        <el-table-column :reserve-selection="true"  type="selection"  width="55"> </el-table-column>
        <el-table-column label="序号" type="index" width="50" > </el-table-column>
        <el-table-column label="物料id" prop="Product_Id" width="100" v-if="false"></el-table-column>
        <el-table-column label="物料编号" prop="ProductCode"  width="200"></el-table-column>
        <el-table-column label="物料名称" prop="ProductName"  width="450"></el-table-column>
        <el-table-column label="库存单位" prop="SmallUnit" width="100"></el-table-column>
        <el-table-column label=" PO单位" prop="BigUnit" width="100"></el-table-column>
         <el-table-column label="库存预警量" prop="Brand_Id" width="100"></el-table-column>
        <el-table-column label="创建人" prop="Creator" width="110" ></el-table-column>
        <el-table-column label="创建时间" prop="CreateDate" width="180" ></el-table-column>
         <el-table-column label="修改时间" prop="ModifyDate" width="180" ></el-table-column>
        
         <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="updataStock(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
      </el-table>
      <el-pagination
        :current-page="queryInfo.pagenum"
        :page-sizes="[5,10, 15, 20,50,100,1000,5000]"
        :page-size="queryInfo.pagesize"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </el-card>
    <el-dialog :visible.sync="dialogFormVisible" :title="titleName" width="30%">
      <el-form :label-width="formLabelWidth" :model="taskForm" :rules="mustRules" ref="taskForm">
        <el-form-item label="物料编号:" prop="ProductCode">
          <el-col :span="18">
            <el-input v-model="taskForm.ProductCode" ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="物料名称:" prop="ProductName">
          <el-col :span="18">
            <el-input v-model="taskForm.ProductName" ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="库存单位:" prop="SmallUnit">
          <el-col :span="18">
            <el-input v-model="taskForm.SmallUnit" ></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="   PO单位:" >
          <el-col :span="18">
            <el-input v-model="taskForm.BigUnit"></el-input>
          </el-col>
        </el-form-item>
         <el-form-item label=" 库存预警量:">
          <el-col :span="18">
            <el-input v-model="taskForm.Brand_Id" type="number" ></el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateProductPosition('taskForm')">确 定</el-button>
      </div>
 
    </el-dialog>
 
  </div>
</template>
<script>
import { parseTime } from "@/utils";
import Cookies from "js-cookie";
import { userInfoCookie, menuListCookie } from "@/utils/auth";
import { getDate } from "@/utils/dateTime";
export default {
  data() {
    return {
      queryInfo: {
        // 当前页
        pagenum: 1,
        // 每页显示多少条信息s
        pagesize: 5
      },
      titleName: "",
      TakeStocklist: [],
      TakeStocklistAll: [],
      total: 0,
      MaterialOperationValue: 0,
      OperationValue: 0,
      dialogFormVisible: false,
      productList: [],
      updateDate: null,
      searchParam: null,
      taskForm: {
        Product_Id: null,
        ProductCode: null,
        ProductName: null,
        SmallUnit: null,
        BigUnit: null,
        Brand_Id: null,
        Creator: null
      },
      mustRules: {
        ProductCode: [{ required: true, message: "产品编号不能为空", trigger: "blur" }],
        ProductName: [{ required: true, message: "产品名称不能为空", trigger: "blur" }],
        SmallUnit: [{ required: true, message: "库存单位不能为空", trigger: "blur" }]
      }
    };
  },
  created() {},
  mounted() {
    this.find();
  },
  methods: {
    // 监听 pagesize 改变
    handleSizeChange(newSizd) {
      this.queryInfo.pagesize = newSizd;
      this.queryInfo.pagenum = 1;
      this.find();
    },
    // 监听 页码值改变
    handleCurrentChange(newpage) {
      this.queryInfo.pagenum = newpage;
      this.find();
    },
    //excel 导出数据
    exportExcel() {
      // import("@/vendor/Export2Excel")
      this.downloadLoading = true;
      import("@/vendor/Export2Excel").then(excel => {
        const tHeader = ["物料id", "物料编号", "物料名称", "库存单位", "PO单位", "库存预警量", "创建人", "创建时间", "修改时间"];
        const filterVal = ["Product_Id", "ProductCode", "ProductName", "SmallUnit", "Brand_Id", "BigUnit", "Creator", "CreateDate", "ModifyDate"];
        debugger;
        const data = this.formatJson(filterVal, this.TakeStocklistAll);
        excel.export_json_to_excel({
          header: tHeader,
          data,
          filename: "物料明细"
        });
        this.downloadLoading = false;
      });
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === "timestamp") {
            return parseTime(v[j]);
          } else {
            return v[j];
          }
        })
      );
    },
    find() {
      const url = "/api/task/findMaterial";
      const params = {
        searchParam: this.searchParam,
        queryInfo: this.queryInfo
      };
      //MaterialOperation
      var callback = res => {
        debugger;
        if (res.result === true) {
          res.data.forEach(item => {
            item.CreateDate = getDate(item.CreateDate);
            item.ModifyDate = getDate(item.ModifyDate);
          });
 
          this.TakeStocklist = res.data;
          this.TakeStocklistAll = res.data;
          this.total = res.countPrint;
        } else {
          this.TakeStocklist = [];
          this.TakeStocklistAll = [];
          this.total = 0;
          if (res.msg == "服务端错误:undefined") {
            return this.$message.error("请打开后台服务");
          } else {
            return this.$message.success("当前条件 查不到数据!");
          }
        }
      };
      this.common.ajax(url, params, callback, true);
    },
    //表格增加汇总数量
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "合计";
          return;
        }
        if (index != 11) {
          sums[index] = "";
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += " ";
        } else {
          sums[index] = "N/A";
        }
      });
 
      return sums;
    },
 
    //删除库存
    handleDelete(index, row) {
      debugger;
      const url = "/api/task/MaterialOperation";
      this.taskForm.Creator = userInfoCookie.getUserInfo().userTrueName;
      const params = {
        taskForm: row,
        OperationValue: 3
      };
      const ref = this.dataList;
      var callback = res => {
        if (res.result) {
          this.find();
          return this.$message.success(res.msg);
        } else {
          this.find();
          return this.$message.error(res.msg);
        }
      };
      this.common.ajax(url, params, callback, ref);
    },
    //向修改页面内赋值
    updataStock(index, row) {
      this.taskForm = row;
      this.titleName = "修改物料";
      this.MaterialOperationValue = 2;
      this.dialogFormVisible = true;
    },
    //向修改页面内赋值
    addMaterial() {
      this.titleName = "新建物料";
      this.MaterialOperationValue = 1;
      this.dialogFormVisible = true;
    },
    //复位
    reset() {
      this.searchParam = "";
      this.MaterialOperationValue = 0;
      this.find();
    },
 
    // 物料新增修改删除操作
    updateProductPosition(formName) {
      this.$refs[formName].validate(valid => {
        debugger;
        if (valid) {
          const url = "/api/task/MaterialOperation";
          if (this.MaterialOperationValue === 1) {
            this.taskForm.Creator = userInfoCookie.getUserInfo().userTrueName;
          }
          const params = {
            taskForm: this.taskForm,
            OperationValue: this.MaterialOperationValue
          };
          const ref = this.dataList;
          var callback = res => {
            if (res.result) {
              this.dialogFormVisible = false;
              this.find();
              return this.$message.success(res.msg);
            } else {
              this.dialogFormVisible = false;
              this.find();
              return this.$message.error(res.msg);
            }
          };
          this.common.ajax(url, params, callback, ref);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>
<style lang="postcss" scoped>
.el-table .el-pagination {
  margin-top: 10px;
  line-height: 30px;
  margin-bottom: 0%;
}
.el-row {
  text-align: left;
}
.searchParamClass {
  width: 380px;
}
.positionTypevalue {
  width: 150px;
}
.el-card {
  padding: 0%;
  margin-bottom: 0%;
}
thead .el-table-column--selection .cell {
  display: none;
}
.displayneed {
  //display: none;
 
  display: inline-block;
  width: 180px;
}
</style>