From 98fa4f7cbca74b91d846396f8cf27f7602eb6aa0 Mon Sep 17 00:00:00 2001 From: zhangds Date: Fri, 2 Sep 2022 11:06:47 +0800 Subject: [PATCH] =?UTF-8?q?1)=20=E5=A2=9E=E5=8A=A0=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E6=96=B0=E5=BB=BA=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UseCouponAddEdit/index.jsx | 101 +- src/components/UseGoodsScopePop/index.jsx | 85 + src/pages/plan/add/step2 copy.js | 1927 --------------------- src/tools/ls.js | 44 + 4 files changed, 224 insertions(+), 1933 deletions(-) create mode 100644 src/components/UseGoodsScopePop/index.jsx delete mode 100644 src/pages/plan/add/step2 copy.js create mode 100644 src/tools/ls.js diff --git a/src/components/UseCouponAddEdit/index.jsx b/src/components/UseCouponAddEdit/index.jsx index ab30a791..ba1eb643 100644 --- a/src/components/UseCouponAddEdit/index.jsx +++ b/src/components/UseCouponAddEdit/index.jsx @@ -1,8 +1,13 @@ -import React, { forwardRef, useImperativeHandle, useRef } from "react"; +import React, { + forwardRef, + useImperativeHandle, + useRef, + useEffect, +} from "react"; import { useSetState } from "ahooks"; import { FixedSizeList } from "react-window"; import { isAmount } from "@/tools/validate"; -import { Card, DateRangePicker, Button, Select } from "zent"; +import { Card, DateRangePicker, Button, Select, Notify } from "zent"; import moment from "moment"; import Ipt from "@/components/input/main"; @@ -10,8 +15,11 @@ import Form from "@/components/form/main"; import FormItem from "@/components/form-item/main"; import Grid from "@/components/gird/main.js"; +import UseGoodsScopePop from "../UseGoodsScopePop/index"; + +import { getProductInfoSelect, handelResponse } from "@/assets/api.js"; + import "./style.less"; -import { useEffect } from "react"; const tableColumn = [ { @@ -172,6 +180,12 @@ const UseCouponAddEdit = forwardRef((props, ref) => { text: `key 1`, }, ], + addProductBtnLoading: false, + addGoldBtnLoading: false, + product_title: "", + showScopePop: false, + scopePopType: "", + productData: [], }); // 基础信息 @@ -209,13 +223,17 @@ const UseCouponAddEdit = forwardRef((props, ref) => { })); const submit = () => { + // 基础信息 let el_setup1 = form_info_el.current.validator(); console.log("el_setup1 =>", el_setup1); console.log("form_info_data =>", form_info_data); + // 发放规则 let el_setup2 = form_rule_el.current.validator(); console.log("el_setup2 =>", el_setup2); console.log("form_rule_data =>", form_rule_data); + + // 商品范围 }; const onReturn = () => {}; @@ -234,7 +252,56 @@ const UseCouponAddEdit = forwardRef((props, ref) => { const onCountChange = () => {}; const selectionFun = () => {}; const onRankChange = () => {}; - const addProduct = () => {}; + const addProduct = (type) => { + // 第一步:获取直连天下的商品数据需要分销商 id + const direct_reseller_ids = 23329; + if (direct_reseller_ids <= 0) { + Notify.error(`请添加映射分销商`); + return; + } + + // 第二步: 区分是新建商品还是立减金 + if (type === "addProduct") { + setState({ + product_title: "新建商品", + addProductBtnLoading: true, + scopePopType: "addProduct", + }); + } else { + setState({ + product_title: "新增立减金", + addGoldBtnLoading: true, + scopePopType: "addKnockGold", + }); + } + + // 第三步:获取商品数据 + let param = { + reseller_id: direct_reseller_ids, + }; + try { + getProductInfoSelect(param).then((res) => { + setState({ addProductBtnLoading: false, addGoldBtnLoading: false }); + handelResponse( + res, + (req, msg) => { + // !!!!!!!!!!!!!! 为了兼容老版本 新增商品设为空!!!老版本使用 productsList 获取商品数据!!!!!!!!!! + sessionStorage.setItem("productsList", JSON.stringify(req.data)); + setState({ + showScopePop: true, + }); + }, + (err) => { + console.log("err =>", err); + } + ); + }); + } catch (err) { + setState({ addProductBtnLoading: false, addGoldBtnLoading: false }); + } + // !!!!!!!!!!!!!! 为了兼容老版本 新增商品设为空!!!老版本使用 productsList 获取商品数据!!!!!!!!!! + setState({ productData: null }); + }; const renderOptionList = (options, renderOption) => { return ( { }); } }; + + // 优惠券弹窗 取消 + const scopePopClose = () => { + setState({ + showScopePop: false, + }); + }; + + // 优惠券弹窗 提交 + const scopePopSubmit = (data) => { + console.log("data =>", data); + }; + return (
@@ -444,7 +524,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
+ + scopePopClose()} + submit={(data) => scopePopSubmit(data)} + > ); }); diff --git a/src/components/UseGoodsScopePop/index.jsx b/src/components/UseGoodsScopePop/index.jsx new file mode 100644 index 00000000..01f4321c --- /dev/null +++ b/src/components/UseGoodsScopePop/index.jsx @@ -0,0 +1,85 @@ +import React, { forwardRef, useImperativeHandle, useRef } from "react"; +import { Card, Drawer, Button } from "zent"; + +import Productform from "@/pages/plan/product/add"; /* 商品 */ +import KnockGold from "@/components/knockGold"; /* 立减金 */ + +import _ from "lodash"; + +const UseGoodsScopePop = forwardRef((props, ref) => { + const { product_title, drawerVisible, onClose, type, productData, submit } = + props; + + // 如果需要 通过ref 控制此组件 放开注释 + // useImperativeHandle(ref, () => ({ + // submit: submitPop, + // })); + + const product_el = useRef(null); + const knockGold_el = useRef(null); + + // 提交数据 + const submitPop = async () => { + let data = null; + let temp = null; + let concatData = []; + // 第一步:判断是立减金还是新建商品 + let visible = false; + if (type === "addProduct") { + visible = await product_el.current.submit(); + } else { + visible = await knockGold_el.current.submit(); + } + console.log("visible =>", visible); + if (visible) { + if (type === "addProduct") { + data = sessionStorage.getItem("productData"); + console.log("商品data =>", JSON.parse(data)); + } + submit(1); + } + }; + + return ( + + + + + } + visible={drawerVisible} + onClose={(e) => onClose()} + maskClosable={false} + > +
+ + {type === "addKnockGold" ? ( + + ) : ( + + )} + +
+
+ ); +}); + +export default UseGoodsScopePop; diff --git a/src/pages/plan/add/step2 copy.js b/src/pages/plan/add/step2 copy.js deleted file mode 100644 index 94671674..00000000 --- a/src/pages/plan/add/step2 copy.js +++ /dev/null @@ -1,1927 +0,0 @@ -/* 生成key step2 */ -import ReactDOM from "react-dom"; -import React from "react"; -import { deWeightThree } from "../../../utils"; - -import "./step2.less"; -import { - Card, - Drawer, - Button, - Tabs, - Notify, - DateRangePicker, - Select, - Input, - Checkbox, - Radio, - Switch, - Icon, - RadioGroup, - RadioButton, - BlockLoading, -} 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 { - handelResponse, - getAccessVerification, - 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 moment from "moment"; -import { uploadImg } from "../../../assets/api.js"; -import "./add.less"; -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 = { - model: { - //数据模型不可少 - style: 1, - quantity: 1, - allow_repetition: 0, - allow_loss: 0, - merge_stock: 1, - code_batch: "", - draw_title: "", - batch_name: "", - }, - drawerVisible: false, - drawerVisible2: false, - checkedList: [], - productData: [], - radioType: 1, - codeInfo: { - //数据模型不可少 - code_name: "", - issued: "", //发放总量 - describe: "", - date_time: "", - range: "", - }, - rank: null, - rankoptions: [], - tempdata: [], - distdata: [], - column_distdata: [], - exceldata: [], - oldData: null, - uploading: false, - rowIndex: -1, - isload: props.isload ? props.isload : false, - 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, - whiteStyle: false, - import_success: false, - - product_title: "新建商品", - newGoodsBtnLoading: false /* 商品按钮lodging */, - newGoldLoading: false /* 立减金按钮lodging */, - direct_reseller_id: 0, - tableLoading: false, - isCopy: props.isCopy ? true : false, - 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", - }, - ], - Column_coupon: [ - { - 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", - }, - ], - }; - } - - componentDidMount(e) { - const dom = ReactDOM.findDOMNode(this); - let items = dom.getElementsByClassName("form-Item"); - let input = items[1].getElementsByTagName("input")[0]; - input.focus(); - if (this.props.name > 0) { - this.setState({ whiteStyle: this.props.whiteStyle }); - this.setState({ white_visible: this.props.whiteStyle }); - let model = this.state.model; - model.style = this.props.keyStyle; - this.setState({ model: model }); - } - } - - submit() { - let valide = false; - if (this.refs.form1.validator()) { - /* 处理数据 区分立减金和商品 开始 2022-05-30 13:40*/ - const dataCopy = this.refs.tempdata.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.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.mobile_excel = this.state.mobile_excel; - data.mobile_repeat = this.state.mobile_repeat; - return data; - } - return valide; - } - - onCancel() { - this.refs.form1.cancel(); - } - onCheckChange = (arr) => { - this.setState({ checkedList: arr }); - let checkedList = arr; - }; - - // 单选 - onRadioChange(e) { - this.setState({ - radioType: e.target.value, - }); - } - - onStyleChange(e) { - if (this.props.name == 0) { - this.props.onStyleChange(e); - } - - let model2 = this.state.model; - model2.style = e.target.value; - model2.quantity = 0; - this.setState({ model: model2 }); - if (e.target.value == 6) { - sessionStorage.setItem("white", 1); - this.setState({ white_visible: true }); - } else { - sessionStorage.setItem("white", 3); - 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: - break; - } - sessionStorage.setItem("productData", ""); - sessionStorage.setItem("knockGoldData", ""); - - let codeInfo = { - //数据模型不可少 - code_name: "", - issued: "", //发放总量 - describe: "", - date_time: JSON.parse(sessionStorage.getItem("datetime")), - range: "", - }; - this.setState({ rank: null }); - this.setState({ rankoptions: [] }); - this.setState({ codeInfo: codeInfo }); - this.setState({ tempdata: [] }); - this.setState({ drawerVisible: true }); - this.setState({ rowIndex: -1 }); - } - closeDraw() { - this.setState({ drawerVisible: false }); - } - - // 获取直连天下商品数据 - getProductInfoSelectData(reseller_id) { - return new Promise((resolve, reject) => { - let param = { - reseller_id: reseller_id, - }; - getProductInfoSelect(param).then((res) => { - if (res.code === 200) { - resolve(res.data.data); - } else { - reject([]); - } - }); - }); - } - - // 获取 直连天下数据 - addProduct(type) { - this.setState({ addIsType: type }); /* 类型 */ - /* type: 立减金/商品 */ - let direct_reseller_ids = this.props.direct_reseller_id; - console.log("direct_reseller_ids =>", direct_reseller_ids); - if (direct_reseller_ids <= 0) { - // 老数据不能进行新增商品操作 - Notify.error(`请添加映射分销商`); - return; - } - - if (type === "addProduct") { - this.setState({ product_title: "新建商品", newGoodsBtnLoading: true }); - } else { - this.setState({ product_title: "新增立减金", newGoldLoading: true }); - } - - this.getProductInfoSelectData(direct_reseller_ids).then((data) => { - sessionStorage.setItem("productsList", JSON.stringify(data)); - if (type === "addProduct") { - this.setState({ - newGoodsBtnLoading: false, - }); - } else { - this.setState({ - newGoldLoading: false, - }); - } - this.setState({ productData: null }); - this.setState({ drawerVisible2: true }); - }); - } - - 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); - } - } - setkeyStyle(style) { - if (style == 6) { - this.setState({ whiteStyle: true }); - this.setState({ white_visible: true }); - } else { - this.setState({ whiteStyle: false }); - this.setState({ white_visible: false }); - } - - let model = this.state.model; - model.style = style; - this.setState({ model: model }); - } - componentWillReceiveProps(nextProps) {} - - onChangeCombinedDate(e) { - let model2 = this.state.codeInfo; - model2.date_time = e; - this.setState({ codeInfo: model2 }); - } - submit2() { - this.refs.form2.validator(); - } - 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; - - _.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(), - }; - - console.log(productlist); - 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.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?.toString(); - obj.detail_url = item.detail_url; - obj.account_type = item.account_type; - 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 }); - } - } - } - addNewKey() { - this.props.addNewkey(); - } - onRestrict(e, rowdata, index) { - let text = e.target.value; - text = text.replace(/[^\d]/g, ""); - this.state.distdata[index].restrict = text; - this.setState({ distdata: this.state.distdata }); - } - - onDisabledCombinedDate = (val) => { - let step1 = JSON.parse(sessionStorage.getItem("step1")); - let str = moment(val).format("YYYY-MM-DD HH:mm:ss"); - let isBetween = moment(str).isBetween( - step1.begin_time, - step1.end_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("knockGold_effectDate")); - let isdisabled = false; - let str = moment(date).format("YYYY-MM-DD HH:mm:ss"); - let isDay = moment(step1.end_time).format("HH:mm:ss"); - if (type == "start") { - if (isDay < "23:59:59") { - isdisabled = - moment(str).isBefore(step1.begin_time) || - moment(str).subtract(1, "days").isAfter(step1.end_time); - } else { - 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; - }; - - edit(data) { - let model = { - //数据模型不可少 - batch_name: data.batch_name, - style: parseInt(data.style), - quantity: data.quantity, - allow_repetition: parseInt(data.allow_repetition), - allow_loss: parseInt(data.allow_loss), - merge_stock: data.merge_stock, - code_batch: data.code_batch, - draw_title: data.draw_title, - }; - this.setState({ mobile_excel: data.mobile_excel }); - this.setState({ mobile_repeat: data.mobile_repeat }); - if (model.style == 6) { - this.setState({ white_visible: true }); - } - - this.setState({ model: model }); - this.setState({ checkedList: data.bind_object.map(Number) }); - - let temp = _.map(data.code_batch, (o) => { - o.checked = true; - return o; - }); - - this.setState({ distdata: temp }); - this.setState({ isload: true }); - } - - 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; - - let arr = _.map(this.state.tempdata, (res) => { - let obj = {}; - obj.key = res.product_id; - obj.text = res.product_name; - return obj; - }); - this.setState({ rankoptions: arr }); - this.setState({ rank: arr }); - 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 }); - } - - 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({ tempdata: temp, drawerVisible: true }); - } - - 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 }); - } - - 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 }); - } - - 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("请上传正确的文件"); - } - } - } - 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 }); - } - - 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"; - } - /* 商品范围列表编辑 */ - productEditShow(rowData) { - console.log("rowData 12==>", rowData); - if (this.props.direct_reseller_id > 0) { - this.setState({ - tableLoading: true, - }); - this.getProductInfoSelectData(this.props.direct_reseller_id).then( - (data) => { - sessionStorage.setItem("productsList", JSON.stringify(data)); - /* 区分立减金 */ - if (rowData.type === 2) { - console.log("编辑立减金:", rowData.origin); - let obj = rowData.origin; - // 是否是复制操作 - if (this.state.isCopy) { - delete obj.id; - } - this.setState({ - product_title: "编辑立减金", - productData: obj, - addIsType: "addKnockGold", - }); - } else { - this.setState({ - product_title: "编辑商品", - productData: rowData, - addIsType: "addProduct", - }); - } - setTimeout(() => { - this.setState({ - tableLoading: false, - }); - this.setState({ drawerVisible2: true }); - }, 300); - } - ); - } else { - // 老数据不能进行新增商品操作 - Notify.error(`请添加映射分销商`); - return; - } - } - - render() { - //校验规则 - const rules = { - 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: "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: "库存总数量", - prop: "quantity", - name: "quantity", - type: "normal", - width: "auto", - }, - { - title: "操作", - prop: "edit", - name: "edit", - type: "slot", - width: "auto", - }, - ]; - - const rules2 = { - codename: [{ type: "required", message: "请输入兑换码名称" }], - issued: [{ type: "required", message: "请输入发放总量" }], - tip: [{ type: "required", message: "请输入" }], - }; - - //基本信息 - 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 ( -
-
- - { - this.onStyleChange(e); - }} - value={this.state.model.style} - > - 0 && this.state.model.style == 6} - > - 串码 - - 0 && this.state.model.style == 6} - > - 链接 - - 0 && this.state.model.style == 6} - > - 二维码 - - 0 && this.state.model.style != 6} - > - 白名单 - - - - - {this.state.isload ? ( - - { - let model2 = this.state.model; - model2.batch_name = e; - this.setState({ model: model2 }); - }} - onClearItem={(e) => { - let model2 = this.state.model; - model2.batch_name = ""; - this.setState({ model: model2 }); - }} - value={this.state.model.batch_name} - placeholder={"请输入"} - labelWidth={"0px"} - maxLength={12} - height={"36px"} - width={"400px"} - alignment={"left"} - /> - - ) : null} - - {this.state.isload ? ( - -
- { - let model2 = this.state.model; - model2.quantity = e; - this.setState({ model: model2 }); - }} - onClearItem={(e) => { - let model2 = this.state.model; - model2.quantity = ""; - this.setState({ model: model2 }); - }} - value={this.state.model.quantity} - disabled={this.state.model.style == 6} - placeholder={"请输入"} - labelWidth={"0px"} - maxLength={5} - height={"36px"} - width={"400px"} - alignment={"left"} - /> - - {this.state.white_visible ? ( - - ) : null} -
-
- ) : null} - - { - this.onCheckChange(e); - }} - > - 兑换码 - - 优惠券 - - - - {/* this.onRadioChange(e)} - value={this.state.radioType} - > - 兑换码 - 优惠券 - */} - - - - {this.state.radioType === 1 ? ( - - ) : null} - {this.state.radioType === 2 ? ( - - ) : null} - - - - - { - this.pageChange(e); - }} - checkChange={(selection) => {}} - ComponentHandler={(com, rowData, rowIndex) => { - if (com == "restrict") { - return ( - { - this.onRestrict(e, rowData, rowIndex); - }} - /> - ); - } - if (com == "edit") { - return ( - { - this.rowItemClick(rowData, rowIndex); - }} - style={{ color: "#2B66F2" }} - > - 编辑 - - ); - } - }} - /> - - - this.onRepetitionChange(e)} - value={this.state.model.allow_repetition} - > - - - - - - - this.onLossChange(e)} - value={this.state.model.allow_loss} - > - - - - -
-
{ - this.addNewKey(); - }} - > - 添加新的批次key -
- - - - -
- } - visible={this.state.drawerVisible} - onClose={(e) => { - this.closeDraw(); - }} - maskClosable={false} - > -
- -
-
- - { - 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"} - /> - - - { - let model = this.state.codeInfo; - model.issued = e; - this.setState({ codeInfo: model }); - }} - onClearItem={(e) => { - let model = this.state.codeInfo; - model.issued = ""; - this.setState({ codeInfo: model }); - }} - unit="条" - countShow={false} - value={this.state.codeInfo.issued} - placeholder={"请输入发放总量"} - labelWidth={"0px"} - maxLength={12} - height={"36px"} - width={"520px"} - alignment={"left"} - /> - - - { - let model = this.state.codeInfo; - model.describe = e.target.value; - this.setState({ codeInfo: model }); - }} - /> - -
-
-
- -
-
- - { - Bus.emit("change", "date_time", e); - this.onChangeCombinedDate(e); - }} - disabledTime={this.onDisabledTime} - disabledDate={this.onDisabledRange} - /> - - -
- this.fileChange(e)} - /> - - 更新文件 -
- )} -
- {this.state.success_visible ? ( -
- - 文件解析成功,点击确定导入 即可导入 -
- ) : null} - {this.state.fail_visible ? ( -
- - 文件解析失败,请查看导入规则并更新文件 -
- ) : null} -
- ) : ( -
- this.fileChange(e)} - /> - {" "} -
- )} - -
-
下载模板并填写后上传
- -
-
- 请先下载「数字世界营销管理系统_白名单_模板」并按照模板填写后再上传。 -
-
-
- -
-
- - -
-
- - - ) : null} - - - - - - } - visible={this.state.drawerVisible2} - onClose={(e) => { - this.setState({ drawerVisible2: false }); - }} - maskClosable={false} - > -
- - {this.state.addIsType === "addKnockGold" ? ( - - ) : ( - - )} - -
-
- - {this.state.excel_visible ? ( -
-
-
-
-
从Excel导入白名单
- { - this.setState({ excel_visible: false }); - }} - /> -
-
- 文件上传成功.共{this.state.excel_count}条手机号,其中 - {this.state.success_count}条可成功导入 -
-
- 发现以下{this.state.error_count}条不符合要求,将不会被导入 -
- -
- -
- { - this.pageChange(e); - }} - ComponentHandler={(com, rowData, rowIndex) => { - if (com == "is_import") { - if ( - rowData.type == "success" || - rowData.type == "repeat" - ) { - let checked = rowData.type == "success"; - return ( - { - this.switchChange(e, rowData); - }} - /> - ); - } else { - return
-
; - } - // if(rowData.type == "repeat") - // { - // return - // } - // if(rowData.type == "success") - // { - // return - // } - // else{ - // return
-
- // } - } - }} - /> -
-
-
- - -
-
-
-
- ) : null} - - ); - } -} diff --git a/src/tools/ls.js b/src/tools/ls.js new file mode 100644 index 00000000..ae2c70d8 --- /dev/null +++ b/src/tools/ls.js @@ -0,0 +1,44 @@ +"use strict"; +exports.__esModule = true; +var Store = /** @class */ (function () { + function Store() { + this.store = window.localStorage; + this.prefix = "bk_"; + } + Store.prototype.set = function (key, value, callback) { + if (callback === void 0) { + callback = function () {}; + } + var val; + try { + val = JSON.stringify(value); + } catch (e) { + val = value; + } + this.store.setItem(this.prefix + key, val); + callback(); + }; + Store.prototype.get = function (key) { + if (!key) { + throw new Error("没有找到key。"); + } + if (typeof key === "object") { + throw new Error("key不能是一个对象。"); + } + var value = this.store.getItem(this.prefix + key); + var val; + if (value !== null) { + try { + val = JSON.parse(value); + } catch (e) { + val = value; + } + } + return val; + }; + Store.prototype.remove = function (key) { + this.store.removeItem(this.prefix + key); + }; + return Store; +})(); +exports["default"] = new Store();