1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| submit = () => { this.props.form.validateFields(async (error, values) => { if (!error) {
const {name, desc, price, categoryIds} = values let pCategoryId, categoryId if (categoryIds.length===1) { pCategoryId = '0' categoryId = categoryIds[0] } else { pCategoryId = categoryIds[0] categoryId = categoryIds[1] } const imgs = this.pw.current.getImgs() const detail = this.editor.current.getDetail()
const product = {name, desc, price, imgs, detail, pCategoryId, categoryId}
if(this.isUpdate) { product._id = this.product._id }
const result = await reqAddOrUpdateProduct(product)
if (result.status===0) { message.success(`${this.isUpdate ? '更新' : '添加'}商品成功!`) this.props.history.goBack() } else { message.error(`${this.isUpdate ? '更新' : '添加'}商品失败!`) } } }) }
|