diff --git a/src/pages/exchangecode/add/add.js b/src/pages/exchangecode/add/add.js index 72f7b0db..2c623d16 100644 --- a/src/pages/exchangecode/add/add.js +++ b/src/pages/exchangecode/add/add.js @@ -1287,7 +1287,7 @@ export default class acclist extends React.Component { style={{ width: "95%", margin: "10px auto" }} title={"基本信息"} > -
+
+
是否取消本次操作?
, - onConfirm:()=>{ - window.location.replace('#/home/exchangecode-list'); - }, - onCancel: this.onCancel, - className:'questModal', - parentComponent: this - }); - } - - - buildData(){ - let code_batch_id = sessionStorage.getItem("code_id") - - let range = [] - _.map(this.state.rank,(o)=>{ - - // if(this.state.oldProduct.indexOf(o.key) < 0) - // { - range.push(o.text) ; - // } - }) - let selectData = this.refs.tempdata.getSelectData(); - let addProduct = selectData.filter((o)=>{ - - return this.state.oldProduct.indexOf(o.product_id) < 0 - }) - - let updateIds = [] - let updateProduct = [] - _.map(selectData,(o)=>{ - - if(this.state.oldProduct.indexOf(o.product_id) > -1) - { - updateIds.push(o.product_id) - let _object = {} - _object.contract_price= o.contract_price; - _object.cost_price= o.cost_price; - _object.describe_url= o.describe_url; - _object.official_price= o.official_price; - _object.product_id= o.product_id - _object.account_type =o.account_type; - _object.product_name= o.product_name - _object.product_type= o.product_type - _object.quantity= o.quantity - _object.show_url = o.show_url - _object.detail_url = o.detail_url - _object.map_product_name = o.map_product_name - updateProduct.push(_object) - } - }); - - - let deleteProduct= _.differenceWith(this.state.oldProduct, updateIds, _.isEqual); - - deleteProduct = deleteProduct.filter((item)=>{return this.state.new_product.indexOf(item) < 0}) - console.log(this.state.new_product) - if(this.state.deleteProduct.length > 0) - { - deleteProduct = deleteProduct.concat(this.state.deleteProduct).map(Number) - } - - let temp = addProduct.filter((item)=>{ - return deleteProduct.indexOf(item.product_id) > -1 - }) - updateIds = _.map(updateProduct,(o)=>{ - return o.product_id; - }) - deleteProduct = _.filter(deleteProduct,(o)=>{ - return updateIds.indexOf(o) < 0 - }) - let data ={ - "reseller_id":this.state.reseller.id, - "reseller_name":this.state.reseller.name, - "company_name":this.state.reseller.company_name, - "receive_email":this.state.reseller.receive_email, - "payment_direction":this.state.payment_direction[this.state.paytype - 1], - "title": this.state.codeInfo.code_name, - "range": range, - "describe": this.state.codeInfo.describe, - "begin_time": this.state.codeInfo.date_time[0], - "end_time": this.state.codeInfo.date_time[1], - "quantity":this.state.codeInfo.issued, - "new_product":addProduct, - "update_product":updateProduct, - "delete_product": deleteProduct, - } - - return data - } - submitCodeData(){ - - if(!this.state.reseller) - { - Notify.error("该兑换码对应分销商不存在") - return - } - - let code_batch_id = sessionStorage.getItem("code_id") - let data = this.buildData(); - putCodesBatch(code_batch_id,data).then((res)=>{ - handelResponse(res,(req,msg)=>{ - console.log(req) - let model2 = this.state.model; - model2.show_url = req.path; - this.setState({model:model2}) - - Notify.clear(); - Notify.success(msg); - setTimeout(()=>{ - window.location.replace('#/home/exchangecode-list'); - },1000); - },(error)=>{ - Notify.error(error); - }) - }); - } - onPayTypeChange(e){ - this.setState({paytype:e.target.value}) - } - - - - submit(){ - - if(this.refs.code_info.validator() && this.refs.code_rule.validator() ) - { - if(this.state.uploading ) - { - - Notify.error("还有图片上传中,不可提交") - return - } - let code_batch_id = sessionStorage.getItem("code_id") - let data = this.buildData() - - let approval_id = sessionStorage.getItem("approval_id") - - if(approval_id <= 0) - { - 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) - }) - }) - } - 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 || req.status == 2 || req.status == 3){ - - 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 new_ids = _.map(req.new_product, (o) => { + return o.product_id; + }); - this.setState({audit_visible:false}) - this.submitCodeData(); - // if(approval_id <= 0) - // { - // this.submitCodeData(); - // }else{ - // if(this.state.approvalsStatus==true) - // { - // this.setState({recall_visible:true}) - // } + this.setState({ new_product: new_ids }); + let delete_product = req.delete_product; + let payment_direction = req.payment_direction; + getCodesDetail(code_batch_id) + .then((res) => { + handelResponse( + res, + (req, msg) => { + codeInfo.stock = req.stock; + this.setState({ plan_time: req.plan.end_time }); + this.setState({ oldTable: req.code_batch_stock }); - // } - - } + let deleteArr = []; - onTypeChange(e){ - let model2 = this.state.model; - model2.type = e.target.value; - this.setState({model:model2}) - } - + 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); + } + 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 + ); - - onUploadError = (type, data) => { - if (type === 'overMaxAmount') { - Notify.error(`最多可上传 ${data.maxAmount} 张图片`); - } else if (type === 'overMaxSize') { - Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`); - } - }; - addProduct(){ - sessionStorage.setItem("productData",JSON.stringify( this.state.tempdata)) - this.setState({drawerVisible2:true}) - this.setState({productData:null}) - - this.setState({product_title:"新建商品"}) - } + res.usage = obj ? obj.usage : 0; + res.stock = obj ? obj.stock : res.quantity - res.usage; + res.checked = res.hasOwnProperty("checked") + ? res.checked + : true; + if (approval_status == 7 && obj) { + res.checked = true; + } - onChangeCombinedDate(e){ - let model2 = this.state.codeInfo; - model2.date_time = e; - this.setState({codeInfo:model2}) - } - + return res; + }); - async productSubmit(){ - let visible = await this.refs.product.submit() - if(visible) - { - this.setState({drawerVisible2:false}) - setTimeout(()=>{ - let data = JSON.parse(sessionStorage.getItem("productData")); - - - let temp = _.map(data,(item)=>{ - - let index = this.state.tempdata.findIndex((o)=>{return o.product_id == item.product_id}) - - - if(index > -1) - { - item.checked = this.state.tempdata[index].checked - } - - return item - }) - - - - this.setState({tempdata:temp }) - let arr = []; - _.map(data,(res)=>{ - let obj = {}; - obj.key = res.product_id; - obj.text= res.product_name; - arr.push(obj) - return obj; - }) - this.setState({rankoptions:arr}) - },500) - } - } - + this.setState({ deleteProduct: [] }); - - - - - onUploadError = (type, data) => { - if (type === 'overMaxAmount') { - Notify.error(`最多可上传 ${data.maxAmount} 张图片`); - } else if (type === 'overMaxSize') { - Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`); - } - }; - - onUploadChange1(file,row){ - - if(file.length > 0 && file[0].status == "success") - { - let rowIndex =this.state.tempdata.findIndex((o)=>{return o.product_id == row.product_id}) - this.state.tempdata[rowIndex].show_url =file[0].src; - this.setState({tempdata:this.state.tempdata}) - - } - }; - onUploadChange2(file,row){ - if(file.length > 0 && file[0].status == "success") - { - let rowIndex =this.state.tempdata.findIndex((o)=>{return o.product_id == row.product_id}) - - this.state.tempdata[rowIndex].describe_url =file[0].src; - this.setState({tempdata:this.state.tempdata}) - } - - } - - onNameChange(e,row){ - let rowIndex =this.state.tempdata.findIndex((o)=>{return o.product_id == row.product_id}) - this.state.tempdata[rowIndex].product_name =e.target.value; - this.setState({tempdata:this.state.tempdata}) - } - onQuantityChange(e,row){ - - this.setState({tempdata:this.state.tempdata}) - let value = e.target.value; - let rowIndex =this.state.tempdata.findIndex((o)=>{return o.product_id == row.product_id}) - if(value - this.state.tempdata[rowIndex].usage < 0) - { - Notify.error(`库存总数量不能小于已使用库存量`); - - return; - } - - this.state.tempdata[rowIndex].quantity = value; - this.state.tempdata[rowIndex].stock = value - this.state.tempdata[rowIndex].usage ; - this.setState({tempdata:this.state.tempdata}) - } - onPriceChange(e,row){ - - let str = e.target.value; - let value= str.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.') - - - let rowIndex =this.state.tempdata.findIndex((o)=>{return o.product_id == row.product_id}) - - this.state.tempdata[rowIndex].contract_price = value; - this.setState({tempdata:this.state.tempdata}) - } - - - onUpload = (file, report) => { - return new Promise((resolve, reject) => { - let path = "" - let formdata= new FormData(); - formdata.append("file",file) - formdata.append("path","common_image") - uploadImg(formdata).then((res)=>{ - handelResponse(res,(req,msg)=>{ - path = req.path; - - },(err)=>{ - reject(); - }) - }); - - let count = 0; - const update = () => { - if(path) - { - - resolve( - path - ); - - } - else{ - - if (count < 100) { - count += 2; - report(count); - setTimeout(update, 500); - console.log("上传中") - } - else{ - - reject(); - } - } - - - }; - setTimeout(update, 500); - }); - - }; - + this.setState({ tempdata: codeInfo.range }); - - onDisabledCombinedDate = (val)=>{ - let str = moment(val).format("YYYY-MM-DD HH:mm:ss") - let isBetween = moment(str).isBetween(this.state.codeInfo.date_time[0],this.state.plan_time,null,'(]'); - return !isBetween - } - - - - - onDisabledTime= (date, type) => { - - const min = new Date(); - const hour = min.getHours(); - const minute = min.getMinutes(); - const second = min.getSeconds(); - const isSame = isSameDay(date, min); - - - return isSame ? { - disabledHours: () => initArray(hour), - disabledMinutes: hourValue => - hourValue === hour ? initArray(minute) : [], - disabledSeconds: (hourValue, minuteValue) => - hourValue === hour && minuteValue === minute - ? initArray(second) - : [], - } - : {}; - - }; - - onDisabledRange = (date, type)=>{ - let step1 = JSON.parse (sessionStorage.getItem("step1")); - // let str = moment(date).format("YYYY-MM-DD HH:mm:ss") - // let isBetween = moment(str).isBetween(step1.begin_time,step1.end_time,null,'(]'); - let isdisabled = false; - let str = moment(date).format("YYYY-MM-DD HH:mm:ss") - - - if( type == "end" ) - { - isdisabled = moment(str).isAfter(this.state.plan_time) - } - return isdisabled - } - - onReCall(){ - let approval_id = sessionStorage.getItem("approval_id") - this.setState({recall_visible:false}) - terminateApprovals(approval_id).then((res)=>{ - handelResponse(res,(req,msg)=>{ - this.setState({approvalLoading:true}) - let timer_c = setInterval(()=>{ - if(this.state.timer <= 0) - { - clearInterval(timer_c) - this.setState({approvalLoading:false}) - Notify.success("撤销成功,请重新提交审核") - } - let time = this.state.timer - 1; - this.setState({timer:time}) - },1000) - },(err)=>{ - Notify.error(err) - }) - }) - } - - - productEditShow(rowData){ - this.setState({drawerVisible2:true}) - this.setState({productData:rowData}) - this.setState({product_title:"编辑商品"}) - } - render(){ - - //基本信息 - const codeInfo = { - code_name: [ - { type: "required", message: "请输入兑换码名称"}, - - ], - } - - - //基本规则 - const rulesInfo = { - date_time: [ - { type: "required", message: "请选择生效时间段"}, - - ], - } + let arr = []; + let temp = []; + _.map(codeInfo.range, (res) => { + let obj = {}; + obj.key = res.product_id; + obj.text = res.product_name; + if (new_ids.indexOf(res.product_id) < 0) { + this.state.oldProduct.push(res.product_id); + } + if ( + table.find((o) => o.product_id == res.product_id) + .checked == true + ) { + temp.push(obj); + } + arr.push(obj); + return obj; + }); + this.setState({ rankoptions: arr }); + this.setState({ rank: temp }); + if (payment_direction) { + let index = + this.state.payment_direction.indexOf( + payment_direction + ); + this.setState({ paytype: index + 1 }); + } + }, + (err) => {} + ); + }) + .catch((err) => {}); + }, + (err) => {} + ); + }) + .catch((err) => {}); + } else { + getCodesDetail(code_batch_id) + .then((res) => { + handelResponse( + res, + (req, msg) => { + let codeInfo = { + code_name: req.title, + issued: req.quantity, + stock: req.stock, + describe: req.describe, + date_time: [req.begin_time, req.end_time], + range: req.code_batch_stock, + }; + this.setState({ plan_time: req.plan.end_time }); + //获取分销商 + getReseller(req.plan.reseller_id).then((res) => { + handelResponse(res, (req, msg) => { + req.receive_email = req.contact_email[0]; + this.setState({ reseller: req }); + this.setState({ phone_list: req.contact_phone }); + this.setState({ email_list: req.contact_email }); + }); + }); - const Column2 = [ - { - title: '商品ID', - name: 'product_id', - prop:'product_id', - width:'auto', - type: "normal", - },{ - title: '商品名称', - width:'auto', - prop:'product_name', - name:'product_name', - type: "slot", - - }, { - title: '当前成本价格', - prop:'cost_price', - name: 'cost_price', - width:'auto', - type: "normal", - }, { - title: '合同价', - name: 'contract_price', - prop:'contract_price', - type: "slot", - width:'auto', - }, - { - title: '商品官方价', - type: "normal", - prop:'official_price', - width:'auto' - }, - { - title: '库存总数量', - prop: 'quantity', - name: 'quantity', - type: "slot", - width:'auto', - }, - { - title: '剩余数量', - prop: 'stock', - name: 'stock', - type: "normal", - width:'auto', - }, - { - title: '已使用数量', - prop: 'usage', - name: 'usage', - type: "normal", - width:'auto', - }, - { - title: '操作', - prop: 'edit', - name: 'edit', - type: "slot", - width:'auto', - }, - // { - // title: '商品图', - // prop: 'describe_url', - // name: 'describe_url', - // type: "slot", - // width:'auto', - // }, - ]; - + this.setState({ codeInfo: codeInfo }); + this.setState({ isload: true }); + let table = _.map(req.code_batch_stock, (res) => { + res.checked = true; + return res; + }); + this.setState({ tempdata: req.code_batch_stock }); + sessionStorage.setItem( + "productData", + JSON.stringify(req.code_batch_stock) + ); + let arr = []; + _.map(req.code_batch_stock, (res) => { + let obj = {}; + obj.key = res.product_id; + obj.text = res.product_name; + this.state.oldProduct.push(res.product_id); + arr.push(obj); + return obj; + }); - return( + this.setState({ rankoptions: arr }); + this.setState({ rank: arr }); + }, + (err) => {} + ); + }) + .catch((err) => {}); + } + } + onRankChange(e) { + _.forEach(this.state.tempdata, (item) => { + item.checked = + e.findIndex((checks) => { + return checks.key == item.product_id; + }) > -1; + }); + this.setState({ tempdata: this.state.tempdata }); + this.setState({ rank: e }); + } + + cancel() { + //取消二次弹出框 + Sweetalert.confirm({ + type: "warning", + closeBtn: true, + title: "确认操作", + content:是否取消本次操作?
, + onConfirm: () => { + window.location.replace("#/home/exchangecode-list"); + }, + onCancel: this.onCancel, + className: "questModal", + parentComponent: this, + }); + } + + buildData() { + let code_batch_id = sessionStorage.getItem("code_id"); + + let range = []; + _.map(this.state.rank, (o) => { + // if(this.state.oldProduct.indexOf(o.key) < 0) + // { + range.push(o.text); + // } + }); + let selectData = this.refs.tempdata.getSelectData(); + let addProduct = selectData.filter((o) => { + return this.state.oldProduct.indexOf(o.product_id) < 0; + }); + + let updateIds = []; + let updateProduct = []; + _.map(selectData, (o) => { + if (this.state.oldProduct.indexOf(o.product_id) > -1) { + updateIds.push(o.product_id); + let _object = {}; + _object.contract_price = o.contract_price; + _object.cost_price = o.cost_price; + _object.describe_url = o.describe_url; + _object.official_price = o.official_price; + _object.product_id = o.product_id; + _object.account_type = o.account_type; + _object.product_name = o.product_name; + _object.product_type = o.product_type; + _object.quantity = o.quantity; + _object.show_url = o.show_url; + _object.detail_url = o.detail_url; + _object.map_product_name = o.map_product_name; + updateProduct.push(_object); + } + }); + + let deleteProduct = _.differenceWith( + this.state.oldProduct, + updateIds, + _.isEqual + ); + + deleteProduct = deleteProduct.filter((item) => { + return this.state.new_product.indexOf(item) < 0; + }); + console.log(this.state.new_product); + if (this.state.deleteProduct.length > 0) { + deleteProduct = deleteProduct + .concat(this.state.deleteProduct) + .map(Number); + } + + let temp = addProduct.filter((item) => { + return deleteProduct.indexOf(item.product_id) > -1; + }); + updateIds = _.map(updateProduct, (o) => { + return o.product_id; + }); + deleteProduct = _.filter(deleteProduct, (o) => { + return updateIds.indexOf(o) < 0; + }); + let data = { + reseller_id: this.state.reseller.id, + reseller_name: this.state.reseller.name, + company_name: this.state.reseller.company_name, + receive_email: this.state.reseller.receive_email, + payment_direction: this.state.payment_direction[this.state.paytype - 1], + title: this.state.codeInfo.code_name, + range: range, + describe: this.state.codeInfo.describe, + begin_time: this.state.codeInfo.date_time[0], + end_time: this.state.codeInfo.date_time[1], + quantity: this.state.codeInfo.issued, + new_product: addProduct, + update_product: updateProduct, + delete_product: deleteProduct, + }; + + return data; + } + submitCodeData() { + if (!this.state.reseller) { + Notify.error("该兑换码对应分销商不存在"); + return; + } + + let code_batch_id = sessionStorage.getItem("code_id"); + let data = this.buildData(); + putCodesBatch(code_batch_id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + console.log(req); + let model2 = this.state.model; + model2.show_url = req.path; + this.setState({ model: model2 }); + + Notify.clear(); + Notify.success(msg); + setTimeout(() => { + window.location.replace("#/home/exchangecode-list"); + }, 1000); + }, + (error) => { + Notify.error(error); + } + ); + }); + } + onPayTypeChange(e) { + this.setState({ paytype: e.target.value }); + } + + submit() { + if (this.refs.code_info.validator() && this.refs.code_rule.validator()) { + if (this.state.uploading) { + Notify.error("还有图片上传中,不可提交"); + return; + } + let code_batch_id = sessionStorage.getItem("code_id"); + let data = this.buildData(); + + let approval_id = sessionStorage.getItem("approval_id"); + + if (approval_id <= 0) { + 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); + } + ); + }); + } 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 || req.status == 2 || req.status == 3) { + 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() { + this.setState({ audit_visible: false }); + this.submitCodeData(); + // if(approval_id <= 0) + // { + // this.submitCodeData(); + // }else{ + // if(this.state.approvalsStatus==true) + // { + // this.setState({recall_visible:true}) + // } + + // } + } + + onTypeChange(e) { + let model2 = this.state.model; + model2.type = e.target.value; + this.setState({ model: model2 }); + } + + onUploadError = (type, data) => { + if (type === "overMaxAmount") { + Notify.error(`最多可上传 ${data.maxAmount} 张图片`); + } else if (type === "overMaxSize") { + Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`); + } + }; + addProduct() { + sessionStorage.setItem("productData", JSON.stringify(this.state.tempdata)); + this.setState({ drawerVisible2: true }); + this.setState({ productData: null }); + + this.setState({ product_title: "新建商品" }); + } + + onChangeCombinedDate(e) { + let model2 = this.state.codeInfo; + model2.date_time = e; + this.setState({ codeInfo: model2 }); + } + + async productSubmit() { + let visible = await this.refs.product.submit(); + if (visible) { + this.setState({ drawerVisible2: false }); + setTimeout(() => { + let data = JSON.parse(sessionStorage.getItem("productData")); + + let temp = _.map(data, (item) => { + let index = this.state.tempdata.findIndex((o) => { + return o.product_id == item.product_id; + }); + + if (index > -1) { + item.checked = this.state.tempdata[index].checked; + } + + return item; + }); + + this.setState({ tempdata: temp }); + let arr = []; + _.map(data, (res) => { + let obj = {}; + obj.key = res.product_id; + obj.text = res.product_name; + arr.push(obj); + return obj; + }); + this.setState({ rankoptions: arr }); + }, 500); + } + } + + onUploadError = (type, data) => { + if (type === "overMaxAmount") { + Notify.error(`最多可上传 ${data.maxAmount} 张图片`); + } else if (type === "overMaxSize") { + Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`); + } + }; + + onUploadChange1(file, row) { + if (file.length > 0 && file[0].status == "success") { + let rowIndex = this.state.tempdata.findIndex((o) => { + return o.product_id == row.product_id; + }); + this.state.tempdata[rowIndex].show_url = file[0].src; + this.setState({ tempdata: this.state.tempdata }); + } + } + onUploadChange2(file, row) { + if (file.length > 0 && file[0].status == "success") { + let rowIndex = this.state.tempdata.findIndex((o) => { + return o.product_id == row.product_id; + }); + + this.state.tempdata[rowIndex].describe_url = file[0].src; + this.setState({ tempdata: this.state.tempdata }); + } + } + + onNameChange(e, row) { + let rowIndex = this.state.tempdata.findIndex((o) => { + return o.product_id == row.product_id; + }); + this.state.tempdata[rowIndex].product_name = e.target.value; + this.setState({ tempdata: this.state.tempdata }); + } + onQuantityChange(e, row) { + this.setState({ tempdata: this.state.tempdata }); + let value = e.target.value; + let rowIndex = this.state.tempdata.findIndex((o) => { + return o.product_id == row.product_id; + }); + if (value - this.state.tempdata[rowIndex].usage < 0) { + Notify.error(`库存总数量不能小于已使用库存量`); + + return; + } + + this.state.tempdata[rowIndex].quantity = value; + this.state.tempdata[rowIndex].stock = + value - this.state.tempdata[rowIndex].usage; + this.setState({ tempdata: this.state.tempdata }); + } + onPriceChange(e, row) { + let str = e.target.value; + let value = str + .replace(/[^\d^\.]+/g, "") + .replace(".", "$#$") + .replace(/\./g, "") + .replace("$#$", "."); + + let rowIndex = this.state.tempdata.findIndex((o) => { + return o.product_id == row.product_id; + }); + + this.state.tempdata[rowIndex].contract_price = value; + this.setState({ tempdata: this.state.tempdata }); + } + + onUpload = (file, report) => { + return new Promise((resolve, reject) => { + let path = ""; + let formdata = new FormData(); + formdata.append("file", file); + formdata.append("path", "common_image"); + uploadImg(formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + path = req.path; + }, + (err) => { + reject(); + } + ); + }); + + let count = 0; + const update = () => { + if (path) { + resolve(path); + } else { + if (count < 100) { + count += 2; + report(count); + setTimeout(update, 500); + console.log("上传中"); + } else { + reject(); + } + } + }; + setTimeout(update, 500); + }); + }; + + onDisabledCombinedDate = (val) => { + let str = moment(val).format("YYYY-MM-DD HH:mm:ss"); + let isBetween = moment(str).isBetween( + this.state.codeInfo.date_time[0], + this.state.plan_time, + null, + "(]" + ); + return !isBetween; + }; + + onDisabledTime = (date, type) => { + const min = new Date(); + const hour = min.getHours(); + const minute = min.getMinutes(); + const second = min.getSeconds(); + const isSame = isSameDay(date, min); + + return isSame + ? { + disabledHours: () => initArray(hour), + disabledMinutes: (hourValue) => + hourValue === hour ? initArray(minute) : [], + disabledSeconds: (hourValue, minuteValue) => + hourValue === hour && minuteValue === minute + ? initArray(second) + : [], + } + : {}; + }; + + onDisabledRange = (date, type) => { + let step1 = JSON.parse(sessionStorage.getItem("step1")); + // let str = moment(date).format("YYYY-MM-DD HH:mm:ss") + // let isBetween = moment(str).isBetween(step1.begin_time,step1.end_time,null,'(]'); + let isdisabled = false; + let str = moment(date).format("YYYY-MM-DD HH:mm:ss"); + + if (type == "end") { + isdisabled = moment(str).isAfter(this.state.plan_time); + } + return isdisabled; + }; + + onReCall() { + let approval_id = sessionStorage.getItem("approval_id"); + this.setState({ recall_visible: false }); + terminateApprovals(approval_id).then((res) => { + handelResponse( + res, + (req, msg) => { + this.setState({ approvalLoading: true }); + let timer_c = setInterval(() => { + if (this.state.timer <= 0) { + clearInterval(timer_c); + this.setState({ approvalLoading: false }); + Notify.success("撤销成功,请重新提交审核"); + } + let time = this.state.timer - 1; + this.setState({ timer: time }); + }, 1000); + }, + (err) => { + Notify.error(err); + } + ); + }); + } + + productEditShow(rowData) { + this.setState({ drawerVisible2: true }); + this.setState({ productData: rowData }); + this.setState({ product_title: "编辑商品" }); + } + render() { + //基本信息 + const codeInfo = { + code_name: [{ type: "required", message: "请输入兑换码名称" }], + }; + + //基本规则 + const rulesInfo = { + date_time: [{ type: "required", message: "请选择生效时间段" }], + }; + + const Column2 = [ + { + title: "商品ID", + name: "product_id", + prop: "product_id", + width: "auto", + type: "normal", + }, + { + title: "商品名称", + width: "auto", + prop: "product_name", + name: "product_name", + type: "slot", + }, + { + title: "当前成本价格", + prop: "cost_price", + name: "cost_price", + width: "auto", + type: "normal", + }, + { + title: "合同价", + name: "contract_price", + prop: "contract_price", + type: "slot", + width: "auto", + }, + { + title: "商品官方价", + type: "normal", + prop: "official_price", + width: "auto", + }, + { + title: "库存总数量", + prop: "quantity", + name: "quantity", + type: "slot", + width: "auto", + }, + { + title: "剩余数量", + prop: "stock", + name: "stock", + type: "normal", + width: "auto", + }, + { + title: "已使用数量", + prop: "usage", + name: "usage", + type: "normal", + width: "auto", + }, + { + title: "操作", + prop: "edit", + name: "edit", + type: "slot", + width: "auto", + }, + // { + // title: '商品图', + // prop: 'describe_url', + // name: 'describe_url', + // type: "slot", + // width:'auto', + // }, + ]; + + return (-
+