Browse Source

小程序:首页接口对接

panyong 2 years ago
parent
commit
f59de12648

+ 1 - 0
htmldev/wxMini/README.md

@@ -52,6 +52,7 @@
 
 * 我的
   * 申请入驻 -> 填写表单:需要审核 -> 变成商户
+    * 审核中、审核失败、审核成功
   * 农户收藏:收藏之后的展示、在哪里去收藏
 
 * 商户消息:

+ 1 - 1
htmldev/wxMini/mixin/upload.js

@@ -74,7 +74,7 @@ module.exports = {
     temp.splice(index, 1)
 
     this.setData({
-      ['form.' + formkey]: temp
+      [`form.${formkey}`]: temp
     })
   },
   async uploadImg(event) {

+ 62 - 0
htmldev/wxMini/pages/businessGoodsEdit/api/index.js

@@ -1,5 +1,53 @@
 const { request } = require('../../../api/request')
 
+const mockData = {
+  'product_img_url': [
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
+      'formkey': 'product_rotation_img_list'
+    }
+  ], // 商品主图
+  'product_rotation_img_list': [
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
+      'formkey': 'product_rotation_img_list'
+    },
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe51c4.jpg',
+      'formkey': 'product_rotation_img_list'
+    },
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffefa54.jpg',
+      'formkey': 'product_rotation_img_list'
+    },
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi6323230067e26.png',
+      'formkey': 'product_rotation_img_list'
+    }
+  ], // 商品轮播图
+  'product_detail_img_list': [
+    {
+      'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
+      'formkey': 'product_rotation_img_list'
+    }
+  ], // 详情图
+  'product_title': '商品标题', // 商品标题
+  'product_desc': '商品简介', // 商品简介
+  'product_category_id': {
+    'category_name': '',
+    'id': '1'
+  }, // 分类ID
+  'product_brand_id': {
+    'brand_name': '',
+    'id': '1'
+  }, // 品牌ID
+  'product_spec': '10个没件', // 规格
+  'product_unit': '个', // 单位
+  'product_all_price': '100', // 批发价
+  'product_price': '88', // 零售价
+  'product_count': '100', // 库存
+  'product_sale_at': '预售' // 预售时间(0代表预售)
+}
 /**
  * 商品添加
  * @param obj
@@ -27,3 +75,17 @@ export const postModifyProduct = (obj) => request({
   },
   showLoading: true
 })
+
+/**
+ * 商品详情
+ * @param id 商品ID
+ * @returns {Promise<*>}
+ */
+export const getProductDetail = (id) => request({
+  url: '/api/shop/product/detail',
+  method: 'POST',
+  data: {
+    id: id
+  },
+  showLoading: true
+})

+ 156 - 82
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -1,7 +1,7 @@
 const uploadJS = require('../../mixin/upload.js')
-const { postAddProduct, postModifyProduct } = require('./api/index')
+const { postAddProduct, postModifyProduct, getProductDetail } = require('./api/index')
 const { getProductCategoryList, getProductBrandList } = require('../../api/common')
-const { formatTs, yuan2Fen } = require('../../utils/util')
+const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
 const minDate = new Date().getTime()
 const objMinDate = formatTs(minDate)
 
@@ -20,51 +20,24 @@ Page({
     // * 状态:现售产品有上架、下架状态
     // * 发售时间:不能低于当前创建时间
     form: {
-      'product_img_url': [
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
-          'formkey': 'product_rotation_img_list'
-        }
-      ], // 商品主图
-      'product_rotation_img_list': [
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
-          'formkey': 'product_rotation_img_list'
-        },
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe51c4.jpg',
-          'formkey': 'product_rotation_img_list'
-        },
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffefa54.jpg',
-          'formkey': 'product_rotation_img_list'
-        },
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi6323230067e26.png',
-          'formkey': 'product_rotation_img_list'
-        }
-      ], // 商品轮播图
-      'product_detail_img_list': [
-        {
-          'url': 'https://tuotuoyinfu-oss.oss-cn-beijing.aliyuncs.com/images/user/bashi632322ffe57fa.jpg',
-          'formkey': 'product_rotation_img_list'
-        }
-      ], // 详情图
-      'product_title': '商品标题', // 商品标题
-      'product_desc': '商品简介', // 商品简介
+      'product_img_url': [], // 商品主图
+      'product_rotation_img_list': [], // 商品轮播图
+      'product_detail_img_list': [], // 详情图
+      'product_title': '', // 商品标题
+      'product_desc': '', // 商品简介
       'product_category_id': {
         'category_name': '',
-        'id': '1'
+        'id': ''
       }, // 分类ID
       'product_brand_id': {
         'brand_name': '',
-        'id': '1'
+        'id': ''
       }, // 品牌ID
-      'product_spec': '10个没件', // 规格
-      'product_unit': '', // 单位
-      'product_all_price': '100', // 批发价
-      'product_price': '88', // 零售价
-      'product_count': '100', // 库存
+      'product_spec': '', // 规格
+      'product_unit': '', // 单位
+      'product_all_price': '', // 批发价
+      'product_price': '', // 零售价
+      'product_count': '', // 库存
       'product_sale_at': '预售' // 预售时间(0代表预售)
     },
     product_img_url_max: 1,
@@ -99,7 +72,7 @@ Page({
       this.setData({
         'form.id': id
       }, () => {
-
+        this.fetchProductDetail()
       })
     }
   },
@@ -131,27 +104,7 @@ Page({
   onUnload() {
 
   },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
-  },
+  // 获取商品分类
   async fetchProductCategoryList() {
     try {
       const { status, data, msg } = await getProductCategoryList()
@@ -172,23 +125,134 @@ Page({
       }
     } catch (err) {}
   },
+  // 获取品牌
   async fetchProductBrandList() {
-    const { status, data, msg } = await getProductBrandList()
-    if (status) {
-      this.setData({
-        brandList: data.map(item => {
-          return {
-            ...item,
-            text: item.brand_name
+    try {
+      const { status, data, msg } = await getProductBrandList()
+      if (status) {
+        this.setData({
+          brandList: data.map(item => {
+            return {
+              ...item,
+              text: item.brand_name
+            }
+          })
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
+  },
+  async fetchProductDetail() {
+    let temp = {}
+    try {
+      // const { status, data, msg } = await getProductDetail(this.data.form.id)
+      const { status, data, msg } = {
+        'status': true,
+        'data': {
+          'id': 2, //商品ID
+          'shop_id': 1,
+          'product_img_url': 'sdsd', //商品主图
+          'product_rotation_img_list': '["sdsjdsd"]', //商品轮播图(json数组)
+          'product_detail_img_list': '["sdsndish"]', //商品详情图(json数据)
+          'product_title': '测试商品', //商品名称
+          'product_category_id': null, //商品分类ID
+          'product_category_name': '', //商品分类
+          'product_brand_id': 1, //商品品牌ID
+          'product_brand_name': '大众', //商品品牌
+          'product_spec': 'xl', //商品规格
+          'product_unit': '个', //单位
+          'product_code': '1-1-1663145154', //货号
+          'product_all_price': 10000, //批发价
+          'product_price': 9000, //单价
+          'product_count': 1000, //库存
+          'product_sale_at': 0, //预售(0代表非预售  时间戳代表预售时间)
+          'product_status': 1, //状态(0下架1上架)
+          'created_at': '2022-09-14 16:45:54',
+          'updated_at': '2022-09-14 16:45:54',
+          'product_market_price': 0, //市场价
+          'product_is_select': 0, //是否精选(0否1是)
+          'product_desc': ''
+        }, //返回数据
+        'code': 200, //授权码
+        'msg': '', //返回文字描述
+        'url': ''
+      }
+      if (status) {
+        for (let key in data) {
+          let value = data[key]
+          if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
+
+            if (key === 'product_img_url' || key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
+              value = value.map(item => {
+                return {
+                  'formkey': key,
+                  'url': item
+                }
+              })
+            }
+
+            if (key === 'product_category_id') {
+              const category = this.data.categoryList.filter(item => item.id === value)
+              if (category.length > 0) {
+                value = category[0]
+                temp['categoryInDefaultIndex'] = this.data.categoryList.findIndex(item => item.id === value)
+              } else {
+                value = {
+                  'category_name': '',
+                  'id': ''
+                }
+              }
+            }
+            if (key === 'product_brand_id') {
+              const brand = this.data.brandList.filter(item => item.id === value)
+              if (brand.length > 0) {
+                value = brand[0]
+                temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value)
+              } else {
+                value = {
+                  'brand_name': '',
+                  'id': ''
+                }
+              }
+            }
+
+            if (key === 'product_unit') {
+              const unit = this.data.unitInColumns.filter(item => item === value)
+              if (unit.length > 0) {
+                temp['unitInDefaultIndex'] = this.data.unitInColumns.findIndex(item => item === value)
+              }
+            }
+
+            if (key === 'product_all_price' || key === 'product_price') {
+              value = fen2Yuan(value)
+            }
+
+            if (key === 'product_sale_at') {
+              if (value === 0) {
+                temp['saleAtType'] = '0'
+              } else {
+                temp['currentDate'] = value
+              }
+            }
+
+            if (this.data.form.hasOwnProperty(key)) {
+              temp[`form.${key}`] = value
+            }
           }
+        }
+
+        this.setData(temp)
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
         })
-      })
-    } else {
-      wx.showToast({
-        title: msg,
-        icon: 'none'
-      })
-    }
+      }
+    } catch (err) {}
   },
   ...uploadJS,
   uploadCallBack(res) {
@@ -206,11 +270,12 @@ Page({
 
     switch (formkey) {
       case 'product_img_url':
-        tempForm[`form.${formkey}`] = temp
+        tempForm[`form.${formkey}[0]`] = temp[0]
         break
       case 'product_rotation_img_list':
       case 'product_detail_img_list':
-        tempForm[`form.${formkey}`] = this.data.form[formkey].concat(...temp)
+        const formkeyData = this.data.form[formkey]
+        tempForm[`form.${formkey}`] = formkeyData.concat(...temp)
         break
       default:
     }
@@ -387,7 +452,6 @@ Page({
       product_sale_at: product_sale_at === '预售' ? 0 : this.data.currentDate
     }
   },
-  setForm() {},
   verify() {
     let errorList = []
     const {
@@ -407,10 +471,10 @@ Page({
     if (!product_img_url) {
       errorList.push('请上传商品主图')
     }
-    if (!product_rotation_img_list.length) {
+    if (!product_rotation_img_list) {
       errorList.push('请上传商品轮播图')
     }
-    if (!product_detail_img_list.length) {
+    if (!product_detail_img_list) {
       errorList.push('请上传商品详情图')
     }
     if (!product_title) {
@@ -463,6 +527,16 @@ Page({
         res = await postModifyProduct({ ...temp, id: this.data.form.id })
       }
       const { status, data, msg } = res
+      if (status) {
+        wx.redirectTo({
+          url: '/pages/businessGoodsManage/businessGoodsManage'
+        })
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
     } catch (err) {}
   }
 })

+ 3 - 2
htmldev/wxMini/pages/mine/mine.wxml

@@ -64,10 +64,11 @@
         </view>
       </view>
     </view>
-    <!-- todo -->
     <view
       class="list"
-      wx:if="{{false}}">
+      wx:if="{{false}}"
+      data-page="businessApply"
+      bind:tap="jump">
       <image class="label" src="../../image/mine/user.png"></image>
       <text class="value">申请入住(成为农户)</text>
     </view>