From 552b510f4bf50acda8d6ba490a01eb955c2c260c Mon Sep 17 00:00:00 2001 From: zhangds Date: Wed, 13 Apr 2022 17:18:46 +0800 Subject: [PATCH] update --- src/pages/exchangecode/add/add.js | 8 +- src/pages/exchangecode/edit/edit.js | 2225 +++++++++++--------- src/pages/exchangecode/product/add copy.js | 619 ++++++ src/pages/exchangecode/product/add.js | 8 +- 4 files changed, 1801 insertions(+), 1059 deletions(-) create mode 100644 src/pages/exchangecode/product/add copy.js 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={"基本信息"} > -

+

-

+
-

+

-

+
diff --git a/src/pages/exchangecode/edit/edit.js b/src/pages/exchangecode/edit/edit.js index e994410d..7ee150ee 100644 --- a/src/pages/exchangecode/edit/edit.js +++ b/src/pages/exchangecode/edit/edit.js @@ -1,1082 +1,1203 @@ -import ReactDOM from 'react-dom'; -import React from "react" -import Ipt from "../../../components/input/main" -import Form from "../../../components/form/main" -import FormItem from "../../../components/form-item/main" -import {Card,Radio,Icon, Drawer, Select,Button,ImageUpload ,DateRangePicker,onUpload,Sweetalert,RadioButton,RadioGroup,Notify,Input,CombinedDateRangePicker} from "zent" -import Bus from "../../../assets/eventBus.js" -import {getIsRequireApproval,getApprovalsStatus,getReseller,getApprovalsInfo,terminateApprovals,getProductInfoSelect,handelResponse,uploadImg,getCodeProduct,putCodeProduct,getCodesDetail,putCodes,putCodesBatch} from "../../../assets/api.js" +import ReactDOM from "react-dom"; +import React from "react"; +import Ipt from "../../../components/input/main"; +import Form from "../../../components/form/main"; +import FormItem from "../../../components/form-item/main"; +import { + Card, + Radio, + Icon, + Drawer, + Select, + Button, + ImageUpload, + DateRangePicker, + onUpload, + Sweetalert, + RadioButton, + RadioGroup, + Notify, + Input, + CombinedDateRangePicker, +} from "zent"; +import Bus from "../../../assets/eventBus.js"; +import { + getIsRequireApproval, + getApprovalsStatus, + getReseller, + getApprovalsInfo, + terminateApprovals, + getProductInfoSelect, + handelResponse, + uploadImg, + getCodeProduct, + putCodeProduct, + getCodesDetail, + putCodes, + putCodesBatch, +} from "../../../assets/api.js"; import _ from "lodash"; -import Productform from "../product/add" -import "./edit.less" +import Productform from "../product/add"; +import "./edit.less"; import moment from "moment"; -import Grid from "../../../components/gird/main.js" -import { isSameDay, addDays, parse } from 'date-fns'; -const initArray = targetNum => { +import Grid from "../../../components/gird/main.js"; +import { isSameDay, addDays, parse } from "date-fns"; +const initArray = (targetNum) => { return Array.from({ length: targetNum }, (_, index) => index); }; - -export default class exchangedit extends React.Component{ - constructor(props){ - super(props) - this.state={ - uploading:false, //上传中 - model:{ //数据模型不可少 - product_id:"", - product_type:"1", - contract_price:"", - official_price:"", - cost_price:"", - quantity:"", - product_name:"", - show_url:"", - describe_url:"", - detail_url:"" - }, - codeInfo:{ //数据模型不可少 - code_name:"", - issued:'',//发放总量 - describe:'', - date_time:"", - range:"", - stock:"" - }, - isload:false, - tempdata:[], - oldProduct:[], - deleteProduct:[], //审批删除的商品 - new_product:[], - cur_product:null, - productOption:[], - rankoptions:[], - rank:[], - recall_visible:false, - approvalLoading:false, - timer:3, - paytype:3, - reseller:null, - payment_direction:["对私账户","对公账户","预付款扣除"], - isAudit:false, - approvalsStatus:false, - oldTable:[], - product_title:"新建商品", - plan_time:"" - } +export default class exchangedit extends React.Component { + constructor(props) { + super(props); + this.state = { + uploading: false, //上传中 + model: { + //数据模型不可少 + product_id: "", + product_type: "1", + contract_price: "", + official_price: "", + cost_price: "", + quantity: "", + product_name: "", + show_url: "", + describe_url: "", + detail_url: "", + }, + codeInfo: { + //数据模型不可少 + code_name: "", + issued: "", //发放总量 + describe: "", + date_time: "", + range: "", + stock: "", + }, + isload: false, + tempdata: [], + oldProduct: [], + deleteProduct: [], //审批删除的商品 + new_product: [], + cur_product: null, + productOption: [], + rankoptions: [], + rank: [], + recall_visible: false, + approvalLoading: false, + timer: 3, + paytype: 3, + reseller: null, + payment_direction: ["对私账户", "对公账户", "预付款扣除"], + isAudit: false, + approvalsStatus: false, + oldTable: [], + product_title: "新建商品", + plan_time: "", + }; } + componentDidMount(e) { + //获取商品信息 - - + 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) => { + handelResponse( + res, + (req, msg) => { + let resller_obj = { + id: req.reseller_id, + name: req.reseller_name, + company_name: req.company_name, + receive_email: req.receive_email, + }; + this.setState({ reseller: resller_obj }); + 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.update_product, + }; - componentDidMount(e){ - //获取商品信息 - - 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=>{ - handelResponse(res,(req,msg)=>{ - - let resller_obj = { - id:req.reseller_id, - name:req.reseller_name, - company_name:req.company_name, - receive_email:req.receive_email - } - this.setState({reseller:resller_obj}) - - 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.update_product - } - - - - - if(req.new_product.length > 0) - { - 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)=>{ - return o.product_id; - }) - - - 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 = [] - - 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); - - - 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 - } - - return res - }); - - - this.setState({deleteProduct:[]}) - - this.setState({tempdata:codeInfo.range}) - - 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}) - }) - }) - - 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; - }) - - 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}) - } + if (req.new_product.length > 0) { + req.new_product = _.map(req.new_product, (item) => { + item.checked = false; + return item; + }); + codeInfo.range = codeInfo.range.concat(req.new_product); + } - 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(){ + 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 (
-
- -

-

- { - this.state.isload? - { - let model = this.state.codeInfo; - model.code_name = e; - this.setState({codeInfo:model}) - }} - - onClearItem={(e)=>{ - let model = this.state.codeInfo; - model.code_name = ""; - this.setState({codeInfo:model}) - }} - - - value={this.state.codeInfo.code_name} placeholder={"请输入兑换码名称"} labelWidth={'0px'} maxLength={10} height={'36px'} width={'520px'} alignment={'left'}/> - :null - } - - -
{this.state.codeInfo.issued}
+
+ +
+ + {this.state.isload ? ( + + { + let model = this.state.codeInfo; + model.code_name = e; + this.setState({ codeInfo: model }); + }} + onClearItem={(e) => { + let model = this.state.codeInfo; + model.code_name = ""; + this.setState({ codeInfo: model }); + }} + value={this.state.codeInfo.code_name} + placeholder={"请输入兑换码名称"} + labelWidth={"0px"} + maxLength={10} + height={"36px"} + width={"520px"} + alignment={"left"} + /> + + ) : null} - - -
{this.state.codeInfo.stock}
- -
- - { - let model = this.state.codeInfo; - model.describe = e.target.value; - console.log( model.describe ) - this.setState({codeInfo:model}) - }} maxCharacterCount={100} - showCount value={this.state.codeInfo.describe} /> - - -

- -
-
- -

-

- - - - { - Bus.emit('change',"date_time" ,e); - this.onChangeCombinedDate(e)} - - } - disabledTime={this.onDisabledTime} - disabledDate={this.onDisabledRange } - /> - - - {this.onNameChange(e,rowData)}} /> - } - if(com=="quantity") - { - return {this.onQuantityChange(e,rowData)}} /> - } - if(com =="contract_price" ) - { - return {this.onPriceChange(e,rowData)}} /> - } - - if(com == "edit") - { - return { - this.productEditShow(rowData) - - }} >编辑 - } - - // if(com == "show_url") - // { - // return {this.onUploadChange1(e,rowData)}} - // onUpload={this.onUpload} - // defaultFileList={[{'src':rowData.show_url}]} - // value={rowData.show_url} - // /> - // } - - // if(com == "describe_url") - // { - // return {this.onUploadChange2(e,rowData)}} - // onUpload={this.onUpload} - // defaultFileList={ rowData.describe_url ? [{'src':rowData.describe_url}] : null} - // value={rowData.describe_url} - // /> - // } - - - }} - /> - -
-

-
-
- - - -
- } - visible={this.state.drawerVisible2} - onClose={(e) =>{this.setState({drawerVisible2:false})} } - maskClosable = {false} - > -
- - - - - -
- - - - { - - this.state.audit_visible ? ( -
-
-
- {this.setState({audit_visible:false})}} /> -
提交审核
-
- - {this.onPayTypeChange(e)}} value={this.state.paytype} className="audit-obj"> - 预付款扣除 - 对私账户 - 对公账户 - - - -
-
- - -
-
-
- ):null - } - { - - this.state.recall_visible ? ( -
-
-
- {this.setState({recall_visible:false})}} /> -
当前正在审核中
-
- - 提交审核会将原来审批撤回才可进行提交,是否撤回? - -
-
- - -
-
-
- ):null - } - { - - this.state.approvalLoading ? ( -
-
-
-
撤销审批中
-
- 正在发起撤销...,请等待 {this.state.timer} 秒 -
-
-
- ):null - } - - -
- - -
+ +
{this.state.codeInfo.issued}
+
+ +
{this.state.codeInfo.stock}
+
+ + { + let model = this.state.codeInfo; + model.describe = e.target.value; + console.log(model.describe); + this.setState({ codeInfo: model }); + }} + maxCharacterCount={100} + showCount + /> + + +
+ +
+
+ +
+
+ + { + Bus.emit("change", "date_time", e); + this.onChangeCombinedDate(e); + }} + disabledTime={this.onDisabledTime} + disabledDate={this.onDisabledRange} + /> + + + { + this.onNameChange(e, rowData); + }} + /> + ); + } + if (com == "quantity") { + return ( + { + this.onQuantityChange(e, rowData); + }} + /> + ); + } + if (com == "contract_price") { + return ( + { + this.onPriceChange(e, rowData); + }} + /> + ); + } + + if (com == "edit") { + return ( + { + this.productEditShow(rowData); + }} + > + 编辑 + + ); + } + + // if(com == "show_url") + // { + // return {this.onUploadChange1(e,rowData)}} + // onUpload={this.onUpload} + // defaultFileList={[{'src':rowData.show_url}]} + // value={rowData.show_url} + // /> + // } + + // if(com == "describe_url") + // { + // return {this.onUploadChange2(e,rowData)}} + // onUpload={this.onUpload} + // defaultFileList={ rowData.describe_url ? [{'src':rowData.describe_url}] : null} + // value={rowData.describe_url} + // /> + // } + }} + /> + +
+
+
+
+ + + + + } + visible={this.state.drawerVisible2} + onClose={(e) => { + this.setState({ drawerVisible2: false }); + }} + maskClosable={false} + > +
+ + + +
+
+ + {this.state.audit_visible ? ( +
+
+
+ { + this.setState({ audit_visible: false }); + }} + /> +
提交审核
+
+ { + this.onPayTypeChange(e); + }} + value={this.state.paytype} + className="audit-obj" + > + 预付款扣除 + 对私账户 + 对公账户 + +
+
+ + +
+
+
+ ) : null} + {this.state.recall_visible ? ( +
+
+
+ { + this.setState({ recall_visible: false }); + }} + /> +
当前正在审核中
+
+ 提交审核会将原来审批撤回才可进行提交,是否撤回? +
+
+ + +
+
+
+ ) : null} + {this.state.approvalLoading ? ( +
+
+
+
撤销审批中
+
+ 正在发起撤销...,请等待{" "} + {this.state.timer} 秒 +
+
+
+ ) : null} + +
+ + +
- ) + ); } } - diff --git a/src/pages/exchangecode/product/add copy.js b/src/pages/exchangecode/product/add copy.js new file mode 100644 index 00000000..62c0e8c5 --- /dev/null +++ b/src/pages/exchangecode/product/add copy.js @@ -0,0 +1,619 @@ +import ReactDOM from "react-dom"; +import React from "react"; +import "./add.less"; +import Ipt from "../../../components/input/main"; +import Form from "../../../components/form/main"; +import FormItem from "../../../components/form-item/main"; +import { + Select, + Button, + ImageUpload, + onUpload, + Sweetalert, + RadioButton, + RadioGroup, + Notify, +} from "zent"; +import Swiper from "swiper/dist/js/swiper.js"; +import "swiper/dist/css/swiper.min.css"; +import Bus from "../../../assets/eventBus.js"; +import { + getProductInfoSelect, + handelResponse, + uploadImg, +} from "../../../assets/api.js"; +import _ from "lodash"; + +var mySwiper = null; +var timer = null; +export default class adduserinfo extends React.Component { + constructor(props) { + super(props); + this.state = { + model: { + //数据模型不可少 + product_id: "", + product_type: "1", + contract_price: "", + official_price: "", + cost_price: "", + quantity: "", + product_name: "", + show_url: "", + describe_url: [], + detail_url: "", + stock: "", + usage: "", + detail_url: "", + map_product_name: "", + }, + cur_product: null, + productOption: [], + products: [], + productpic: [], + }; + } + componentDidMount() { + mySwiper = new Swiper(".swiper-container", { + slidesPerView: 1, + centeredSlides: true, + loop: true, + autoplay: 3000, + initialSlide: 0, + observer: true, // 修改swiper自己或子元素时,自动初始化swiper + observeParents: true, // 修改swiper的父元素时,自动初始化swiper + pagination: ".swiper-pagination", + }); + } + componentWillReceiveProps() { + mySwiper.update(); + } + componentWillMount(e) { + //获取商品信息 + if (this.props.data) { + let model_temp = this.props.data; + + let model = this.state.model; + model.product_id = model_temp.product_id; + model.product_type = model_temp.product_type; + + model.contract_price = model_temp.contract_price; + model.official_price = model_temp.official_price; + model.cost_price = model_temp.cost_price; + model.quantity = model_temp.quantity; + model.product_name = model_temp.product_name; + model.show_url = model_temp.show_url; + model.account_type = model_temp.account_type; + model.detail_url = model_temp.detail_url; + let defaultPic = []; + let arr = []; + + let temp_productpic = this.state.productpic; + let pics = ""; + if (Array.isArray(model_temp.describe_url)) { + pics = model_temp.describe_url; + } else { + if ( + model_temp.describe_url != "" && + model_temp.describe_url != undefined + ) { + pics = model_temp.describe_url.split(","); + } else { + pics = []; + } + } + + for (let i = 0; i < pics.length; i++) { + let obj = {}; + let nameArr = pics[i].split("/"); + obj.name = nameArr[5]; + obj.src = pics[i]; + defaultPic.push(obj); + let obj2 = { + name: nameArr[5], + url: pics[i], + }; + temp_productpic.push(obj2); + } + this.setState({ temp_productpic }); + model.describe_url = defaultPic; + model.stock = model_temp.stock; + model.usage = model_temp.usage; + model.map_product_name = model_temp.map_product_name; + this.setState({ model: model }); + } + this.getProductInfo(); + } + + //获取直连天下商品映射信息 + getProductInfo() { + let productList = sessionStorage.getItem("productsList"); + + productList = JSON.parse(productList); + let product_data = []; + if (sessionStorage.getItem("productData")) { + product_data = JSON.parse(sessionStorage.getItem("productData")); + } + let checked_product = product_data ? product_data : []; + + let arr = []; + this.setState({ products: productList }); + + _.map(productList, (res) => { + let obj = {}; + obj.key = res.id; + obj.text = res.title; + obj.disabled = + checked_product.findIndex((item) => { + return item.product_id == res.id; + }) > -1; + if (obj.disabled) { + } + + arr.push(obj); + return obj; + }); + console.log("arr ==>", arr); + + this.setState({ productOption: arr }); + + if (this.state.model.product_id) { + let cur_product = arr.find((item) => { + return item.key == this.state.model.product_id; + }); + this.setState({ cur_product: cur_product }); + } + } + + async submit() { + if (this.refs.form1.validator()) { + if (this.props.data) { + let temp = []; + if (sessionStorage.getItem("productData")) { + temp = JSON.parse(sessionStorage.getItem("productData")); + + let index = temp.findIndex((item) => { + return item.product_id == this.props.data.product_id; + }); + + temp[index].product_name = this.state.model.product_name; + temp[index].account_type = this.state.model.account_type; + temp[index].product_id = this.state.model.product_id; + temp[index].product_type = this.state.model.product_type; + temp[index].contract_price = this.state.model.contract_price; + temp[index].official_price = this.state.model.official_price; + temp[index].cost_price = this.state.model.cost_price; + temp[index].quantity = this.state.model.quantity; + temp[index].stock = this.state.model.quantity; + temp[index].usage = this.state.model.usage; + temp[index].show_url = this.state.model.show_url; + temp[index].detail_url = this.state.model.detail_url; + let urls = _.map(this.state.productpic, (o) => { + return o.url; + }); + if (urls.length <= 0) { + Notify.error(`商品图至少请上传一张`); + return; + } + + temp[index].describe_url = urls; + temp[index].map_product_name = this.state.model.map_product_name; + temp[index].account_type = this.state.model.account_type; + + sessionStorage.setItem("productData", JSON.stringify(temp)); + } + } else { + let model = this.state.model; + + let urls = _.map(this.state.productpic, (o) => { + return o.url; + }); + + if (urls.length <= 0) { + Notify.error(`商品图至少请上传一张`); + return; + } + + model.describe_url = urls; + + this.setState({ model: model }); + + if (this.state.model.show_url == "") { + Notify.error(`请上传商品Logo`); + return; + } + let temp = []; + if (sessionStorage.getItem("productData")) { + temp = JSON.parse(sessionStorage.getItem("productData")); + } + let data = temp ? temp : []; + data.push(this.state.model); + sessionStorage.setItem("productData", JSON.stringify(data)); + } + return true; + } + } + onProductChange(e) { + this.setState({ cur_product: e }); + let cur_product = this.state.products.find((item) => { + return item.id == e.key; + }); + let picItem = window.goods.find((item) => { + return item.id == cur_product.product_category_id; + }); + let quantity = this.state.model.quantity; + let model2 = { + product_id: cur_product.id, + product_type: cur_product.type, + contract_price: this.state.model.contract_price, + official_price: cur_product.official_price, + cost_price: cur_product.cost_price, + quantity: quantity, + stock: quantity, + usage: 0, + product_name: cur_product.title, + show_url: picItem ? picItem.pic : "", + describe_url: "", + detail_url: "", + map_product_name: cur_product.title, + account_type: cur_product.account_type, + }; + this.setState({ model: model2 }); + } + onTypeChange(e) { + let model2 = this.state.model; + model2.type = e.target.value; + this.setState({ model: model2 }); + } + + onUpload = (file, report) => { + return new Promise((resolve, reject) => {}); + }; + onUploadChange(files) { + if (files.length > 0) { + let formdata = new FormData(); + formdata.append("file", files[0].file); + formdata.append("path", "common_image"); + uploadImg(formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + let path = req.path; + let model = this.state.model; + model.show_url = path; + + this.setState({ model: model }); + }, + (err) => {} + ); + }); + } else { + let model = this.state.model; + model.show_url = ""; + this.setState({ model: model }); + } + } + onUploadChange1(files, e) { + let arr = _.map(files, (o) => { + return o.name; + }); + if (mySwiper !== 0) { + mySwiper.destroy(); + } + mySwiper = new Swiper(".swiper-container", { + observer: true, //修改swiper自己或子元素时,自动初始化swiper + observeParents: true, //修改swiper的父元素时,自动初始化swiper + pagination: ".swiper-pagination", + paginationClickable: true, + autoplay: 3000, + }); + clearTimeout(timer); + timer = setTimeout(() => { + if (arr.length > this.state.productpic.length) { + //新增 + for (let i = 0; i < arr.length; i++) { + let index = this.state.productpic.findIndex((o) => { + return o.name == arr[i]; + }); + if (index < 0) { + let path = ""; + let formdata = new FormData(); + formdata.append("file", files[i].file); + formdata.append("path", "common_image"); + + uploadImg(formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + path = req.path; + let obj = { + name: files[i].name, + url: path, + }; + let arr = this.state.productpic; + arr.push(obj); + this.setState({ arr }); + }, + (err) => {} + ); + }); + } + } + } + if (arr.length < this.state.productpic.length) { + let temp_arr = Object.assign([], this.state.productpic); + this.setState({ productpic: [] }); + this.state.productpic = []; + let temp_arr2 = this.state.productpic; + for (let i = 0; i < temp_arr.length; i++) { + let temp = temp_arr[i]; + if (arr.indexOf(temp.name) > -1) { + temp_arr2.push(temp); + } + } + this.setState({ temp_arr2 }); + } + + // //调整位置 + if (arr.length == this.state.productpic.length) { + let temp_arr = []; + let pic_arr = this.state.productpic; + for (let i = 0; i < arr.length; i++) { + let temp = pic_arr.find((o) => { + return o.name == arr[i]; + }); + temp_arr[i] = temp; + } + this.setState({ productpic: temp_arr }); + } + }, 500); + } + onUploadError = (type, data) => { + if (type === "overMaxAmount") { + Notify.error(`最多可上传 ${data.maxAmount} 张图片`); + } else if (type === "overMaxSize") { + Notify.error(`图片大小不能超过 ${data.formattedMaxSize}`); + } + }; + onUploadChange2(files) { + if (files.length > 0) { + let formdata = new FormData(); + formdata.append("file", files[0].file); + formdata.append("path", "common_image"); + uploadImg(formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + let path = req.path; + let model = this.state.model; + model.detail_url = path; + + this.setState({ model: model }); + }, + (err) => {} + ); + }); + } else { + let model = this.state.model; + model.detail_url = ""; + this.setState({ model: model }); + } + } + + render() { + //校验规则 + const rules = { + product: [{ type: "required", message: "请选择映射商品" }], + quantity: [ + { type: "required", message: "请输入商品库存" }, + { + type: "regExp", + message: "请输入小于100万的整数", + reg: "^(?!0)(?:[0-9]{1,6}|1000000)$", + }, + ], + contract_price: [ + { type: "required", message: "请输入合同价" }, + { + type: "regExp", + message: "最多保留4位小数", + reg: "^[0-9]+(.[0-9]{1,4})?$", + }, + ], + product_name: [{ type: "required", message: "请输入商品名称" }], + }; + return ( +
+
+ +