You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
270 lines
6.6 KiB
270 lines
6.6 KiB
// monitor/pages/materialUse/materialUse.js
|
|
var Api = require("../../../utils/util.js");
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
type: 1,
|
|
listData: [],
|
|
jgList: [], //可用物料传过来的临时数据
|
|
typeList: [], //物料类型下拉
|
|
specList: [], //物料规格下拉
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
if(options.orderId){
|
|
this.setData({
|
|
orderId: options.orderId
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面显示
|
|
*/
|
|
onShow() {
|
|
// this.getTypeList()
|
|
},
|
|
//文本输入
|
|
inputText: function(e) {
|
|
let name = e.currentTarget.dataset.name
|
|
let index = e.currentTarget.dataset.index
|
|
this.setData({
|
|
[`listData[${index}].${name}`]: e.detail.value,
|
|
})
|
|
},
|
|
//数字输入
|
|
inputNum: function(e) {
|
|
let name = e.currentTarget.dataset.name
|
|
let index = e.currentTarget.dataset.index
|
|
this.setData({
|
|
[`listData[${index}].${name}`]: Number(e.detail.value),
|
|
})
|
|
},
|
|
|
|
//下拉选择
|
|
changSelect: function(e) {
|
|
let name = e.currentTarget.dataset.name
|
|
let list = e.currentTarget.dataset.list
|
|
let index = e.currentTarget.dataset.index
|
|
let indexVal = Number(e.detail.value);
|
|
this.setData({
|
|
[`listData[${index}].${name}`]: this.data[list][indexVal],
|
|
})
|
|
if(name == 'materialType'){
|
|
this.setData({
|
|
[`listData[${index}].materialSpec`]: '',//重新选择类型则清空规格
|
|
})
|
|
let key = this.data.typeKeyList[indexVal]
|
|
this.getSpecList(key)
|
|
}
|
|
},
|
|
|
|
//物料规格
|
|
getSpecList(key){
|
|
Api.req('blade-platformFittingApply/platformFittingApply/getMaterialSpecList', {
|
|
materialType: key //物料类型
|
|
// orderId: options.id
|
|
}, 'get')
|
|
.then(res => {
|
|
if(res.code == 200){
|
|
this.setData({
|
|
specList: res.data,
|
|
})
|
|
}
|
|
})
|
|
},
|
|
//物料类型
|
|
getTypeList(){
|
|
Api.req('blade-system/dict/dictionary', {
|
|
code: 'wl_type'
|
|
}, 'get')
|
|
.then(res => {
|
|
if(res.code == 200){
|
|
this.setData({
|
|
typeList: res.data.map(itm=>itm.dictValue),
|
|
typeKeyList: res.data.map(itm=>itm.dictKey),
|
|
})
|
|
}
|
|
})
|
|
},
|
|
//改变物料归属
|
|
changeType(e){
|
|
if(this.data.listData.length>0){
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '改变物料归属原数据将会被清空,确定改变吗?',
|
|
complete: (res) => {
|
|
if (res.cancel) {
|
|
if(e.detail.value == '1'){
|
|
this.setData({
|
|
type: 2
|
|
})
|
|
}else{
|
|
this.setData({
|
|
type: 1
|
|
})
|
|
}
|
|
}
|
|
if (res.confirm) {
|
|
this.setData({
|
|
listData: [],
|
|
type: e.detail.value
|
|
})
|
|
}
|
|
}
|
|
})
|
|
}else{
|
|
this.setData({
|
|
type: e.detail.value
|
|
})
|
|
}
|
|
|
|
},
|
|
//添加物料
|
|
addList(e){
|
|
let listData = this.data.listData
|
|
if(this.data.type == '1'){//物料甲供--添加物料使用
|
|
wx.navigateTo({
|
|
url: '../materialList/materialList?id=' + e.currentTarget.dataset.id
|
|
})
|
|
}else{
|
|
listData.push({
|
|
materialName: '', //物料名称
|
|
materialCode: '', //物料代码
|
|
materialType: '', //物料类型
|
|
materialSpec: '', // 物料规格
|
|
userAmount: '', //使用数量
|
|
})
|
|
this.setData({
|
|
listData
|
|
})
|
|
}
|
|
},
|
|
|
|
|
|
//添加甲供物料使用
|
|
addJgList(){
|
|
let jgList = this.data.jgList
|
|
let listData = this.data.listData
|
|
if(jgList.length>0){
|
|
jgList.forEach(item=>{
|
|
listData.push(item)
|
|
})
|
|
}
|
|
this.setData({
|
|
listData
|
|
})
|
|
},
|
|
//删除物料
|
|
delList(e){
|
|
let index = e.currentTarget.dataset.index
|
|
let listData = this.data.listData
|
|
listData.splice(index, 1)
|
|
this.setData({
|
|
listData
|
|
})
|
|
},
|
|
//保存
|
|
submitForm(e){
|
|
let listData = JSON.parse(JSON.stringify(this.data.listData))
|
|
let isCheck = true
|
|
if(this.data.listData.length == 0){
|
|
wx.showToast({
|
|
title: '请先添加物料',
|
|
icon: 'error'
|
|
})
|
|
return
|
|
}else if(this.data.type == '1'){//物料甲供
|
|
try{
|
|
listData.forEach(item=>{
|
|
if(item.userAmount<0 || item.userAmount=='' || !/^[1-9]\d*$/.test(item.userAmount)){
|
|
wx.showToast({
|
|
title: '使用数量只能是大于0的整数',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
isCheck = false
|
|
throw Error()
|
|
}
|
|
})
|
|
}catch(e) {
|
|
console.log(e)
|
|
}
|
|
}else if(this.data.type == '2'){//自备物料
|
|
try{
|
|
listData.forEach(item=>{
|
|
if(item.materialType == ''){
|
|
wx.showToast({
|
|
title: '物料类型不能为空',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
isCheck = false
|
|
throw Error()
|
|
}else if(item.materialSpec == ''){
|
|
wx.showToast({
|
|
title: '物料规格不能为空',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
isCheck = false
|
|
throw Error()
|
|
}else if(item.userAmount<0 || item.userAmount=='' || !/^[1-9]\d*$/.test(item.userAmount)){
|
|
wx.showToast({
|
|
title: '使用数量只能是大于0的整数',
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
isCheck = false
|
|
throw Error()
|
|
}
|
|
})
|
|
}catch(e) {
|
|
console.log(e)
|
|
}
|
|
}
|
|
if(!isCheck){
|
|
return
|
|
}
|
|
// console.log(1221, this.data.listData)
|
|
// return
|
|
wx.showLoading({
|
|
title: '提交中...',
|
|
mask: true
|
|
})
|
|
var data = {
|
|
orderId: this.data.orderId, //订单ID
|
|
materialFrom: this.data.type, //物料归属
|
|
userMaterila: this.data.listData, //物料明细
|
|
}
|
|
// console.log("执行",data);
|
|
// return
|
|
Api.req('blade-operationOrderMaterial/operationOrderMaterial/orderFittingUse', data, 'post', '','1')
|
|
.then(res => {
|
|
wx.hideLoading()
|
|
if (res.code == '200') {
|
|
wx.showToast({
|
|
title: '操作成功',
|
|
})
|
|
var page = getCurrentPages();
|
|
let prevPage = page[page.length - 2];
|
|
setTimeout(function() {
|
|
prevPage.getList();
|
|
wx.navigateBack({})
|
|
}, 1000)
|
|
} else {
|
|
wx.showToast({
|
|
title: res.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}) |