From 28bac3845c4f89ded84575042ddda135875844ff Mon Sep 17 00:00:00 2001 From: wangsongsole Date: Wed, 18 May 2022 14:32:26 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=A2=B3=E7=90=86=E5=85=91=E6=8D=A2?= =?UTF-8?q?=E7=A0=81=E7=AE=A1=E7=90=86=E5=95=86=E5=93=81=E8=8C=83=E5=9B=B4?= =?UTF-8?q?=E7=BC=96=E8=BE=91=202=E3=80=81=E6=96=B0=E5=A2=9E=E7=AB=8B?= =?UTF-8?q?=E5=87=8F=E9=87=91=E6=B7=BB=E5=8A=A0uuid=203=E3=80=81=E5=B0=81?= =?UTF-8?q?=E8=A3=85uuid=E7=94=9F=E6=88=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/exchangecode/edit/edit.js | 13 +++++++++--- src/pages/plan/knockGold/index.jsx | 9 ++++++--- src/pages/plan/knockGold/utils.js | 31 +++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 src/pages/plan/knockGold/utils.js diff --git a/src/pages/exchangecode/edit/edit.js b/src/pages/exchangecode/edit/edit.js index 97ac742e..0cb65dcd 100644 --- a/src/pages/exchangecode/edit/edit.js +++ b/src/pages/exchangecode/edit/edit.js @@ -573,6 +573,7 @@ export default class exchangedit extends React.Component { this.setState({ codeInfo: model2 }) } + //渲染范围列表数据以及数据转换 async productSubmit() { let visible = '' if (this.state.addIsType === 'addProduct') { @@ -615,7 +616,7 @@ export default class exchangedit extends React.Component { data = JSON.parse(sessionStorage.getItem('knockGoldData')) temp = _.map(data, (item) => { let index = this.state.tempdata.findIndex((o) => { - return o.product_id === item.id + return o.product_id === item.uuid }) if (index > -1) { @@ -625,7 +626,7 @@ export default class exchangedit extends React.Component { /* 转换商品结构 */ // temp return { - product_id: item.id, + product_id: item.uuid, product_name: item.batch_goods_name, //名字 cost_price: '', contract_price: item.contract_price, //单价 @@ -689,6 +690,7 @@ export default class exchangedit extends React.Component { } } + /* 修改商品名称 */ onNameChange(e, row) { let rowIndex = this.state.tempdata.findIndex((o) => { return o.product_id == row.product_id @@ -696,6 +698,8 @@ export default class exchangedit extends React.Component { 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 @@ -713,6 +717,8 @@ export default class exchangedit extends React.Component { value - this.state.tempdata[rowIndex].usage this.setState({ tempdata: this.state.tempdata }) } + + /* 修改合同价 */ onPriceChange(e, row) { let str = e.target.value let value = str @@ -851,6 +857,7 @@ export default class exchangedit extends React.Component { }) } + /* 商品范围列表编辑 */ productEditShow(rowData) { console.log('direct_reseller_id ==>', this.state.direct_reseller_id) console.log('rowData 12==>', rowData) @@ -865,7 +872,7 @@ export default class exchangedit extends React.Component { if (rowData.type === 'knockGold') { const temp = JSON.parse(sessionStorage.getItem('knockGoldData')) const editData = temp.filter( - (item) => item.id === rowData.product_id + (item) => item.uuid === rowData.product_id ) this.setState({ diff --git a/src/pages/plan/knockGold/index.jsx b/src/pages/plan/knockGold/index.jsx index 0bec283e..930e3cdc 100644 --- a/src/pages/plan/knockGold/index.jsx +++ b/src/pages/plan/knockGold/index.jsx @@ -6,6 +6,7 @@ import Form from '../../../components/form/main' import FormItem from '../../../components/form-item/main' import rules from './rules' import moment from 'moment' +import { uuid } from './utils' import { Select, Button, @@ -30,7 +31,7 @@ export default class adduserinfo extends React.Component { this.state = { model: { //数据模型不可少 - id: '', + uuid: '', channel: '1', // 渠道 entry_time: '', // 生效时间 expire_time: '', // 过期时间 @@ -166,7 +167,7 @@ export default class adduserinfo extends React.Component { temp = JSON.parse(sessionStorage.getItem('knockGoldData')) let index = temp.findIndex((item) => { - return item.id === this.props.data.id + return item.uuid === this.props.data.uuid }) for (let key in this.state.model) { @@ -199,7 +200,9 @@ export default class adduserinfo extends React.Component { temp = JSON.parse(sessionStorage.getItem('knockGoldData')) } let data = temp ? temp : [] - data.push(this.state.model) + const models = this.state.model + models.uuid = uuid(6, 16) + data.push(models) sessionStorage.setItem('knockGoldData', JSON.stringify(data)) return true } diff --git a/src/pages/plan/knockGold/utils.js b/src/pages/plan/knockGold/utils.js new file mode 100644 index 00000000..f71985b1 --- /dev/null +++ b/src/pages/plan/knockGold/utils.js @@ -0,0 +1,31 @@ +/* uuid生成器 */ +export function uuid(len, radix) { + var chars = + '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') + var uuid = [], + i + radix = radix || chars.length + + if (len) { + // Compact form + for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)] + } else { + // rfc4122, version 4 form + var r + + // rfc4122 requires these characters + uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-' + uuid[14] = '4' + + // Fill in random data. At i==19 set the high bits of clock sequence as + // per rfc4122, sec. 4.1.5 + for (i = 0; i < 36; i++) { + if (!uuid[i]) { + r = 0 | (Math.random() * 16) + uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r] + } + } + } + + return uuid.join('') +}