var _this; var nowTime = new Date().getTime(); var periodChart, typeChart; new Vue({ el: '#app', filters: { getImgList(key){ return [fileUrl+key]; } }, data: function() { return { queryParams: { pageNum: 1, pageSize: 10, createBy: "lyzh" }, imgUrl: '', storageList: [], allTotal: 0, stockTypeList: [], title: "", drawerDolag: false, storageForm: {}, rules: { sparePartNumber: [{ required: true, message: "备件编号不能为空", trigger: "blur" }], sparePartName: [{ required: true, message: "备件名称不能为空", trigger: "blur" }], sparePartSpecifications: [{ required: true, message: "备件规格不能为空", trigger: "blur" }], sparePartBrand: [{ required: true, message: "备件品牌不能为空", trigger: "blur" }], sparePartUnitPrice: [{ required: true, message: "备件单价期不能为空", trigger: "blur" }], sparePartQuantity: [{ required: true, message: "库存总量不能为空", trigger: "blur" }], sparePartStockType: [{ required: true, message: "备件类型不能为空", trigger: "blur" }], sparePartAccessExplain: [{ required: true, message: "出入库说明不能为空", trigger: "blur" }] }, upHeaders: {}, srorageQuantityOut: {}, storageOutTotal: 0, srorageQuantityIn: {}, storageInTotal: 0, drawerOutIn: false, sparePartAccessType: '10', submitForm: {} } }, created() { _this = this; _this.imgUrl = fileUrl; _this.upHeaders = { "Authorization": "Bearer " + getCookie("tzToken") } let _obj = getUseDict("com_spare_part_stock_type") setTimeout(()=>{ _this.stockTypeList = _obj["com_spare_part_stock_type"]; this.getList(); }, 500); }, mounted:function(){ }, methods: { getList(){ // setFileLogin() getStorageList(_this.queryParams).then((_res) => { _this.storageList = _res.rows; _this.allTotal = _res.total; }); }, handleQuery() { _this.queryParams.pageNum = 1; this.getList(); }, resetQuery() { _this.queryParams = { pageNum: 1, pageSize: 10 } this.handleQuery(); }, handleCurrentChange(val) { if(val != _this.queryParams.pageNum){ _this.queryParams.pageNum = val; this.getList(); } }, handleUpdate(row) { this.reset(); var sparePartId = row.sparePartId; getStorageDetail(sparePartId).then(response => { _this.storageForm = response.data; _this.drawerDolag = true; _this.title = "修改备件"; }); }, handleAdd(){ this.reset(); _this.drawerDolag = true; _this.title = "添加备件"; }, reset() { _this.storageForm = { sparePartId: null, sparePartNumber: "", sparePartName: "", sparePartSpecifications: "", sparePartBrand: "", sparePartStorageLocation: "", sparePartStockType: "", sparePartGoodsType: "", sparePartQuantity: "", createBy: "", createTime: "", updateBy: "", updateTime: "", remark: "", sparePartUnitPrice: "", impa: "", filePath: "", }; }, handleDelete(row) { this.$confirm('是否确认删除改条备件记录为"' + row.sparePartId + '"的数据项?').then(function () { return DelStorage(row.sparePartId) }).then(() => { this.getList(); this.$message({ showClose: true, message: "删除成功", type: 'success' }); }).catch(() => { }); }, handleSubmitForm(){ if(_this.storageForm.sparePartName.length&&_this.storageForm.sparePartNumber.length&&_this.storageForm.sparePartName.length&&_this.storageForm.sparePartSpecifications.length&&_this.storageForm.sparePartStockType.length){ if (_this.storageForm.sparePartId != null) { updateStorage(_this.storageForm).then(response => { this.$message({ showClose: true, message: "修改成功", type: 'success' }); _this.drawerDolag = false; this.getList(); }); } else { addStorage(_this.storageForm).then(response => { this.$message({ showClose: true, message: "新增成功", type: 'success' }); _this.drawerDolag = false; this.getList(); }); } }else{ this.$message.error('请先填写完信息!'); } }, handleAvatarSuccess(res, file) { _this.storageForm.filePath = res.fileName; }, beforeAvatarUpload(file) { const fileType = ["png", "jpg", "jpeg"]; const isLt2M = file.size / 1024 / 1024 < 5; let fileExtension = ""; if (file.name.lastIndexOf(".") > -1) { fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1); } isImg = fileType.some(type => { if (file.type.indexOf(type) > -1) return true; if (fileExtension && fileExtension.indexOf(type) > -1) return true; return false; }); if (!isImg) { this.$message.error('上传头像图片只能是 "png", "jpg", "jpeg" 格式!'); } if (!isLt2M) { this.$message.error('上传头像图片大小不能超过 5MB!'); } return isImg && isLt2M; }, handleStorageOrder(key){ _this.drawerOutIn = true; _this.sparePartAccessType = key; _this.submitForm = { sparePartAccessExplain: "", sparePartAccessType: "", sparePartAccessDetailsList: [] }; }, handleStorageOut(row){ _this.storageOutTotal = this.addStorageTotal(_this.srorageQuantityOut, row); }, handleStorageIn(row){ _this.storageInTotal = this.addStorageTotal(_this.srorageQuantityIn, row); }, updateStorageOut(row){ _this.storageOutTotal = this.updateStorageTotal(_this.srorageQuantityOut, row); }, updateStorageIn(row){ _this.storageInTotal = this.updateStorageTotal(_this.srorageQuantityIn, row); }, removeQuantityIn(row){ _this.storageInTotal = this.removeStorageTotal(_this.srorageQuantityIn, row); }, removeQuantityOut(row){ _this.storageOutTotal = this.removeStorageTotal(_this.srorageQuantityOut, row); }, clrearQuantityIn(msg){ _this.srorageQuantityIn = {}; _this.storageInTotal = 0; if(msg){ this.$message.success('已清空') } }, clrearQuantityOut(msg){ _this.srorageQuantityOut = {}; _this.storageOutTotal = 0; if(msg){ this.$message.success('已清空') } }, submitOrder(){ if(_this.submitForm.sparePartAccessExplain.length){ _this.submitForm.sparePartAccessDetailsList = Object.values(_this.sparePartAccessType == 10 ? _this.srorageQuantityIn : _this.srorageQuantityOut); _this.submitForm.sparePartAccessType = _this.sparePartAccessType; setInOutOrder(_this.submitForm).then((_res) =>{ if(_res.code == 200){ this.$message.success('提交成功!'); this.getList(); _this.submitForm = {}; _this.drawerOutIn = false; _this.sparePartAccessType == 10 ? _this.clrearQuantityIn(false) : _this.clrearQuantityOut(false) }else{ this.$message.success(_res.msg) } }) }else{ this.$message.error('请先填写完信息!'); } }, removeStorageTotal(_list, item){ delete _list[item.sparePartId] let total = 0; Object.values(_list).map((item) => { total += item.sparePartRetrievalQuantity; }); this.$message.success('已删除') return total; }, updateStorageTotal(_list, item){ if (_list[item.sparePartId] == undefined) { item.sparePartRetrievalQuantity = 1 _list[item.sparePartId] = item; } else { _list[item.sparePartId].sparePartRetrievalQuantity = parseInt(item.sparePartRetrievalQuantity) } let total = 0; Object.values(_list).map((item) => { total += item.sparePartRetrievalQuantity; }); this.$message.success('修改成功') return total; }, addStorageTotal(_list, item){ if (_list[item.sparePartId] == undefined) { item.sparePartRetrievalQuantity = 1 _list[item.sparePartId] = item } else { _list[item.sparePartId].sparePartRetrievalQuantity++ } let total = 0; Object.values(_list).map((item) => { total += item.sparePartRetrievalQuantity; }); this.$message.success('添加成功') return total; } } })