Browse Source

小程序:商家端-商品添加

panyong 2 years ago
parent
commit
adea0690b7

+ 1 - 33
htmldev/wxMini/pages/businessGoodsEdit/api/index.js

@@ -28,22 +28,7 @@ export const postAddProduct = (obj) => request({
   url: '/api/shop/product/add',
   method: 'POST',
   data: {
-    // "product_img_url": "sdsd", //商品主图
-    // "product_rotation_img_list": [
-    //   "sdsjdsd"
-    // ], //商品轮播图
-    // "product_detail_img_list": [
-    //   "sdsndish"
-    // ], //详情图
-    // "product_title": "测试商品", //商品标题
-    // "product_category_id": 1, //分类ID
-    // "product_brand_id": 1, //品牌ID
-    // "product_spec": "xl", //规格
-    // "product_unit": "个", //单位
-    // "product_all_price": 10000, //批发价
-    // "product_price": 9000, //零售价
-    // "product_count": 1000, //库存
-    // "product_sale_at": 0 //预售时间(0代表预售)
+    ...obj
   },
   showLoading: true
 })
@@ -58,23 +43,6 @@ export const postModifyProduct = (obj) => request({
   method: 'POST',
   data: {
     ...obj
-    // "id": 1,
-    // "product_img_url": "sdsd", //商品主图
-    // "product_rotation_img_list": [
-    //   "sdsjdsd"
-    // ], //商品轮播图
-    // "product_detail_img_list": [
-    //   "sdsndish"
-    // ], //详情图
-    // "product_title": "测试商品1", //商品标题
-    // "product_category_id": 1, //分类ID
-    // "product_brand_id": 1, //品牌ID
-    // "product_spec": "xl", //规格
-    // "product_unit": "个", //单位
-    // "product_all_price": 10000, //批发价
-    // "product_price": 9000, //零售价
-    // "product_count": 1000, //库存
-    // "product_status": 0 //状态(0下架1上架)
   },
   showLoading: true
 })

+ 30 - 13
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -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) {}
   }
 })