提交兑换码代码
This commit is contained in:
parent
75fb80965f
commit
2fb3d6916a
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,4 @@
|
|||
import React from "react"
|
||||
import React, { Fragment } from "react"
|
||||
import Ipt from "@/components/input/main"
|
||||
import Form from "@/components/form/main"
|
||||
import FormItem from "@/components/form-item/main"
|
||||
|
@ -27,7 +27,10 @@ import {
|
|||
getProductInfoSelect,
|
||||
handelResponse,
|
||||
getCodesDetail,
|
||||
putCodesBatch
|
||||
putCodesBatch,
|
||||
keyEditApproval,
|
||||
queryPlans,
|
||||
queryKeyBatch
|
||||
} from "@/assets/api.js"
|
||||
import _ from "lodash"
|
||||
import ProductForm from "../product/add" /* 商品 */
|
||||
|
@ -51,22 +54,76 @@ export default class exchangeAdd extends React.Component {
|
|||
const isState = ~~sessionStorage.getItem("isState") /*复制1 编辑2 */
|
||||
code_batch_id = ~~sessionStorage.getItem("code_id") /* 兑换码id */
|
||||
this.setState({ isState })
|
||||
if (isState === 1) {
|
||||
/* 复制 */
|
||||
this.copyFunction()
|
||||
} else if (isState === 2) {
|
||||
/* 编辑 */
|
||||
this.editFunction()
|
||||
|
||||
/* 编辑和复制时才调用 */
|
||||
if (isState) {
|
||||
this.getDetailFunction()
|
||||
} else {
|
||||
/* 新增 */
|
||||
sessionStorage.setItem("productData", [])
|
||||
sessionStorage.setItem("knockGoldData", [])
|
||||
this.getPlanSelect()
|
||||
}
|
||||
}
|
||||
|
||||
/* 请求归属营销计划下拉框数据 */
|
||||
getPlanSelect() {
|
||||
queryPlans({ status: "3,4,5" }).then((res) => {
|
||||
handelResponse(
|
||||
res,
|
||||
(req, msg) => {
|
||||
const select = req.map((o) => {
|
||||
return { key: o.id, text: o.title, ...o }
|
||||
})
|
||||
this.setState({ planSelectData: select })
|
||||
},
|
||||
(err) => {
|
||||
Notify.error(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/* 请求归属key下拉框数据 */
|
||||
getKeyBatchSelect(key) {
|
||||
queryKeyBatch({
|
||||
status: "4,5",
|
||||
plan_id: key
|
||||
}).then((res) => {
|
||||
handelResponse(
|
||||
res,
|
||||
(req, msg) => {
|
||||
const select = req.map((o) => {
|
||||
return { key: o.id, text: o.batch_name, ...o }
|
||||
})
|
||||
this.setState({ keyBatchSelectData: select })
|
||||
},
|
||||
(err) => {
|
||||
Notify.error(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/* 获取分销商 */
|
||||
getResellerFunction(reseller_id) {
|
||||
getReseller(reseller_id).then((res) => {
|
||||
handelResponse(res, (req1, msg) => {
|
||||
this.setState({
|
||||
direct_reseller_id: req1.direct_reseller_id,
|
||||
reseller: req1,
|
||||
phone_list: req1.contact_phone,
|
||||
email_list: req1.contact_email[0]
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/* 编辑处理数据 */
|
||||
editFunction() {
|
||||
getDetailFunction() {
|
||||
let approval_id = sessionStorage.getItem("approval_id")
|
||||
let approval_status = sessionStorage.getItem("approval_status")
|
||||
if (Number(approval_id) > 0) {
|
||||
/* 判断是否是在审批中、状态是否时编辑 */
|
||||
if (Number(approval_id) > 0 && this.state.isState === 2) {
|
||||
//此处为审核中
|
||||
getApprovalsInfo(approval_id)
|
||||
.then((res) => {
|
||||
|
@ -80,20 +137,8 @@ export default class exchangeAdd extends React.Component {
|
|||
receive_email: req.receive_email
|
||||
}
|
||||
|
||||
//获取分销商
|
||||
getReseller(req.reseller_id).then((res) => {
|
||||
handelResponse(res, (req1, msg) => {
|
||||
req1.receive_email = req1.contact_email[0]
|
||||
this.setState({ reseller: req1 })
|
||||
this.setState({ phone_list: req1.contact_phone })
|
||||
this.setState({ email_list: req1.contact_email })
|
||||
this.setState({
|
||||
direct_reseller_id: req1.direct_reseller_id
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
this.setState({ reseller: resller_obj })
|
||||
this.getResellerFunction(req.reseller_id)
|
||||
|
||||
req.update_product = [...this.transFormData1(req.update_product)]
|
||||
req.new_product = [...this.transFormData1(req.new_product, true)]
|
||||
|
@ -128,7 +173,9 @@ export default class exchangeAdd extends React.Component {
|
|||
res,
|
||||
(req, msg) => {
|
||||
codeInfo.stock = req.stock
|
||||
this.setState({ plan_time: req.plan.end_time })
|
||||
this.setState({
|
||||
plan_time: [req.plan.start_time, req.plan.end_time]
|
||||
})
|
||||
let reqCopy = _.cloneDeep(req)
|
||||
const resData = this.transFormData(reqCopy)
|
||||
this.setState({ oldTable: resData })
|
||||
|
@ -227,20 +274,20 @@ export default class exchangeAdd extends React.Component {
|
|||
range: reqCopy.goods
|
||||
}
|
||||
|
||||
this.setState({ plan_time: reqCopy.plan.end_time })
|
||||
//获取分销商
|
||||
getReseller(reqCopy.plan.reseller_id).then((res) => {
|
||||
handelResponse(res, (req1, msg) => {
|
||||
req1.receive_email = req1.contact_email[0]
|
||||
this.setState({ reseller: req1 })
|
||||
this.setState({ phone_list: req1.contact_phone })
|
||||
this.setState({ email_list: req1.contact_email })
|
||||
this.setState({
|
||||
direct_reseller_id: req1.direct_reseller_id
|
||||
})
|
||||
})
|
||||
/* 复制状态改变code_name */
|
||||
if (this.state.isState === 1) {
|
||||
codeInfo.code_name = `${reqCopy.title}_${
|
||||
reqCopy.copy_count + 1
|
||||
}`
|
||||
}
|
||||
|
||||
this.setState({
|
||||
plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time]
|
||||
})
|
||||
|
||||
//获取分销商
|
||||
this.getResellerFunction(reqCopy.plan.reseller_id)
|
||||
|
||||
this.setState({ codeInfo: codeInfo })
|
||||
this.setState({ isload: true })
|
||||
_.map(reqCopy.goods, (res) => {
|
||||
|
@ -279,74 +326,6 @@ export default class exchangeAdd extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
/* 复制处理数据 */
|
||||
copyFunction() {
|
||||
getCodesDetail(code_batch_id)
|
||||
.then((res) => {
|
||||
handelResponse(
|
||||
res,
|
||||
(req, msg) => {
|
||||
let reqCopy = _.cloneDeep(req)
|
||||
const resData = this.transFormData(reqCopy)
|
||||
reqCopy.goods = resData
|
||||
let codeInfo = {
|
||||
code_name: reqCopy.title /* 兑换码名称 count++ */,
|
||||
issued: reqCopy.quantity,
|
||||
stock: reqCopy.stock,
|
||||
describe: reqCopy.describe,
|
||||
date_time: [reqCopy.begin_time, reqCopy.end_time],
|
||||
range: reqCopy.goods
|
||||
}
|
||||
|
||||
this.setState({ plan_time: reqCopy.plan.end_time })
|
||||
//获取分销商
|
||||
getReseller(reqCopy.plan.reseller_id).then((res) => {
|
||||
handelResponse(res, (req1, msg) => {
|
||||
req1.receive_email = req1.contact_email[0]
|
||||
this.setState({
|
||||
reseller: req1,
|
||||
phone_list: req1.contact_phone,
|
||||
email_list: req1.contact_email,
|
||||
direct_reseller_id: req1.direct_reseller_id
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
this.setState({ isload: true, codeInfo: codeInfo })
|
||||
_.map(reqCopy.goods, (res) => {
|
||||
res.checked = true
|
||||
return res
|
||||
})
|
||||
this.setState({ tempdata: reqCopy.goods || [] })
|
||||
|
||||
let a1 = reqCopy.goods.map((item) => {
|
||||
let obj = {
|
||||
...item,
|
||||
in: true
|
||||
}
|
||||
return obj
|
||||
})
|
||||
sessionStorage.setItem("productData", JSON.stringify(a1))
|
||||
sessionStorage.setItem("knockGoldData", JSON.stringify(a1))
|
||||
|
||||
let arr = []
|
||||
_.map(reqCopy.goods, (res) => {
|
||||
let obj = {}
|
||||
obj.key = res.only
|
||||
obj.text = res.product_name
|
||||
obj.id = res.id
|
||||
this.state.oldProduct.push(res.id)
|
||||
arr.push(obj)
|
||||
return obj
|
||||
})
|
||||
this.setState({ rankoptions: arr, rank: arr })
|
||||
},
|
||||
(err) => {}
|
||||
)
|
||||
})
|
||||
.catch((err) => {})
|
||||
}
|
||||
|
||||
// 立减金 加款后 商品范围列表数据进行变动
|
||||
getTableList() {
|
||||
if (sessionStorage.getItem("addMoneyData")) {
|
||||
|
@ -494,6 +473,7 @@ export default class exchangeAdd extends React.Component {
|
|||
})
|
||||
}
|
||||
|
||||
/* 编辑状态 数据整合 */
|
||||
buildData() {
|
||||
let range = []
|
||||
_.map(this.state.rank, (o) => {
|
||||
|
@ -597,6 +577,47 @@ export default class exchangeAdd extends React.Component {
|
|||
return { data, addProduct, updateProduct }
|
||||
}
|
||||
|
||||
/* 复制\新增状态 数据整合 */
|
||||
copyOrAddBuildData() {
|
||||
let range = []
|
||||
_.map(this.state.rank, (o) => {
|
||||
range.push(o.text)
|
||||
})
|
||||
|
||||
let selection = this.refs.tempdata.getSelectData()
|
||||
const newData = {
|
||||
begin_time: this.state.codeInfo.date_time[0],
|
||||
end_time: this.state.codeInfo.date_time[1],
|
||||
describe: this.state.codeInfo.describe,
|
||||
quantity: this.state.codeInfo.issued,
|
||||
range,
|
||||
title: this.state.codeInfo.code_name,
|
||||
product: [
|
||||
{
|
||||
legal: selection.filter((item2) => item2.type == 1),
|
||||
reduce: selection
|
||||
.filter((item3) => item3.type === 2)
|
||||
.map((item4) => item4.origin)
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
if (this.state.isState === 1) {
|
||||
newData.copy_code_batch_id = code_batch_id
|
||||
}
|
||||
|
||||
let data = {
|
||||
code_batch: newData,
|
||||
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]
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/* 编辑状态下数据提交 */
|
||||
submitCodeData() {
|
||||
if (!this.state.reseller) {
|
||||
Notify.error("该兑换码对应分销商不存在")
|
||||
|
@ -625,13 +646,34 @@ export default class exchangeAdd extends React.Component {
|
|||
})
|
||||
}
|
||||
|
||||
/* 复制\新增状态下数据提交 */
|
||||
submitCopyOrAddCodeData() {
|
||||
let data = this.copyOrAddBuildData()
|
||||
let id = sessionStorage.getItem("keybatch_id")
|
||||
|
||||
keyEditApproval(id, data).then((res) => {
|
||||
handelResponse(
|
||||
res,
|
||||
(req, msg) => {
|
||||
Notify.success("成功发起审批")
|
||||
setTimeout(() => {
|
||||
window.history.back()
|
||||
}, 1000)
|
||||
},
|
||||
(err) => {
|
||||
Notify.error(err)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
submit() {
|
||||
// if (this.state.direct_reseller_id <= 0) {
|
||||
// // 老数据不能进行新增商品操作
|
||||
// Notify.error(`请添加映射分销商`)
|
||||
// return
|
||||
// }
|
||||
if (this.refs.code_info.validator() && this.refs.code_rule.validator()) {
|
||||
if (!(this.refs.code_info.validator() && this.refs.code_rule.validator())) {
|
||||
return
|
||||
}
|
||||
|
||||
/* 编辑状态 */
|
||||
if (this.state.isState === 2) {
|
||||
if (this.state.uploading) {
|
||||
Notify.error("还有图片上传中,不可提交")
|
||||
return
|
||||
|
@ -694,12 +736,33 @@ export default class exchangeAdd extends React.Component {
|
|||
)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
/* 复制和新增状态 */
|
||||
let selection = this.refs.tempdata.getSelectData()
|
||||
|
||||
if (this.state.uploading) {
|
||||
return Notify.error("还有图片上传中,不可提交")
|
||||
}
|
||||
|
||||
if (selection.length < 1) {
|
||||
return Notify.error("请绑定对象")
|
||||
}
|
||||
|
||||
if (!this.state.reseller) {
|
||||
return Notify.error("该兑换码对应分销商不存在")
|
||||
}
|
||||
|
||||
this.setState({ audit_visible: true })
|
||||
}
|
||||
}
|
||||
|
||||
onConfirm() {
|
||||
this.setState({ audit_visible: false })
|
||||
this.submitCodeData()
|
||||
if (this.state.isState !== 2) {
|
||||
this.submitCopyOrAddCodeData() /* 复制、新增 */
|
||||
} else {
|
||||
this.submitCodeData() /* 编辑 */
|
||||
}
|
||||
}
|
||||
|
||||
addProduct(type) {
|
||||
|
@ -878,9 +941,14 @@ export default class exchangeAdd extends React.Component {
|
|||
let isdisabled = false
|
||||
let str = moment(date).format("YYYY-MM-DD HH:mm:ss")
|
||||
|
||||
if (type == "end") {
|
||||
isdisabled = moment(str).isAfter(this.state.plan_time)
|
||||
if (type === "start") {
|
||||
isdisabled = moment(str).isBefore(this.state.plan_time[0])
|
||||
}
|
||||
|
||||
if (type === "end") {
|
||||
isdisabled = moment(str).isAfter(this.state.plan_time[1])
|
||||
}
|
||||
|
||||
return isdisabled
|
||||
}
|
||||
|
||||
|
@ -984,34 +1052,54 @@ export default class exchangeAdd extends React.Component {
|
|||
rules={codeInfo}
|
||||
ref='code_info'
|
||||
className='addform'>
|
||||
<FormItem labelname='归属计划' prop='planId' id='planId'>
|
||||
<Select
|
||||
onChange={(e) => this.handleChange(e, "planId")}
|
||||
clearable
|
||||
value={this.state.codeInfo.planId}
|
||||
options={this.state.rankoptions}
|
||||
placeholder={"请选择"}
|
||||
labelWidth={"0px"}
|
||||
height={"36px"}
|
||||
width={"520px"}
|
||||
disabled={this.state.isState}
|
||||
alignment={"left"}
|
||||
/>
|
||||
</FormItem>
|
||||
<FormItem labelname='归属key' prop='keyBatchId' id='keyBatchId'>
|
||||
<Select
|
||||
onChange={(e) => this.handleChange(e, "keyBatchId")}
|
||||
clearable
|
||||
value={this.state.codeInfo.keyBatchId}
|
||||
options={this.state.rankoptions}
|
||||
placeholder={"请选择"}
|
||||
labelWidth={"0px"}
|
||||
height={"36px"}
|
||||
width={"520px"}
|
||||
disabled={this.state.isState}
|
||||
alignment={"left"}
|
||||
/>
|
||||
</FormItem>
|
||||
{!this.state.isState ? (
|
||||
<FormItem
|
||||
labelname='归属计划'
|
||||
prop='planSelect'
|
||||
id='planSelect'>
|
||||
<Select
|
||||
onChange={(e) => {
|
||||
this.handleChange(e, "planSelect")
|
||||
if (e?.key) {
|
||||
this.getKeyBatchSelect(e.key)
|
||||
this.getResellerFunction(e.reseller_id)
|
||||
this.setState({
|
||||
plan_time: [e.start_time, e.end_time]
|
||||
})
|
||||
}
|
||||
}}
|
||||
clearable
|
||||
value={this.state.codeInfo.planSelect}
|
||||
options={this.state.planSelectData}
|
||||
placeholder={"请选择"}
|
||||
labelWidth={"0px"}
|
||||
height={"36px"}
|
||||
width={"520px"}
|
||||
disabled={this.state.isState}
|
||||
alignment={"left"}
|
||||
/>
|
||||
</FormItem>
|
||||
) : null}
|
||||
{!this.state.isState ? (
|
||||
<FormItem
|
||||
labelname='归属key'
|
||||
prop='keyBatchSelect'
|
||||
id='keyBatchSelect'>
|
||||
<Select
|
||||
onChange={(e) => this.handleChange(e, "keyBatchSelect")}
|
||||
clearable
|
||||
value={this.state.codeInfo.keyBatchSelect}
|
||||
options={this.state.keyBatchSelectData}
|
||||
placeholder={"请选择"}
|
||||
labelWidth={"0px"}
|
||||
height={"36px"}
|
||||
width={"520px"}
|
||||
disabled={this.state.isState}
|
||||
alignment={"left"}
|
||||
/>
|
||||
</FormItem>
|
||||
) : null}
|
||||
|
||||
<FormItem
|
||||
labelname='兑换码名称'
|
||||
prop='code_name'
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//基本信息
|
||||
export const codeInfo = {
|
||||
code_name: [{ type: "required", message: "请输入兑换码名称" }],
|
||||
planId: [{ type: "required", message: "请选择归属计划" }],
|
||||
keyBatchId: [{ type: "required", message: "请选择归属Key" }],
|
||||
planSelect: [{ type: "required", message: "请选择归属计划" }],
|
||||
planSelect: [{ type: "required", message: "请选择归属Key" }],
|
||||
issued: [{ type: "required", message: "请输入发放总量" }]
|
||||
}
|
||||
|
||||
|
@ -133,8 +133,8 @@ export const init = () => {
|
|||
date_time: "",
|
||||
range: "",
|
||||
stock: "",
|
||||
planId: "",
|
||||
keyBatchId: ""
|
||||
planSelect: [] /* 归属计划 */,
|
||||
keyBatchSelect: [] /* 归属key */
|
||||
},
|
||||
isload: false,
|
||||
tempdata: [],
|
||||
|
|
Loading…
Reference in New Issue