diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index 842233a4..9b3f0d68 100644 --- a/src/pages/exchangecode/exchangecodeAdd/index.jsx +++ b/src/pages/exchangecode/exchangecodeAdd/index.jsx @@ -1,8 +1,8 @@ import React from 'react' -import Ipt from '../../../components/input/main' -import Form from '../../../components/form/main' -import FormItem from '../../../components/form-item/main' -import { deWeightThree } from '../../../utils' +import Ipt from '@/components/input/main' +import Form from '@/components/form/main' +import FormItem from '@/components/form-item/main' +import { deWeightThree } from '@/utils' import { Card, Radio, @@ -17,7 +17,7 @@ import { Input, BlockLoading } from 'zent' -import Bus from '../../../assets/eventBus.js' +import Bus from '@/assets/eventBus.js' import { getIsRequireApproval, getApprovalsStatus, @@ -29,20 +29,20 @@ import { uploadImg, getCodesDetail, putCodesBatch -} from '../../../assets/api.js' +} from '@/assets/api.js' import _ from 'lodash' -import Productform from '../product/add' +import ProductForm from '../product/add' /* 商品 */ import KnockGold from '@/components/knockGold' /* 立减金 */ - import './index.less' import moment from 'moment' -import Grid from '../../../components/gird/main.js' +import Grid from '@/components/gird/main.js' import { isSameDay } from 'date-fns' +import { Column2, rulesInfo, codeInfo } from './utils' const initArray = (targetNum) => { return Array.from({ length: targetNum }, (_, index) => index) } -export default class exchangedit extends React.Component { +export default class exchangeAdd extends React.Component { constructor(props) { super(props) this.state = { @@ -94,16 +94,29 @@ export default class exchangedit extends React.Component { newGoodsBtnLoading: false, tableLoading: false, newGoldLoading: false, - addIsType: '' + addIsType: '', + isState: 0 } } componentDidMount(e) { + const isState = sessionStorage.getItem('isState') /*复制1 编辑2 */ + this.setState({ isState }) + if (~~isState === 1) { + /* 复制 */ + } else if (~~isState === 2) { + /* 编辑 */ + this.editFunction() + } else { + /* 新增 */ + } + } + + /* 编辑处理数据 */ + editFunction() { let code_batch_id = sessionStorage.getItem('code_id') let approval_id = sessionStorage.getItem('approval_id') let approval_status = sessionStorage.getItem('approval_status') - console.log('approval_id ==>', Number(approval_id)) - if (Number(approval_id) > 0) { //此处为审核中 getApprovalsInfo(approval_id) @@ -121,7 +134,6 @@ export default class exchangedit extends React.Component { //获取分销商 getReseller(req.reseller_id).then((res) => { handelResponse(res, (req1, msg) => { - console.log('req ==>1', req1) req1.receive_email = req1.contact_email[0] this.setState({ reseller: req1 }) this.setState({ phone_list: req1.contact_phone }) @@ -270,7 +282,6 @@ export default class exchangedit extends React.Component { //获取分销商 getReseller(reqCopy.plan.reseller_id).then((res) => { handelResponse(res, (req1, msg) => { - console.log('req ==>1', req1) req1.receive_email = req1.contact_email[0] this.setState({ reseller: req1 }) this.setState({ phone_list: req1.contact_phone }) @@ -602,9 +613,6 @@ export default class exchangedit extends React.Component { ) }) } - onPayTypeChange(e) { - this.setState({ paytype: e.target.value }) - } submit() { // if (this.state.direct_reseller_id <= 0) { @@ -625,7 +633,6 @@ export default class exchangedit extends React.Component { } let approval_id = sessionStorage.getItem('approval_id') - console.log('approval_id ==>', approval_id) if (Number(approval_id) <= 0) { //非审核中状态 @@ -683,30 +690,6 @@ export default class exchangedit extends React.Component { 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(type) { @@ -727,7 +710,6 @@ export default class exchangedit extends React.Component { } try { getProductInfoSelect(param).then((res) => { - console.log('home/exchangecode-edit ==> 1', res) if (res.code === 200) { sessionStorage.setItem('productsList', JSON.stringify(res.data.data)) this.setState({ productData: null }) @@ -862,129 +844,7 @@ export default class exchangedit extends React.Component { } } - // - 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) => { + onDisabledTime = (date) => { const min = new Date() const hour = min.getHours() const minute = min.getMinutes() @@ -1005,9 +865,6 @@ export default class exchangedit extends React.Component { } 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') @@ -1060,8 +917,6 @@ export default class exchangedit extends React.Component { /* 商品范围列表编辑 */ productEditShow(rowData) { - console.log('direct_reseller_id ==>', this.state.direct_reseller_id) - console.log('rowData 12==>', rowData) if (this.state.direct_reseller_id > 0) { this.setState({ tableLoading: true @@ -1098,119 +953,8 @@ export default class exchangedit extends React.Component { return } } + 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: '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: '450px', - prop: 'effectDate', - name: 'effectDate', - type: 'normal' - }, - - { - title: '当前成本价格', - prop: 'cost_price', - name: 'cost_price', - width: 'auto', - 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: '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 (