diff --git a/src/pages/exchangecode/edit/edit.js b/src/pages/exchangecode/edit/edit.js index c93fe996..d859052c 100644 --- a/src/pages/exchangecode/edit/edit.js +++ b/src/pages/exchangecode/edit/edit.js @@ -57,6 +57,8 @@ export default class exchangedit extends React.Component{ reseller:null, payment_direction:["对私账户","对公账户","预付款扣除"], isAudit:false, + approvalsStatus:false, + oldTable:[] } } @@ -70,6 +72,7 @@ export default class exchangedit extends React.Component{ let code_batch_id = sessionStorage.getItem("code_id") let approval_id = sessionStorage.getItem("approval_id") + let approval_status = sessionStorage.getItem("approval_status") if(approval_id > 0) { getApprovalsInfo(approval_id).then(res=>{ @@ -92,9 +95,25 @@ export default class exchangedit extends React.Component{ range:req.update_product } + + + if(req.new_product.length > 0) { - codeInfo.range = codeInfo.range.concat(req.new_product); + + if(approval_status == 7) + { + req.new_product = _.map(req.new_product,(item)=>{ + item.checked = false + return item + }) + + + + } + + codeInfo.range = codeInfo.range.concat(req.new_product); + } let new_ids = _.map(req.new_product,(o)=>{ @@ -109,22 +128,45 @@ export default class exchangedit extends React.Component{ handelResponse(res,(req,msg)=>{ codeInfo.stock = req.stock; + this.setState({oldTable:req.code_batch_stock}) + console.log("老数据",this.state.oldTable) + let deleteArr = [] + for(let i =0;i < delete_product.length;i++) + { + let deleteData = req.code_batch_stock.find(o=>o.product_id == delete_product[i]) + deleteData.checked = false; + deleteArr.push(deleteData) + } + + console.log("删除数组",deleteArr) this.setState({codeInfo:codeInfo}) this.setState({isload:true}); + codeInfo.range = codeInfo.range.concat(deleteArr) + + + + let table = _.map(codeInfo.range,(res)=>{ let obj = req.code_batch_stock.find(o=>o.product_id == res.product_id); + + res.usage = obj ? obj.usage : 0; res.stock =obj ? obj.stock : res.quantity - res.usage; - res.checked = true; + res.checked = res.hasOwnProperty("checked") ? res.checked : true; + if(approval_status == 7 && obj) + { + res.checked = true + } + return res }); - this.setState({deleteProduct:delete_product}) + this.setState({deleteProduct:[]}) this.setState({tempdata:codeInfo.range}) @@ -134,11 +176,17 @@ export default class exchangedit extends React.Component{ let obj = {}; obj.key = res.product_id; obj.text= res.product_name; - this.state.oldProduct.push(res.product_id); + if(new_ids.indexOf(res.product_id) < 0) + { + this.state.oldProduct.push(res.product_id); + } arr.push(obj) return obj; }) + + + this.setState({rankoptions:arr}) this.setState({rank:arr}) @@ -317,33 +365,31 @@ export default class exchangedit extends React.Component{ let temp = addProduct.filter((item)=>{ return deleteProduct.indexOf(item.product_id) > -1 }) - let tempIds = _.map(temp,(item)=>{ - return item.product_id - }) + // let tempIds = _.map(temp,(item)=>{ + // return item.product_id + // }) - if(temp.length > 0) - { + // if(temp.length > 0) + // { - addProduct = addProduct.filter((item)=>{ - return tempIds.indexOf(item.product_id) < 0 - }) + // // addProduct = addProduct.filter((item)=>{ + // // return tempIds.indexOf(item.product_id) < 0 + // // }) - console.log("新增",addProduct) - - let updateAdd =_.filter(addProduct,(item)=>{ + // // let updateAdd =_.filter(addProduct,(item)=>{ - return deleteProduct.indexOf(item.product_id) > -1 - }) + // // return deleteProduct.indexOf(item.product_id) > -1 + // // }) - updateProduct = updateProduct.concat(updateAdd); + // // updateProduct = updateProduct.concat(updateAdd); - } + // } @@ -420,62 +466,73 @@ export default class exchangedit extends React.Component{ } let code_batch_id = sessionStorage.getItem("code_id") let data = this.buildData() - getIsRequireApproval(code_batch_id,data).then((res)=>{ - handelResponse(res,(req,msg)=>{ + + let approval_id = sessionStorage.getItem("approval_id") + + if(approval_id <= 0) + { + this.setState({audit_visible:true}) + } + else{ + getApprovalsStatus(approval_id).then((res)=>{ + handelResponse(res,(req,msg)=>{ + if(req.status == 0) + { + this.setState({approvalsStatus:true}) + this.setState({recall_visible:true}) + } + if(req.status == 1) + { + Notify.error("进行中的批次不能提交审核") + + } + if(req.status == 2 || req.status == 3){ - if(req.is_require_approval) - { - this.setState({audit_visible:true}) - } - else{ - this.submitCodeData(); - } - - - },(err)=>{ - Notify.error(err) - }) - }) + getIsRequireApproval(code_batch_id,data).then((res)=>{ + handelResponse(res,(req,msg)=>{ + + if(req.is_require_approval) + { + this.setState({audit_visible:true}) + } + else{ + this.submitCodeData(); + } + },(err)=>{ + Notify.error(err) + }) + }) + + } + },(err)=>{ + Notify.error(err) + }) + }) + + } + + + + } } onConfirm(){ - let approval_id = sessionStorage.getItem("approval_id") + this.setState({audit_visible:false}) - if(approval_id <= 0) - { - this.submitCodeData(); - }else{ - - getApprovalsStatus(approval_id).then((res)=>{ - handelResponse(res,(req,msg)=>{ - if(req.status == 0) - { - this.setState({recall_visible:true}) - } - if(req.status == 1) - { - Notify.error("进行中的批次不能提交审核") - setTimeout(()=>{ - this.props.history.push('/home/key-list/'); - },2000) - - } - if(req.status == 2 || req.status == 3){ - - this.submitCodeData(); - - } - },(err)=>{ - Notify.error(err) - }) - }) - - - - } + this.submitCodeData(); + // if(approval_id <= 0) + // { + // this.submitCodeData(); + // }else{ + // if(this.state.approvalsStatus==true) + // { + // this.setState({recall_visible:true}) + // } + + // } } @@ -727,6 +784,11 @@ export default class exchangedit extends React.Component{ clearInterval(timer_c) this.setState({approvalLoading:false}) Notify.success("撤销成功,请重新提交审核") + + + + + } let time = this.state.timer - 1; this.setState({timer:time}) diff --git a/src/pages/exchangecode/list/list.js b/src/pages/exchangecode/list/list.js index f946e846..68c17d85 100644 --- a/src/pages/exchangecode/list/list.js +++ b/src/pages/exchangecode/list/list.js @@ -175,6 +175,7 @@ export default class acclist extends React.Component{ sessionStorage.setItem("code_id",rowData.id) sessionStorage.setItem('breaknav',JSON.stringify(activerou)); sessionStorage.setItem("approval_id",rowData.approval_id) + sessionStorage.setItem("approval_status",rowData.status) window.open('#/home/exchangecode-edit'); } tabFn(index){