fix: 修复优惠券key批次接口

This commit is contained in:
zhangds 2022-10-09 18:32:08 +08:00
parent 0b2c7ddf5c
commit d015c4ae1b
5 changed files with 4282 additions and 296 deletions

View File

@ -204,7 +204,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
coupon_batch_id: "",
isEdit: false,
oldProduct: {}, // ,
id: 0,
id: "",
status: -1,
});
@ -548,7 +548,7 @@ const UseCouponAddEdit = forwardRef((props, ref) => {
//
const clearCouponForm = () => {
setState({ id: 0, status: "" });
setState({ id: "", status: "" });
setForm_rule_data({
full: "",
reduce: "",

View File

@ -894,44 +894,28 @@ export default class acclist extends React.Component {
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");
data.copy_key_batch_id = this.state.keyCodeId;
addKeysBatchInfo(id, data).then((res) => {
addKeysBatchInfo(this.state.model.plan_id, data).then((res) => {
handelResponse(
res,
(req, msg) => {
// keyApproval(id, req.key_batch_id, data).then((res) => {
// handelResponse(
// res,
// (req, msg) => {
Notify.success(res.message);
setTimeout(() => {
// this.props.history.push('/home/key-list/')
window.history.back();
}, 2000);
// },
// (err) => {
// Notify.error(err)
// }
// )
// })
},
(err) => {
Notify.error(err);
@ -1304,6 +1288,14 @@ export default class acclist extends React.Component {
this.setState({ audit_visible: true });
}
}
// 优惠券范围
coupon_range(product) {
let arr_legal = product.legal.map((item) => item.product_name);
let arr_reduce = product.reduce.map((item) => item.batch_goods_name);
let arr = arr_legal.concat(arr_reduce);
arr = arr.join(",");
return <span>{arr}</span>;
}
keyProductClick(row, index) {
console.log("keyProductClick 13==>", row);
if (this.state.direct_reseller_id > 0) {
@ -1636,6 +1628,10 @@ export default class acclist extends React.Component {
/>
);
}
// 优惠券范围
if (com === "product" && this.state.keyType === 2) {
return this.coupon_range(rowData.product);
}
if (com == "edit") {
return (
<span

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,7 @@ import {
getApprovalsStatus,
approvals,
getProductInfoSelect,
addKeysBatchInfo,
} from "../../../assets/api.js";
import Productform from "../product/add";
import Bus from "../../../assets/eventBus.js";
@ -221,6 +222,8 @@ export default class acclist extends React.Component {
},
],
rowCouponData: "",
id: "",
white_visible: false,
};
}
@ -321,6 +324,7 @@ export default class acclist extends React.Component {
this.setState({ mobile_excel: req.mobile_excel });
this.setState({ mobile_repeat: req.mobile_repeat });
this.setState({ status: req.status });
this.setState({ id: req.id });
console.log("详情 =>", req);
this.keyFormat(req);
// 如果有审批单的数据
@ -788,173 +792,24 @@ export default class acclist extends React.Component {
this.setState({ audit_visible: true });
}
onConfirm() {
// 兑换码
if (this.state.keyType === 1) {
let selection = this.refs.bindObj.getSelectData();
let formdata = selection.filter((item) => {
return !item.hasOwnProperty("disabled") || item.disabled == false;
});
// 转换数据
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),
};
})
// 优惠券审核提交逻辑
couponSubmit() {
let keybatch_id = sessionStorage.getItem("keybatch_id");
// key_status 1 创建中 审核驳回
if (this.state.key_status === 1) {
console.log("this.state.couponData =>", this.state.couponData);
// 判断是否有数据的审核驳回
let couponArr = this.state.couponData.filter(
(item) => item.id && item.id !== ""
);
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 selection = this.refs.bindObj.getSelectData()
// let dataCopy = selection.filter((item) => {
// return (
// !item.hasOwnProperty('disabled') || item.disabled == false
// )
// })
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],
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],
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.keyType],
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],
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(res.message);
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.keyType],
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,
if (couponArr.length > 0) {
let edit_coupon_data = this.state.couponData.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "")
);
let edit_param = {
coupon: edit_coupon_data,
reseller_id: this.state.reseller.id,
reseller_name: this.state.reseller.name,
company_name: this.state.reseller.company_name,
@ -962,78 +817,26 @@ export default class acclist extends React.Component {
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(res.message);
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);
}
);
});
}
}
} else {
let id = sessionStorage.getItem("keybatch_id");
// 如果是创建中的状态走新增接口 key_status 1
console.log("this.state.key_status =>", this.state.key_status);
if (this.state.key_status === 1) {
keyEditApproval(keybatch_id, edit_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
window.history.back();
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
} else {
let coupon_data = this.state.couponData.filter(
(item) => item.checked === true && !item.id
);
let create_param = {
id: this.state.id,
batch_name: this.state.model.batch_name,
style: this.state.model.style,
quantity: this.state.model.quantity,
@ -1051,40 +854,9 @@ export default class acclist extends React.Component {
payment_direction:
this.state.payment_direction[this.state.paytype - 1],
};
console.log("新增 =>", create_param);
keyApproval(this.state.plan_id, id, create_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
this.props.history.push("/home/key-list/");
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
} else {
console.log("this.state.couponData =>", this.state.couponData);
// 优惠券
let edit_coupon_data = this.state.couponData.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || !item.id)
);
let edit_param = {
coupon: edit_coupon_data,
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],
};
console.log("编辑 =>", edit_param);
keyEditApproval(id, edit_param).then((res) => {
console.log("addKeysBatchInfo");
console.log("create_param =>", create_param);
addKeysBatchInfo(this.state.plan_id, create_param).then((res) => {
handelResponse(
res,
(req, msg) => {
@ -1099,6 +871,105 @@ export default class acclist extends React.Component {
);
});
}
} else {
// 其它状态
let edit_coupon_data = this.state.couponData.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "")
);
let edit_param = {
coupon: edit_coupon_data,
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],
};
keyEditApproval(keybatch_id, edit_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
window.history.back();
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
}
}
// 兑换码
exchangeSubmit() {
let keybatch_id = sessionStorage.getItem("keybatch_id");
let selection = this.refs.bindObj.getSelectData();
let formdata = selection.filter((item) => {
return !item.hasOwnProperty("disabled") || item.disabled == false;
});
// 转换数据
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_status 1 创建中 审核驳回
if (this.state.key_status === 1) {
} else {
// 其它状态
let edit_exchange_data = this.state.distdata.filter(
(item) =>
item.checked === true &&
(item.status === -1 || item.status === 7 || item.id === "")
);
let edit_param = {
coupon: edit_exchange_data,
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],
};
console.log("edit_param =>", edit_param);
return;
keyEditApproval(keybatch_id, edit_param).then((res) => {
handelResponse(
res,
(req, msg) => {
Notify.success("成功发起审批");
setTimeout(() => {
window.history.back();
}, 1000);
},
(err) => {
Notify.error(err);
}
);
});
}
}
onConfirm() {
// keyType 1兑换码 2优惠券
if (this.state.keyType === 1) {
this.exchangeSubmit();
} else {
this.couponSubmit();
}
}
@ -1429,7 +1300,29 @@ export default class acclist extends React.Component {
prop="batch_name"
id="batch_name"
>
<div className="line-value">{this.state.model.batch_name}</div>
{this.state.key_status === 1 ? (
<Ipt
onChange={(e) => {
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"}
/>
) : (
<div className="line-value">{this.state.model.batch_name}</div>
)}
</FormItem>
<FormItem labelname=" key样式" prop="style" id="style">
<RadioGroup
@ -1439,20 +1332,60 @@ export default class acclist extends React.Component {
value={this.state.model.style}
disabled={this.state.isEdit}
>
<RadioButton value={1}>串码</RadioButton>
<RadioButton value={2}>链接</RadioButton>
<RadioButton value={4}>二维码</RadioButton>
<RadioButton value={6}>白名单</RadioButton>
<RadioButton value={1} disabled={this.state.model.style == 6}>
串码
</RadioButton>
<RadioButton value={2} disabled={this.state.model.style == 6}>
链接
</RadioButton>
<RadioButton value={4} disabled={this.state.model.style == 6}>
二维码
</RadioButton>
<RadioButton value={6} disabled={this.state.model.style != 6}>
白名单
</RadioButton>
</RadioGroup>
</FormItem>
{this.state.white_visible ? (
<Button
type="primary"
onClick={(e) => {
this.initUpload();
this.setState({ import_visible: true });
}}
>
导入白名单
</Button>
) : null}
<FormItem labelname="key发放" prop="quantity" id="quantity">
<div className="line-value">{this.state.model.quantity}</div>
{this.state.key_status === 1 ? (
<Ipt
onChange={(e) => {
let model2 = this.state.model;
model2.quantity = e;
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"}
/>
) : (
<div className="line-value">{this.state.model.quantity}</div>
)}
</FormItem>
<FormItem labelname="key剩余" prop="quantity" id="quantity">
<div className="line-value">{this.state.model.stock}</div>
</FormItem>
{this.state.key_status === 1 ? null : (
<FormItem labelname="key剩余" prop="quantity" id="quantity">
<div className="line-value">{this.state.model.stock}</div>
</FormItem>
)}
<FormItem labelname="绑定类型" prop="bind_object" id="bind_object">
<Radio.Group