diff --git a/src/pages/exchangecode/add copy/add.js b/src/pages/exchangecode/add copy/add.js new file mode 100644 index 00000000..badedf4e --- /dev/null +++ b/src/pages/exchangecode/add copy/add.js @@ -0,0 +1,2068 @@ +import { deWeightThree } from '../../../utils' +import React from 'react' +import { + Card, + Sweetalert, + DateRangePicker, + Drawer, + Button, + Radio, + Tabs, + Notify, + Select, + Input, + Checkbox, + Switch, + Icon, + RadioGroup, + RadioButton +} from 'zent' +import Ipt from '../../../components/input/main' +import Form from '../../../components/form/main' +import FormItem from '../../../components/form-item/main' +import Grid from '../../../components/gird/main.js' +import { + addPlanStep, + handelResponse, + addKeysBatchInfo, + getKeyBatchDetail, + putKeyBatchDetail, + uploadImg, + getReseller, + getAccessVerification, + keyApproval, + getProductInfoSelect +} from '../../../assets/api.js' +import Productform from '../product/add' +import KnockGold from '@/components/knockGold' /* 立减金 */ + +import Bus from '../../../assets/eventBus.js' +import _ from 'lodash' +import './add.less' +import moment from 'moment' +import { isSameDay } from 'date-fns' +const TabPanel = Tabs.TabPanel + +const initArray = (targetNum) => { + return Array.from({ length: targetNum }, (_, index) => index) +} + +export default class acclist extends React.Component { + constructor(props) { + super(props) + this.state = { + keys: [ + { + style: 1, + quantity: '', + allow_repetition: 0, + allow_loss: 0, + merge_stock: 1, + code_batch: '', + draw_title: '' + } + ], + model: { + //数据模型不可少 + style: 1, + quantity: '', + plan_id: '', + title: '', + allow_repetition: 0, + allow_loss: 0, + merge_stock: 1, + code_batch: '', + draw_title: '', + batch_name: '' + }, + drawerVisible: false, + drawerVisible2: false, + checkedList: [1], + productData: [], + codeInfo: { + //数据模型不可少 + code_name: '', + issued: '', //发放总量 + describe: '', + date_time: '', + range: '' + }, + rank: null, + rankoptions: [], + tempdata: [], + distdata: [], + pagetitle: '新建key', + isEdit: false, + begintime: '', + endtime: '', + rowIndex: -1, + uploading: false, + audit_visible: false, + phone_list: [], + email_list: [], + email_radio: -1, + phone_radio: -1, + paytype: 3, + reseller: null, + payment_direction: ['对私账户', '对公账户', '预付款扣除'], + + import_visible: false, + white_visible: false, + success_visible: false, + fail_visible: false, + file_loading: false, + upload_visible: false, + excel_visible: false, + accessVerify: false, + mobile_excel: '', + mobile_repeat: [], + execel_path: '', + excel_count: 0, + success_count: 0, + error_count: 0, + direct_reseller_id: 0, + newGoodsBtnLoading: false, + newGoldLoading: false, + product_title: '新建商品', + addIsType: '' + } + } + + componentDidMount(e) { + let batch_id = sessionStorage.getItem('keybatch_id') + let copyOpearo = sessionStorage.getItem('copyOpearo') + //key样式 + let keystyle = sessionStorage.getItem('keyStyle') + + if (keystyle == 1) { + let model = this.state.model + model.style = 6 + this.setState({ model: model }) + this.setState({ white_visible: true }) + } + //复制 + if (batch_id > 0 || copyOpearo == 2) { + // this.setState({isEdit:true}) + getKeyBatchDetail(batch_id).then((res) => { + handelResponse( + res, + (req, msg) => { + this.setState({ pagetitle: '复制key' }) + getReseller(req.reseller_id).then((res) => { + handelResponse(res, (req, msg) => { + this.setState({ + phone_list: req.contact_phone, + direct_reseller_id: req.direct_reseller_id, + email_list: req.contact_email, + reseller: req + }) + getProductInfoSelect({ + reseller_id: req.direct_reseller_id + }).then((res) => { + if (res.code === 200) { + sessionStorage.setItem( + 'productsList', + JSON.stringify(res.data.data) + ) + } + }) + }) + }) + let model = { + title: req.plan_title, + style: req.style, + quantity: req.quantity, + allow_repetition: req.allow_repetition, + allow_loss: req.allow_loss, + merge_stock: req.merge_stock, + code_batch: req.code_batch, + batch_name: `${req.batch_name}_${++req.copy_count}`, + copy_code_batch_id: req.id + } + let codeInfo = { + //数据模型不可少 + date_time: [req.begin_time, req.end_time] + } + sessionStorage.setItem( + 'plan_item', + JSON.stringify({ + begin_time: req.begin_time, + end_time: req.end_time + }) + ) + this.setState({ + checkedList: req.bind_object, + model: model, + endtime: req.end_time, + begintime: req.begin_time, + codeInfo: codeInfo + }) + + let list = _.map(req.code_batch, (item) => { + item.product = item.product.map((item1) => { + let obj = {} + if (item1.type === 1) { + obj = item1.entity + obj.upstream = '直连天下' + obj.only = item1.entity.product_id + obj.id = item1.entity.product_id + obj.weight = item1.weight + obj.type = item1.type + } else if (item1.type === 2) { + obj.type = item1.type + obj.product_id = item1.entity.goods_id + obj.product_type_text = '立减金' + obj.only = item1.entity.channel_activity_id + obj.id = item1.entity.goods_id + obj.upstream = + String(item1.entity.channel) === '1' ? '支付宝' : '微信' + obj.code_batch_id = item1.code_batch_id + obj.contract_price = item1.entity.price + obj.create_time = item1.create_time + obj.official_price = item1.entity.reduce_amount + obj.channel_activity_id = item1.entity.channel_activity_id + obj.product_name = item1.entity.batch_goods_name + obj.quantity = item1.entity.stock + item1.entity.weight = item1.weight + obj.stock = Math.trunc( + item1.entity.all_budget / item1.entity.reduce_amount - + item1.entity.used_amount / item1.entity.reduce_amount + ) + obj.usage = Math.trunc( + item1.entity.all_budget / item1.entity.reduce_amount - + (item1.entity.all_budget - item1.entity.used_amount) / + item1.entity.reduce_amount + ) + obj.effectDate = + item1.entity.time_limit.effect_time.start_time + + ' 至 ' + + item1.entity.time_limit.effect_time.end_time + //有效时间 + delete item1.entity.id + obj.origin = item1.entity + } + + return obj + }) + let pr = {} + pr.range = item.range + pr.restrict = item.restrict + pr.title = item.title + pr.begin_time = item.begin_time + pr.end_time = item.end_time + pr.quantity = item.quantity + pr.describe = item.describe + pr.product = item.product + item = pr + return item + }) + this.setState({ distdata: list }) + }, + (err) => {} + ) + }) + /* 新增 */ + } else { + let plan_item = sessionStorage.getItem('plan_item') + if (plan_item) { + plan_item = JSON.parse(plan_item) + let model = this.state.model + model.title = plan_item.title + + this.setState({ model: model }) + this.setState({ endtime: plan_item.end_time }) + this.setState({ begintime: plan_item.begin_time }) + + let id = plan_item.reseller_id + + getReseller(id).then((res) => { + handelResponse(res, (req, msg) => { + this.setState({ reseller: req }) + this.setState({ phone_list: req.contact_phone }) + this.setState({ email_list: req.contact_email }) + this.setState({ + direct_reseller_id: req.direct_reseller_id + }) + }) + }) + + let codeInfo = { + //数据模型不可少 + code_name: '', + issued: '', //发放总量 + describe: '', + date_time: [plan_item.begin_time, plan_item.end_time], + range: '' + } + + this.setState({ codeInfo: codeInfo }) + } + } + } + + onPayTypeChange(e) { + this.setState({ paytype: e.target.value }) + } + + async submit() { + let valide = false + if (this.refs.form1.validator()) { + let data = {} + data.batch_name = this.state.model.batch_name + data.style = this.state.model.style + data.quantity = this.state.model.quantity + data.bind_object = this.state.model.bind_object + data.allow_repetition = this.state.model.allow_repetition + data.allow_loss = this.state.model.allow_loss + data.merge_stock = this.state.model.merge_stock + data.code_batch = this.state.distdata + let formdata = {} + formdata.step = 'key' + formdata.data = data + await addPlanStep('', formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + sessionStorage.setItem('plan_id', req.id) + valide = true + return + }, + (err) => { + Notify.error(err) + } + ) + }) + } + return valide + } + + importClick() { + if (this.state.file_loading) { + Notify.error('文件正在解析中请稍等') + } else { + if (this.state.success_visible) { + this.setState({ accessVerify: false }) + this.setState({ excel_visible: true }) + this.setState({ import_visible: false }) + } else { + Notify.error('请上传正确的文件') + } + } + } + Cancel() { + Sweetalert.confirm({ + type: 'warning', + closeBtn: true, + title: '确认操作', + content:
是否取消本次操作?
, + onConfirm: () => { + window.history.back() + }, + onCancel: this.onCancel, + className: 'questModal', + parentComponent: this + }) + } + onCheckChange = (arr) => { + this.setState({ checkedList: arr }) + let checkedList = arr + } + + onStyleChange(e) { + let model2 = this.state.model + model2.style = e.target.value + model2.quantity = 0 + this.setState({ model: model2 }) + if (e.target.value == 6) { + this.setState({ white_visible: true }) + } else { + this.setState({ white_visible: false }) + } + } + + onRepetitionChange(e) { + let model2 = this.state.model + model2.allow_repetition = e.target.value + this.setState({ model: model2 }) + } + + onLossChange(e) { + let model2 = this.state.model + model2.allow_loss = e.target.value + this.setState({ model: model2 }) + } + checkIndex(e) { + switch (e) { + case 0: + this.setState({ draw_title: '新建兑换码' }) + break + case 1: + this.setState({ draw_title: '新建优惠券' }) + break + case 2: + this.setState({ draw_title: '新建立减金' }) + break + default: + return + } + this.setState({ drawerVisible: false }) + this.state.codeInfo = { + //数据模型不可少 + code_name: '', + issued: '', //发放总量 + describe: '', + date_time: [this.state.begintime, this.state.endtime], + range: '' + } + this.setState({ tempdata: [] }) + this.setState({ rank: null }) + this.setState({ rankoptions: [] }) + this.setState({ drawerVisible: true }) + sessionStorage.setItem('productData', '') + sessionStorage.setItem('knockGoldData', '') + } + closeDraw() { + this.setState({ drawerVisible: false }) + } + addProduct(type) { + this.setState({ addIsType: type }) /* 类型 */ + let direct_reseller_ids = this.state.direct_reseller_id + if (direct_reseller_ids <= 0) { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + + if (type === 'addProduct') { + this.setState({ product_title: '新建商品', newGoodsBtnLoading: true }) + } else { + this.setState({ product_title: '新增立减金', newGoldLoading: true }) + } + let param = { + reseller_id: direct_reseller_ids + } + try { + getProductInfoSelect(param).then((res) => { + if (res.code === 200) { + sessionStorage.setItem('productsList', JSON.stringify(res.data.data)) + this.setState({ productData: null }) + this.setState({ drawerVisible2: true }) + } + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + }) + } catch (err) { + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + } + } + //渲染范围列表数据以及数据转换 + async productSubmit() { + let visible = '' + if (this.state.addIsType === 'addProduct') { + visible = await this.refs.product.submit() + } else { + visible = await this.refs.knockGold.submit() + } + + if (visible) { + Notify.success('保存成功') + this.setState({ drawerVisible2: false }) + setTimeout(() => { + let data = null + let temp = null + let concatData = [] + /* 处理商品 */ + if (this.state.addIsType === 'addProduct') { + data = JSON.parse(sessionStorage.getItem('productData')).filter( + (item) => item.type !== 2 + ) + + concatData = this.state.tempdata.filter((item) => item.type !== 1) + + 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 + } + item.type = 1 + item.only = item.product_id + item.upstream = '直连天下' + return item + }) + } else { + /* 处理立减金 */ + data = JSON.parse(sessionStorage.getItem('knockGoldData')).filter( + (item) => item.type !== 1 + ) + + concatData = this.state.tempdata.filter((item) => item.type !== 2) + + temp = _.map(data, (item) => { + let index = this.state.tempdata.findIndex((o) => { + return o.channel_activity_id === item.channel_activity_id + }) + + if (index > -1) { + item.checked = this.state.tempdata[index].checked + } + + /* 转换商品结构 */ + // temp + const newObj = {} + newObj.product_name = item.batch_goods_name + ? item.batch_goods_name + : item.product_name //名字 + newObj.map_product_name = item.product_name + newObj.channel_activity_id = item.channel_activity_id //批次号 + newObj.only = item.channel_activity_id //批次号 + newObj.type = 2 //类型 + newObj.checked = item?.checked + newObj.upstream = String(item.channel) === '1' ? '支付宝' : '微信' //上游 + newObj.edit = 'edit' + newObj.effectDate = item.effectDate + ? item.effectDate + : item.time_limit?.effect_time.start_time + + ' 至 ' + + item.time_limit?.effect_time.end_time //有效时间 + newObj.contract_price = item.contract_price + ? item.contract_price + : item.price //单价 + newObj.official_price = item.official_price + ? item.official_price + : item.reduce_amount //官方价 + newObj.quantity = item.quantity + ? item.quantity + : Math.trunc(item.all_budget / item.reduce_amount) //总库 + newObj.origin = item?.origin ? item?.origin : item + return newObj + }) + } + let newArray = deWeightThree(temp.concat(concatData), 'only') + + //select数据 + let arr = [] + let rank = [] + _.map(newArray, (res) => { + arr.push({ key: res.only, text: res.product_name }) + if (res.checked) { + rank.push({ key: res.only, text: res.product_name }) + } + }) + + arr = deWeightThree(arr, 'key') + this.setState({ tempdata: newArray, rankoptions: arr, rank }) + }, 500) + } + } + onChangeCombinedDate(e) { + let model2 = this.state.codeInfo + model2.date_time = e + this.setState({ codeInfo: model2 }) + } + submit2() { + this.refs.form2.validator() + } + //select + onRankChange(e) { + _.forEach(this.state.tempdata, (item) => { + item.checked = + e.findIndex((checks) => { + return checks.key == item.only + }) > -1 + }) + this.setState({ tempdata: this.state.tempdata }) + this.setState({ rank: e }) + } + codeSubmit() { + if (this.refs.code_info.validator() && this.refs.code_rule.validator()) { + if (this.state.uploading) { + Notify.error('还有图片上传中,不可提交') + return + } + + let productlist = _.filter(this.state.tempdata, (item) => { + return item.checked == true + }) + let sum = 0 + _.forEach(productlist, (o) => { + sum += parseInt(o.quantity) + }) + if (sum < this.state.codeInfo.issued) { + Notify.error('所选商品库存总数小于发放量') + return + } + // let productList = JSON.parse(sessionStorage.getItem("productsList")); + + this.setState({ drawerVisible: false }) + let rank = _.map(this.state.rank, (item) => { + return item.text + }) + + let temp = { + title: this.state.codeInfo.code_name, + 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, + range: rank.toString(), + restrict: this.state.codeInfo.restrict + } + + let arr = _.map(productlist, (item) => { + let obj = {} + obj.product_id = item.product_id + obj.product_type = item.product_type + obj.product_name = item.product_name + obj.account_type = item.account_type + obj.contract_price = item.contract_price + obj.cost_price = item.cost_price + obj.official_price = item.official_price + obj.quantity = item.quantity + obj.show_url = item.show_url + obj.describe_url = item.describe_url + obj.detail_url = item.detail_url + obj.map_product_name = item.map_product_name + if (item.type === 2) { + obj.channel_activity_id = item.channel_activity_id //批次号 + obj.effectDate = item.effectDate //有效时间 + obj.origin = item.origin // 原始数据 + } + obj.only = item.only + obj.weight = item.weight + obj.type = item.type + obj.upstream = item.upstream + return obj + }) + temp.product = arr + + if (this.state.rowIndex > -1) { + this.state.distdata[this.state.rowIndex] = temp + this.setState({ distdata: this.state.distdata }) + } else { + let tempdata = this.state.distdata + tempdata.push(temp) + this.setState({ distdata: tempdata }) + } + } + } + onAddKey() { + let obj = { + style: '1', + quantity: '', + allow_repetition: 0, + allow_loss: 0, + merge_stock: '1', + code_batch: '', + draw_title: '', + batch_name: '' + } + let keys = this.state.keys + keys.push(obj) + + this.setState({ keys: keys }) + } + onAudit() { + if (!this.state.reseller) { + Notify.error('对应分销商数据不存在') + return + } + + if (this.state.isEdit) { + let selection = this.refs.bindObj.getSelectData() + let formdata = selection.filter((item) => { + return !item.hasOwnProperty('disabled') + }) + + let id = sessionStorage.getItem('keybatch_id') + let data = { + code_batch: formdata + } + putKeyBatchDetail(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + setTimeout(() => { + window.history.back() + }, 1000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } else { + if (this.refs.form1.validator()) { + /* 处理数据 区分立减金和商品 开始 2022-05-30 13:40*/ + const dataCopy = this.refs.bindObj.getSelectData() + + dataCopy.map((item) => { + item.products = item.product + }) + + dataCopy.map((item) => + item.products.map(() => { + item.product = { + legal: item.products.filter((item2) => item2.type === 1), + reduce: item.products + .map((item2) => { + if (item2.type === 2) return item2.origin + }) + .filter((item3) => item3) + } + }) + ) + + dataCopy.map((item) => { + delete item.products + }) + /* 处理数据 区分立减金和商品 完成 2022-05-30 13:40*/ + + let data = {} + data.batch_name = this.state.model.batch_name + data.copy_code_batch_id = this.state.model?.copy_code_batch_id + data.style = this.state.model.style + data.quantity = this.state.model.quantity + data.bind_object = this.state.checkedList + data.allow_repetition = this.state.model.allow_repetition + data.allow_loss = this.state.model.allow_loss + data.merge_stock = this.state.model.merge_stock + data.code_batch = dataCopy + + data.reseller_id = this.state.reseller.id + data.reseller_name = this.state.reseller.name + data.company_name = this.state.reseller.company_name + data.receive_email = this.state.reseller.contact_email[0] + data.payment_direction = + this.state.payment_direction[this.state.paytype - 1] + + data.mobile_excel = this.state.mobile_excel + data.mobile_repeat = this.state.mobile_repeat + + if (data.code_batch.length == 0) { + Notify.error('请绑定对象') + return + } + this.setState({ audit_visible: false }) + + let id = sessionStorage.getItem('key_plan_id') + addKeysBatchInfo(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + keyApproval(id, req.key_batch_id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + // this.props.history.push('/home/key-list/') + window.history.back() + }, 2000) + }, + (err) => { + Notify.error(err) + } + ) + }) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + } + } + + onBindNum(e, row, rowIndex) { + this.state.distdata[rowIndex].restrict = e.target.value + this.setState({ distdata: this.state.distdata }) + } + + onDisabledRange = (date, type) => { + let step1 = JSON.parse(sessionStorage.getItem('plan_item')) + let isdisabled = false + let str = moment(date).format('YYYY-MM-DD HH:mm:ss') + if (type == 'start') { + isdisabled = + moment(str).isBefore(step1.begin_time) || + moment(str).isAfter(step1.end_time) + } + + if (type == 'end') { + isdisabled = + moment(str).add(1, 'days').isBefore(step1.begin_time) || + moment(str).isAfter(step1.end_time) + } + return isdisabled + } + + rowItemClick(row, rowIndex) { + let codeInfo = { + //数据模型不可少 + code_name: row.title, + issued: row.quantity, //发放总量 + describe: row.describe, + date_time: [row.begin_time, row.end_time], + range: row.range, + restrict: row.restrict + } + + let arr = _.map(row.product, (res) => { + let obj = {} + obj.key = res.only + obj.text = res.product_name + return obj + }) + this.setState({ + draw_title: '编辑兑换码', + rankoptions: arr, + rank: arr, + codeInfo: codeInfo, + rowIndex: rowIndex + }) + + let temp = _.map(row.product, (o) => { + o.checked = true + return o + }) + + sessionStorage.setItem('productData', JSON.stringify(row.product)) + sessionStorage.setItem('knockGoldData', JSON.stringify(row.product)) + this.setState({ drawerVisible: true, tempdata: temp }) + } + + 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) + } else { + reject() + } + } + } + setTimeout(update, 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].describe_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, rowIndex) { + this.state.tempdata[rowIndex].product_name = e.target.value + this.setState({ tempdata: this.state.tempdata }) + } + onQuantityChange(e, row, rowIndex) { + this.state.tempdata[rowIndex].quantity = + e.target.value == '' ? 0 : e.target.value + this.setState({ tempdata: this.state.tempdata }) + } + onPriceChange(e, row, rowIndex) { + let str = e.target.value + let value = str + .replace(/[^\d^\.]+/g, '') + .replace('.', '$#$') + .replace(/\./g, '') + .replace('$#$', '.') + + this.state.tempdata[rowIndex].contract_price = value + this.setState({ tempdata: this.state.tempdata }) + } + 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) + : [] + } + : {} + } + + onReturn() { + let self = this + Sweetalert.confirm({ + type: 'warning', + closeBtn: true, + title: '确认操作', + content:是否返回key列表?
, + onConfirm: () => { + self.props.history.push('/home/key-list/') + }, + onCancel: this.onCancel, + className: 'questModal', + parentComponent: this + }) + } + onPhoneChange(e) { + this.setState({ phone_radio: e.target.value }) + } + onEmailChange(e) { + this.setState({ email_radio: e.target.value }) + } + cancel(e) { + this.setState({ audit_visible: false }) + } + phoneChange = (e) => { + this.setState({ phone: e.target.value }) + } + emailChange = (e) => { + this.setState({ email: e.target.value }) + } + initUpload() { + this.setState({ import_visible: false }) + this.setState({ success_visible: false }) + this.setState({ fail_visible: false }) + this.setState({ file_loading: false }) + this.setState({ upload_visible: false }) + this.setState({ excel_visible: false }) + this.setState({ accessVerify: false }) + } + + fileChange(e) { + // this.initUpload(); + + let my_file = e.target.files[0] + this.setState({ myfile: my_file }) + this.setState({ upload_visible: true }) + + if ( + my_file.name.indexOf('.xls') || + my_file.name.indexOf('.xlsx') || + my_file.name.indexOf('.csv') + ) { + if (my_file.size > 1024000) { + Notify.error('文件大小不能大于2M') + return + } + let formdata = new FormData() + formdata.append('file', my_file) + formdata.append('path', 'white_list_excel') + this.setState({ file_loading: true }) + uploadImg(formdata).then((res) => { + handelResponse( + res, + (req, msg) => { + let data = { + excel: req.path + } + + this.setState({ mobile_excel: req.path }) + getAccessVerification(data).then((res) => { + this.setState({ file_loading: false }) + handelResponse( + res, + (req, msg) => { + this.setState({ accessVerify: true }) + this.setState({ excel_count: req.count }) + this.setState({ error_count: req.errorCount }) + let success = req.count - req.errorCount + this.setState({ success_count: success }) + this.setState({ exceldata: req.validationFailed }) + + this.setState({ success_visible: true }) + }, + (err) => { + Notify.error(err) + this.setState({ success_visible: false }) + } + ) + }) + }, + (err) => { + Notify.error(err) + this.setState({ success_visible: false }) + } + ) + }) + } else { + this.setState({ success_visible: false }) + } + } + + resetUpload() { + this.setState({ excel_visible: false }) + this.setState({ import_visible: true }) + this.setState({ accessVerify: true }) + } + allowImport(data) { + let arr = this.state.mobile_repeat + if (arr.indexOf(data.mobile) < 0) { + arr.push(data.mobile) + } + data.type = 'success' + this.setState({ mobile_repeat: arr }) + } + importConfirmClick() { + let temp = this.state.exceldata.filter((o) => o.type == 'success') + let mobile_repeat = _.map(temp, (o) => { + return o.mobile + }) + this.setState({ mobile_repeat: mobile_repeat }) + + let model = this.state.model + model.quantity = + this.state.excel_count - this.state.error_count + mobile_repeat.length + this.setState({ model: model }) + this.setState({ accessVerify: false }) + this.setState({ excel_visible: false }) + this.setState({ import_visible: false }) + this.setState({ import_success: true }) + } + resetUpload() { + this.setState({ excel_visible: false }) + this.setState({ import_visible: true }) + this.setState({ accessVerify: true }) + } + switchChange(e, rowData) { + if (e) { + rowData.type = 'success' + } else { + rowData.type = rowData.type == 'success' ? 'repeat' : 'error' + } + } + downLoadTemplate() { + window.location.href = + 'https://lsxdemall.oss-cn-beijing.aliyuncs.com/MarketingSystem/%E7%99%BD%E5%90%8D%E5%8D%95%E6%A8%A1%E6%9D%BF.xlsx' + } + submitAudit() { + if (this.refs.form1.validator()) { + this.setState({ audit_visible: true }) + } + } + keyProductClick(row, index) { + console.log('keyProductClick 13==>', row) + if (this.state.direct_reseller_id > 0) { + /* 区分立减金 */ + if (row.type === 2) { + this.setState({ + product_title: '编辑立减金', + productData: row.origin, + addIsType: 'addKnockGold', + drawerVisible2: true + }) + } else { + this.setState({ + product_title: '编辑商品', + productData: row, + addIsType: 'addProduct', + drawerVisible2: true + }) + } + } else { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + } + render() { + const Column = [ + { + title: '兑换名称', + name: 'title', + prop: 'title', + type: 'normal', + width: 'auto' + }, + { + title: '兑换码范围', + + type: 'normal', + prop: 'range', + width: 'auto' + }, + { + title: '有效开始日期', + prop: 'begin_time', + name: 'begin_time', + width: 'auto', + type: 'normal' + }, + { + title: '有效结束日期', + name: 'end_time', + prop: 'end_time', + type: 'normal', + width: 'auto' + }, + { + title: '兑换码数量', + name: 'quantity', + type: 'normal', + prop: 'quantity', + defaultText: 'PM', + width: 'auto' + }, + { + title: '绑定数', + prop: 'restrict', + name: 'restrict', + type: 'slot', + width: 'auto' + }, + { + title: '操作', + prop: 'edit', + name: 'edit', + type: 'slot', + width: 'auto' + } + ] + //校验规则 + const rules = { + quantity: [ + { type: 'required', message: '请输入key数量' }, + { + type: 'regExp', + message: '请输入正整数', + reg: '^([1-9][0-9]*){1,3}$' + } + ], + bind_object: [{ type: 'required', message: '请选择绑定类型' }], + + batch_name: [{ type: 'required', message: '请输入key批次名称' }] + } + + const Column2 = [ + { + title: '商品ID', + name: 'product_id', + prop: 'product_id', + width: 'auto', + type: 'normal' + }, + { + title: '立减金平台批次号', + width: '250px', + prop: 'channel_activity_id', + name: 'channel_activity_id', + type: 'normal' + }, + { + title: '类型', + width: 'auto', + prop: 'type', + name: 'type', + type: 'slot' + }, + { + title: '上游平台', + width: 'auto', + prop: 'upstream', + name: 'upstream', + type: 'normal' + }, + { + title: '有效时间段', + width: '575px', + prop: 'effectDate', + name: 'effectDate', + type: 'normal' + }, + { + title: '商品名称', + width: 'auto', + prop: 'product_name', + name: 'product_name', + type: 'normal' + }, + { + title: '当前成本价格', + prop: 'cost_price', + name: 'cost_price', + width: '250px', + type: 'slot' + }, + { + title: '合同价', + name: 'contract_price', + prop: 'contract_price', + type: 'normal', + width: 'auto' + }, + { + title: '商品官方价', + type: 'normal', + prop: 'official_price', + width: 'auto' + }, + { + title: '库存数量', + prop: 'quantity', + name: 'quantity', + type: 'normal', + width: 'auto' + }, + { + title: '操作', + prop: 'edit', + name: 'edit', + type: 'slot', + width: 'auto' + } + ] + + //基本信息 + const codeInfo = { + code_name: [{ type: 'required', message: '请输入兑换码名称' }], + issued: [ + { type: 'required', message: '请输入发放总量' }, + { + type: 'regExp', + message: '请输入正整数', + reg: '^([1-9][0-9]*){1,3}$' + } + ] + } + + //基本规则 + const rulesInfo = { + date_time: [{ type: 'required', message: '请选择生效时间段' }], + rank: [{ type: 'required', message: '请选择商品范围' }] + } + + const excelColumn = [ + { + title: '行号', + name: 'line', + prop: 'line', + width: '30px', + type: 'normal' + }, + { + title: '手机号', + width: '80px', + prop: 'mobile', + name: 'mobile', + type: 'normal' + }, + { + title: '错误原因', + width: '80px', + prop: 'tips', + name: 'tips', + type: 'normal' + }, + { + title: '是否导入', + width: '50px', + prop: 'is_import', + name: 'is_import', + type: 'slot' + } + ] + return ( +是否取消本次操作?
, + onConfirm: () => { + window.history.back() + }, + onCancel: this.onCancel, + className: 'questModal', + parentComponent: this + }) + } + + closeDraw() { + this.setState({ drawerVisible: false }) + } + addProduct(type) { + this.setState({ addIsType: type }) /* 类型 */ + let direct_reseller_ids = this.state.direct_reseller_id + if (direct_reseller_ids <= 0) { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + + if (type === 'addProduct') { + this.setState({ product_title: '新建商品', newGoodsBtnLoading: true }) + } else { + this.setState({ product_title: '新增立减金', newGoldLoading: true }) + } + let param = { + reseller_id: direct_reseller_ids + } + try { + getProductInfoSelect(param).then((res) => { + if (res.code === 200) { + sessionStorage.setItem('productsList', JSON.stringify(res.data.data)) + this.setState({ productData: null }) + this.setState({ drawerVisible2: true }) + } + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + }) + } catch (err) { + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + } + } + //渲染范围列表数据以及数据转换 + async productSubmit() { + let visible = '' + if (this.state.addIsType === 'addProduct') { + visible = await this.refs.product.submit() + } else { + visible = await this.refs.knockGold.submit() + } + + if (visible) { + Notify.success('保存成功') + this.setState({ drawerVisible2: false }) + setTimeout(() => { + let data = null + let temp = null + let concatData = [] + /* 处理商品 */ + if (this.state.addIsType === 'addProduct') { + data = JSON.parse(sessionStorage.getItem('productData')).filter( + (item) => item.type !== 2 + ) + + concatData = this.state.tempdata.filter((item) => item.type !== 1) + + 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 + } + item.type = 1 + item.only = item.product_id + item.upstream = '直连天下' + return item + }) + } else { + /* 处理立减金 */ + data = JSON.parse(sessionStorage.getItem('knockGoldData')).filter( + (item) => item.type !== 1 + ) + + concatData = this.state.tempdata.filter((item) => item.type !== 2) + + temp = _.map(data, (item) => { + let index = this.state.tempdata.findIndex((o) => { + return o.channel_activity_id === item.channel_activity_id + }) + + if (index > -1) { + item.checked = this.state.tempdata[index].checked + } + + /* 转换商品结构 */ + // temp + const newObj = {} + newObj.product_name = item.batch_goods_name + ? item.batch_goods_name + : item.product_name //名字 + newObj.map_product_name = item.product_name + newObj.channel_activity_id = item.channel_activity_id //批次号 + newObj.only = item.channel_activity_id //批次号 + newObj.type = 2 //类型 + newObj.checked = item?.checked + newObj.upstream = String(item.channel) === '1' ? '支付宝' : '微信' //上游 + newObj.edit = 'edit' + newObj.effectDate = item.effectDate + ? item.effectDate + : item.time_limit?.effect_time.start_time + + ' 至 ' + + item.time_limit?.effect_time.end_time //有效时间 + newObj.contract_price = item.contract_price + ? item.contract_price + : item.price //单价 + newObj.official_price = item.official_price + ? item.official_price + : item.reduce_amount //官方价 + newObj.quantity = item.quantity + ? item.quantity + : Math.trunc(item.all_budget / item.reduce_amount) //总库 + newObj.origin = item?.origin ? item?.origin : item + return newObj + }) + } + let newArray = deWeightThree(temp.concat(concatData), 'only') + + //select数据 + let arr = [] + let rank = [] + _.map(newArray, (res) => { + arr.push({ key: res.only, text: res.product_name }) + if (res.checked) { + rank.push({ key: res.only, text: res.product_name }) + } + }) + + arr = deWeightThree(arr, 'key') + this.setState({ tempdata: newArray, rankoptions: arr, rank }) + }, 500) + } + } + onChangeCombinedDate(e) { + let model2 = this.state.codeInfo + model2.date_time = e + this.setState({ codeInfo: model2 }) + } + + //select + onRankChange(e) { + _.forEach(this.state.tempdata, (item) => { + item.checked = + e.findIndex((checks) => { + return checks.key == item.only + }) > -1 + }) + this.setState({ tempdata: this.state.tempdata }) + this.setState({ rank: e }) + } + codeSubmit() { + if (this.refs.code_info.validator() && this.refs.code_rule.validator()) { + if (this.state.uploading) { + Notify.error('还有图片上传中,不可提交') + return + } + + let productlist = _.filter(this.state.tempdata, (item) => { + return item.checked == true + }) + let sum = 0 + _.forEach(productlist, (o) => { + sum += parseInt(o.quantity) + }) + if (sum < this.state.codeInfo.issued) { + Notify.error('所选商品库存总数小于发放量') + return + } + // let productList = JSON.parse(sessionStorage.getItem("productsList")); + + this.setState({ drawerVisible: false }) + let rank = _.map(this.state.rank, (item) => { + return item.text + }) + + let temp = { + title: this.state.codeInfo.code_name, + 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, + range: rank.toString(), + restrict: this.state.codeInfo.restrict + } + + let arr = _.map(productlist, (item) => { + let obj = {} + obj.product_id = item.product_id + obj.product_type = item.product_type + obj.product_name = item.product_name + obj.account_type = item.account_type + obj.contract_price = item.contract_price + obj.cost_price = item.cost_price + obj.official_price = item.official_price + obj.quantity = item.quantity + obj.show_url = item.show_url + obj.describe_url = item.describe_url + obj.detail_url = item.detail_url + obj.map_product_name = item.map_product_name + if (item.type === 2) { + obj.channel_activity_id = item.channel_activity_id //批次号 + obj.effectDate = item.effectDate //有效时间 + obj.origin = item.origin // 原始数据 + } + obj.only = item.only + obj.weight = item.weight + obj.type = item.type + obj.upstream = item.upstream + return obj + }) + temp.product = arr + + if (this.state.rowIndex > -1) { + this.state.distdata[this.state.rowIndex] = temp + this.setState({ distdata: this.state.distdata }) + } else { + let tempdata = this.state.distdata + tempdata.push(temp) + this.setState({ distdata: tempdata }) + } + } + } + + onAudit() { + // if (!this.state.reseller) { + // Notify.error('对应分销商数据不存在') + // return + // } + /* 处理数据 区分立减金和商品 开始 2022-05-30 13:40*/ + const dataCopy = this.refs.bindObj.getSelectData() + if (dataCopy.filter((item) => !item.disabled).length == 0) { + Notify.error('请绑定对象') + return + } + dataCopy.map((item) => { + item.products = item.product + }) + + dataCopy.map((item) => + item.products.map(() => { + item.product = { + legal: item.products.filter((item2) => item2.type === 1), + reduce: item.products + .map((item2) => { + if (item2.type === 2) return item2.origin + }) + .filter((item3) => item3) + } + }) + ) + + dataCopy.map((item) => { + delete item.products + }) + /* 处理数据 区分立减金和商品 完成 2022-05-30 13:40*/ + let data = {} + data.batch_name = this.state.model.batch_name + data.copy_code_batch_id = this.state.model?.copy_code_batch_id + data.style = this.state.model.style + data.quantity = this.state.model.quantity + data.bind_object = this.state.checkedList + data.allow_repetition = this.state.model.allow_repetition + data.allow_loss = this.state.model.allow_loss + data.merge_stock = this.state.model.merge_stock + data.code_batch = dataCopy + + data.reseller_id = this.state.reseller.id + data.reseller_name = this.state.reseller.name + data.company_name = this.state.reseller.company_name + data.receive_email = this.state.reseller.contact_email[0] + data.payment_direction = + this.state.payment_direction[this.state.paytype - 1] + + data.mobile_excel = this.state.mobile_excel + data.mobile_repeat = this.state.mobile_repeat + + this.setState({ audit_visible: false }) + + keyEditApproval(this.state.copyBatch_id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + window.history.back() + }, 2000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + + onBindNum(e, row, rowIndex) { + this.state.distdata[rowIndex].restrict = e.target.value + this.setState({ distdata: this.state.distdata }) + } + + onDisabledRange = (date, type) => { + let step1 = JSON.parse(sessionStorage.getItem('plan_item')) + let isdisabled = false + let str = moment(date).format('YYYY-MM-DD HH:mm:ss') + if (type == 'start') { + isdisabled = + moment(str).isBefore(step1.begin_time) || + moment(str).isAfter(step1.end_time) + } + + if (type == 'end') { + isdisabled = + moment(str).add(1, 'days').isBefore(step1.begin_time) || + moment(str).isAfter(step1.end_time) + } + return isdisabled + } + + rowItemClick(row, rowIndex) { + let codeInfo = { + //数据模型不可少 + code_name: row.title, + issued: row.quantity, //发放总量 + describe: row.describe, + date_time: [row.begin_time, row.end_time], + range: row.range, + restrict: row.restrict + } + + let arr = _.map(row.product, (res) => { + let obj = {} + obj.key = res.only + obj.text = res.product_name + return obj + }) + this.setState({ + draw_title: '编辑兑换码', + rankoptions: arr, + rank: arr, + codeInfo: codeInfo, + rowIndex: rowIndex + }) + + let temp = _.map(row.product, (o) => { + o.checked = true + return o + }) + + sessionStorage.setItem('productData', JSON.stringify(row.product)) + sessionStorage.setItem('knockGoldData', JSON.stringify(row.product)) + this.setState({ drawerVisible: true, tempdata: temp }) + } + + 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) + : [] + } + : {} + } + + submitAudit() { + if (this.refs.form1.validator()) { + this.setState({ audit_visible: true }) + } + } + keyProductClick(row, index) { + console.log('keyProductClick 13==>', row) + if (this.state.direct_reseller_id > 0) { + /* 区分立减金 */ + if (row.type === 2) { + this.setState({ + product_title: '编辑立减金', + productData: row.origin, + addIsType: 'addKnockGold', + drawerVisible2: true + }) + } else { + this.setState({ + product_title: '编辑商品', + productData: row, + addIsType: 'addProduct', + drawerVisible2: true + }) + } + } else { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + } + render() { + return ( +是否取消本次操作?
, + onConfirm: () => { + window.history.back() + }, + onCancel: this.onCancel, + className: 'questModal', + parentComponent: this + }) + } + + onStyleChange(e) { + let model2 = this.state.model + model2.style = e.target.value + this.setState({ model: model2 }) + } + + onRepetitionChange(e) { + let model2 = this.state.model + model2.allow_repetition = e.target.value + this.setState({ model: model2 }) + } + + onLossChange(e) { + let model2 = this.state.model + model2.allow_loss = e.target.value + this.setState({ model: model2 }) + } + + checkIndex(e) { + switch (e) { + case 0: + this.setState({ draw_title: '新建兑换码' }) + break + case 1: + this.setState({ draw_title: '新建优惠券' }) + break + case 2: + this.setState({ draw_title: '新建立减金' }) + break + default: + return + } + this.setState({ drawerVisible: false }) + let codeInfo = { + //数据模型不可少 + code_name: '', + issued: '', //发放总量 + describe: '', + date_time: [this.state.begintime, this.state.endtime], + range: '' + } + + this.setState({ codeInfo: codeInfo }) + this.setState({ tempdata: [] }) + this.setState({ rank: null }) + this.setState({ rankoptions: [] }) + this.setState({ drawerVisible: true }) + sessionStorage.setItem('productData', '') + sessionStorage.setItem('knockGoldData', '') + } + + addProduct(type) { + this.setState({ addIsType: type }) /* 类型 */ + /* type: 立减金/商品 */ + let direct_reseller_ids = this.state.direct_reseller_id + if (direct_reseller_ids <= 0) { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + + if (type === 'addProduct') { + this.setState({ product_title: '新建商品', newGoodsBtnLoading: true }) + } else { + this.setState({ product_title: '新增立减金', newGoldLoading: true }) + } + let param = { + reseller_id: direct_reseller_ids + } + try { + getProductInfoSelect(param).then((res) => { + console.log('res ==>1', res) + console.log('this.state.tempdata ==>', this.state.tempdata) + if (res.code === 200) { + sessionStorage.setItem('productsList', JSON.stringify(res.data.data)) + console.log('res ==>2', res.data.data) + this.setState({ productData: null }) + this.setState({ drawerVisible2: true }) + } + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + }) + } catch (err) { + if (type === 'addProduct') { + this.setState({ + newGoodsBtnLoading: false + }) + } else { + this.setState({ + newGoldLoading: false + }) + } + } + } + + async productSubmit() { + let visible = '' + if (this.state.addIsType === 'addProduct') { + visible = await this.refs.product.submit() + } else { + visible = await this.refs.knockGold.submit() + } + if (visible) { + Notify.success('保存成功') + this.setState({ drawerVisible2: false }) + setTimeout(() => { + let data = null + let temp = null + let concatData = [] + /* 处理商品 */ + if (this.state.addIsType === 'addProduct') { + data = JSON.parse(sessionStorage.getItem('productData')).filter( + (item) => item.type != 2 + ) + concatData = this.state.tempdata.filter((item) => item.type !== 1) + 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 + } + + item.type = 1 + item.only = item.product_id + item.upstream = '直连天下' + return item + }) + } else { + /* 处理立减金 */ + data = JSON.parse(sessionStorage.getItem('knockGoldData')).filter( + (item) => item.type != 1 + ) + concatData = this.state.tempdata.filter((item) => item.type !== 2) + temp = _.map(data, (item) => { + let index = this.state.tempdata.findIndex((o) => { + return o.channel_activity_id === item.channel_activity_id + }) + + if (index > -1) { + item.checked = this.state.tempdata[index].checked + } + + /* 转换商品结构 */ + // temp + const newObj = {} + newObj.product_name = item.batch_goods_name + ? item.batch_goods_name + : item.product_name //名字 + newObj.channel_activity_id = item.channel_activity_id //批次号 + newObj.only = item.channel_activity_id //批次号 + newObj.type = 2 //类型 + newObj.checked = item?.checked + newObj.upstream = String(item.channel) === '1' ? '支付宝' : '微信' //上游 + newObj.edit = 'edit' + newObj.effectDate = item.effectDate + ? item.effectDate + : item.time_limit?.effect_time.start_time + + ' 至 ' + + item.time_limit?.effect_time.end_time //有效时间 + newObj.contract_price = item.contract_price + ? item.contract_price + : item.price //单价 + newObj.official_price = item.official_price + ? item.official_price + : item.reduce_amount //官方价 + newObj.quantity = item.quantity + ? item.quantity + : Math.trunc(item.all_budget / item.reduce_amount) //总库 + newObj.origin = item.origin ? item.origin : item + newObj.id = item.goods_id ? item.goods_id : item.id + return newObj + }) + } + let newArray = deWeightThree(temp.concat(concatData), 'only') + + //select数据 + let arr = [] + let rank = [] + _.map(newArray, (res) => { + arr.push({ key: res.only, text: res.product_name }) + if (res.checked) { + rank.push({ key: res.only, text: res.product_name }) + } + }) + + arr = deWeightThree(arr, 'key') + + this.setState({ tempdata: newArray, rankoptions: arr, rank }) + }, 500) + } + } + + onChangeCombinedDate(e) { + let model2 = this.state.codeInfo + model2.date_time = e + this.setState({ codeInfo: model2 }) + } + + onRankChange(e) { + _.forEach(this.state.tempdata, (item) => { + item.checked = + e.findIndex((checks) => { + return checks.key == item.only + }) > -1 + }) + this.setState({ tempdata: this.state.tempdata }) + this.setState({ rank: e }) + } + + codeSubmit() { + if (this.refs.code_info.validator() && this.refs.code_rule.validator()) { + let productlist = _.filter(this.state.tempdata, (item) => { + return item.checked == true + }) + let sum = 0 + let productList = JSON.parse(sessionStorage.getItem('productsList')) + + _.forEach(productlist, (o) => { + sum += parseInt(o.quantity) + }) + + if (sum < this.state.codeInfo.issued) { + Notify.error('所选商品库存总数小于发放量') + return + } + + if (this.state.uploading) { + Notify.error('还有图片上传中,不可提交') + return + } + + this.setState({ drawerVisible: false }) + let rank = _.map(this.state.rank, (item) => { + return item.text + }) + + let temp = { + title: this.state.codeInfo.code_name, + 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, + restrict: this.state.codeInfo.restrict, + range: rank.toString() + } + + let arr = _.map(productlist, (item) => { + let obj = {} + obj.product_id = item.product_id + obj.product_type = item.product_type + obj.product_name = item.product_name + obj.account_type = item.account_type + obj.contract_price = item.contract_price + obj.cost_price = item.cost_price + obj.official_price = item.official_price + obj.quantity = item.quantity + obj.show_url = item.show_url + obj.describe_url = item.describe_url + obj.detail_url = item.detail_url + obj.map_product_name = item.map_product_name + if (item.type === 2) { + obj.channel_activity_id = item.channel_activity_id //批次号 + obj.effectDate = item.effectDate //有效时间 + obj.origin = item.origin // 原始数据 + } + obj.weight = item.weight + obj.only = item.only + obj.type = item.type + obj.upstream = item.upstream + return obj + }) + temp.product = arr + if (this.state.rowIndex > -1) { + this.state.distdata[this.state.rowIndex] = temp + this.setState({ distdata: this.state.distdata }) + } else { + let tempdata = this.state.distdata + tempdata.push(temp) + this.setState({ distdata: tempdata }) + } + } + } + + onReCall() { + let approval_id = sessionStorage.getItem('approval_id') + this.setState({ recall_visible: false }) + if (approval_id > 0) { + 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) + } + ) + }) + } + } + + onSubmit() { + let selection = this.refs.bindObj.getSelectData() + if (selection.filter((item) => !item.disabled).length == 0) { + return Notify.error('请绑定对象') + } + + this.setState({ audit_visible: true }) + } + + onConfirm() { + let selection = this.refs.bindObj.getSelectData() + let formdata = selection.filter((item) => { + return !item.hasOwnProperty('disabled') || item.disabled == false + }) + + /* 被复制得兑换码id */ + let copy_code_id = ~~sessionStorage.getItem('copy_code_id') + // 转换数据 + let dataCopy = _.cloneDeep(formdata) + dataCopy.map((item) => { + item.products = item.product + }) + + dataCopy.map((item) => + item.products.map(() => { + item.product = { + legal: item.products.filter((item2) => item2.type == 1), + reduce: item.products + .filter((item3) => item3.type === 2) + .map((item4) => item4.origin) + } + }) + ) + + dataCopy.map((item) => { + delete item.products + }) + + //除了创建中 编辑key + if (this.state.isEdit) { + this.setState({ audit_visible: false }) + let approval_id = sessionStorage.getItem('approval_id') + if (approval_id > 0) { + getApprovalsStatus(approval_id).then((res) => { + handelResponse( + res, + (req, msg) => { + if (req.status == 0) { + this.setState({ recall_visible: true }) + } + if (req.status == 1) { + this.setState({ audit_visible: true }) + } + if (req.status == 2 || req.status == 3) { + let id = sessionStorage.getItem('keybatch_id') + let data = { + code_batch: dataCopy, + reseller_id: this.state.reseller.id, + reseller_name: this.state.reseller.name, + company_name: this.state.reseller.company_name, + receive_email: this.state.reseller.contact_email[0], + copy_code_id, + payment_direction: + this.state.payment_direction[this.state.paytype - 1] + } + + keyEditApproval(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + window.history.back() + }, 1000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + }, + (err) => { + Notify.error(err) + } + ) + }) + } else { + if (this.state.key_status != 1) { + let id = sessionStorage.getItem('keybatch_id') + let data = { + code_batch: dataCopy, + reseller_id: this.state.reseller?.id, + reseller_name: this.state.reseller?.name, + company_name: this.state.reseller?.company_name, + receive_email: this.state.reseller?.contact_email[0], + copy_code_id, + payment_direction: + this.state.payment_direction[this.state.paytype - 1] + } + + keyEditApproval(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + window.history.back() + }, 1000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } else { + let data = { + batch_name: this.state.model.batch_name, + style: this.state.model.style, + quantity: this.state.model.quantity, + bind_object: this.state.checkedList, + allow_repetition: this.state.model.allow_repetition, + allow_loss: this.state.model.allow_loss, + merge_stock: this.state.model.merge_stock, + mobile_excel: this.state.mobile_excel, + mobile_repeat: this.state.mobile_repeat, + code_batch: dataCopy, + reseller_id: this.state.reseller.id, + reseller_name: this.state.reseller.name, + company_name: this.state.reseller.company_name, + receive_email: this.state.reseller.contact_email[0], + copy_code_id, + payment_direction: + this.state.payment_direction[this.state.paytype - 1] + } + + let id = sessionStorage.getItem('keybatch_id') + putKeyBatchDetail(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + keyApproval(this.state.plan_id, id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + this.props.history.push('/home/key-list/') + }, 2000) + }, + (err) => { + Notify.error(err) + } + ) + }) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + } + } else { + //创建中 编辑key + let data = { + batch_name: this.state.model.batch_name, + style: this.state.model.style, + quantity: this.state.model.quantity, + bind_object: this.state.checkedList, + allow_repetition: this.state.model.allow_repetition, + allow_loss: this.state.model.allow_loss, + merge_stock: this.state.model.merge_stock, + mobile_excel: this.state.mobile_excel, + mobile_repeat: this.state.mobile_repeat, + code_batch: dataCopy, + copy_code_id, + reseller_id: this.state.reseller.id, + reseller_name: this.state.reseller.name, + company_name: this.state.reseller.company_name, + receive_email: this.state.reseller.contact_email[0], + payment_direction: this.state.payment_direction[this.state.paytype - 1] + } + + let id = sessionStorage.getItem('keybatch_id') + let approval_id = sessionStorage.getItem('approval_id') + if (approval_id > 0) { + getApprovalsStatus(approval_id).then((res) => { + handelResponse( + res, + (req, msg) => { + if (req.status == 0) { + this.setState({ recall_visible: true }) + } + if (req.status == 1) { + this.setState({ audit_visible: true }) + } + if (req.status == 2 || req.status == 3) { + putKeyBatchDetail(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + keyApproval(this.state.plan_id, id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + this.props.history.push('/home/key-list/') + }, 2000) + }, + (err) => { + Notify.error(err) + } + ) + }) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + }, + (err) => { + Notify.error(err) + } + ) + }) + } else { + keyApproval(this.state.plan_id, id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success('成功发起审批') + setTimeout(() => { + this.props.history.push('/home/key-list/') + }, 2000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + } + } + + onBindNum(e, row) { + let index = this.state.distdata.findIndex((o) => { + return o == row + }) + + this.state.distdata[index].restrict = e.target.value + this.setState({ distdata: this.state.distdata }) + } + + rowItemClick(row, rowIndex) { + let codeInfo = { + //数据模型不可少 + code_name: row.title, + issued: row.quantity, //发放总量 + describe: row.describe, + date_time: [row.begin_time, row.end_time], + range: row.range, + restrict: row.restrict + } + + this.setState({ codeInfo: codeInfo }) + + let arr = _.map(row.product, (res) => { + let obj = {} + obj.key = res.only + obj.text = res.product_name + return obj + }) + + this.setState({ + draw_title: '编辑兑换码', + rankoptions: arr, + rank: arr, + rowIndex: rowIndex + }) + + let temp = _.map(row.product, (o) => { + o.checked = true + return o + }) + sessionStorage.setItem('productData', JSON.stringify(row.product)) + sessionStorage.setItem('knockGoldData', JSON.stringify(row.product)) + this.setState({ tempdata: temp, drawerVisible: true }) + } + + 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 isdisabled = false + let str = moment(date).format('YYYY-MM-DD HH:mm:ss') + let beign_time = this.state.codeInfo.date_time[0] + let end_time = this.state.codeInfo.date_time[1] + if (type == 'start') { + isdisabled = + moment(str).isBefore(beign_time) || moment(str).isAfter(end_time) + } + + if (type == 'end') { + isdisabled = + moment(str).isBefore(beign_time) || moment(str).isAfter(end_time) + } + return isdisabled + } + + onPayTypeChange(e) { + this.setState({ paytype: e.target.value }) + } + + keyProductClick(row, index) { + console.log('keyProductClick 13==>', row) + if (this.state.direct_reseller_id > 0) { + /* 区分立减金 */ + if (row.type === 2) { + this.setState({ + product_title: '编辑立减金', + productData: row.origin, + addIsType: 'addKnockGold', + drawerVisible2: true + }) + } else { + this.setState({ + product_title: '编辑商品', + productData: row, + addIsType: 'addProduct', + drawerVisible2: true + }) + } + } else { + // 老数据不能进行新增商品操作 + Notify.error(`请添加映射分销商`) + return + } + } + + render() { + const Column = [ + { + title: '兑换名称', + name: 'title', + prop: 'title', + type: 'normal', + width: 'auto' + }, + { + title: '兑换码范围', + type: 'normal', + prop: 'range', + width: 'auto' + }, + { + title: '有效开始日期', + prop: 'begin_time', + name: 'begin_time', + width: 'auto', + type: 'normal' + }, + { + title: '有效结束日期', + name: 'end_time', + prop: 'end_time', + type: 'normal', + width: 'auto' + }, + { + title: '兑换码数量', + name: 'quantity', + type: 'normal', + prop: 'quantity', + defaultText: 'PM', + width: 'auto' + }, + { + title: '绑定数', + prop: 'restrict', + name: 'restrict', + type: 'slot', + width: 'auto' + }, + { + title: '操作', + prop: 'edit', + name: 'edit', + type: 'slot', + width: 'auto' + } + ] + //校验规则 + const rules = { + bind_object: [{ 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: 'normal' + }, + { + title: '立减金平台批次号', + width: '250px', + prop: 'channel_activity_id', + name: 'channel_activity_id', + type: 'normal' + }, + { + title: '类型', + width: 'auto', + prop: 'type', + name: 'type', + type: 'slot' + }, + { + title: '上游平台', + width: 'auto', + prop: 'upstream', + name: 'upstream', + type: 'normal' + }, + { + title: '有效时间段', + width: '575px', + prop: 'effectDate', + name: 'effectDate', + type: 'normal' + }, + { + title: '当前成本价格', + prop: 'cost_price', + name: 'cost_price', + width: '200px', + type: 'slot' + }, + { + title: '合同价', + name: 'contract_price', + prop: 'contract_price', + type: 'normal', + width: 'auto' + }, + { + title: '商品官方价', + type: 'normal', + prop: 'official_price', + width: 'auto' + }, + { + title: '库存', + type: 'normal', + prop: 'quantity', + width: 'auto' + }, + { + title: '操作', + prop: 'edit', + name: 'edit', + type: 'slot', + width: 'auto' + } + ] + + //基本信息 + const codeInfo = { + code_name: [{ type: 'required', message: '请输入兑换码名称' }], + issued: [ + { type: 'required', message: '请输入发放总量' }, + { + type: 'regExp', + message: '请输入正整数', + reg: '^([1-9][0-9]*){1,3}$' + } + ] + } + + //基本规则 + const rulesInfo = { + date_time: [{ type: 'required', message: '请选择生效时间段' }], + rank: [{ type: 'required', message: '请选择商品范围' }] + } + + return ( +