|
@@ -1,5 +1,5 @@
|
|
|
const uploadJS = require('../../mixin/upload.js')
|
|
|
-const { getProductCategoryList, getProductBrandList } = require('./api/index')
|
|
|
+const { getProductCategoryList, getProductBrandList, postAddProduct, postModifyProduct } = require('./api/index')
|
|
|
const { formatTs, yuan2Fen } = require('../../utils/util')
|
|
|
const minDate = new Date().getTime()
|
|
|
const objMinDate = formatTs(minDate)
|
|
@@ -53,17 +53,17 @@ Page({
|
|
|
'product_desc': '商品简介', // 商品简介
|
|
|
'product_category_id': {
|
|
|
'category_name': '',
|
|
|
- 'id': ''
|
|
|
+ 'id': '1'
|
|
|
}, // 分类ID
|
|
|
'product_brand_id': {
|
|
|
'brand_name': '',
|
|
|
- 'id': ''
|
|
|
+ 'id': '1'
|
|
|
}, // 品牌ID
|
|
|
- 'product_spec': '', // 规格
|
|
|
- 'product_unit': '', // 单位
|
|
|
- 'product_all_price': '', // 批发价
|
|
|
- 'product_price': '', // 零售价
|
|
|
- 'product_count': '', // 库存
|
|
|
+ 'product_spec': '10个没件', // 规格
|
|
|
+ 'product_unit': '个', // 单位
|
|
|
+ 'product_all_price': '100', // 批发价
|
|
|
+ 'product_price': '88', // 零售价
|
|
|
+ 'product_count': '100', // 库存
|
|
|
'product_sale_at': '预售' // 预售时间(0代表预售)
|
|
|
},
|
|
|
product_img_url_max: 1,
|
|
@@ -90,8 +90,17 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
async onLoad(options) {
|
|
|
+ const { id } = options
|
|
|
+
|
|
|
await this.fetchProductCategoryList()
|
|
|
await this.fetchProductBrandList()
|
|
|
+ if (id) {
|
|
|
+ this.setData({
|
|
|
+ 'form.id': id
|
|
|
+ }, () => {
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -374,7 +383,7 @@ Page({
|
|
|
product_all_price: yuan2Fen(product_all_price),
|
|
|
product_price: yuan2Fen(product_price),
|
|
|
product_count,
|
|
|
- product_sale_at
|
|
|
+ product_sale_at: product_sale_at === '预售' ? 0 : this.data.currentDate
|
|
|
}
|
|
|
},
|
|
|
setForm() {},
|
|
@@ -390,8 +399,6 @@ Page({
|
|
|
product_brand_id,
|
|
|
product_spec,
|
|
|
product_unit,
|
|
|
- product_all_price,
|
|
|
- product_price,
|
|
|
product_count,
|
|
|
product_sale_at
|
|
|
} = this.getForm()
|
|
@@ -432,19 +439,29 @@ Page({
|
|
|
if (!product_count) {
|
|
|
errorList.push('请输入库存')
|
|
|
}
|
|
|
- if (!product_sale_at) {
|
|
|
+ if (product_sale_at !== 0 && !product_sale_at) {
|
|
|
errorList.push('请选择发售时间')
|
|
|
}
|
|
|
|
|
|
return errorList
|
|
|
},
|
|
|
- onSubmit(e) {
|
|
|
+ async onSubmit(e) {
|
|
|
+ const temp = this.getForm()
|
|
|
const verifyList = this.verify()
|
|
|
+
|
|
|
if (verifyList.length) {
|
|
|
wx.showToast({
|
|
|
title: verifyList[0],
|
|
|
icon: 'none'
|
|
|
})
|
|
|
+ return
|
|
|
}
|
|
|
+ try {
|
|
|
+ let res = await postAddProduct(temp)
|
|
|
+ if (this.data.form.id) {
|
|
|
+ res = await postModifyProduct({ ...temp, id: this.data.form.id })
|
|
|
+ }
|
|
|
+ const { status, data, msg } = res
|
|
|
+ } catch (err) {}
|
|
|
}
|
|
|
})
|