Browse Source

小程序:首页接口对接

panyong 2 years ago
parent
commit
934da5a5a4

+ 29 - 51
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -1,5 +1,5 @@
 const uploadJS = require('../../mixin/upload.js')
-const { postAddProduct, postModifyProduct, getProductDetail, mockData } = require('./api/index')
+const { postAddProduct, postModifyProduct, getProductDetail } = require('./api/index')
 const { getProductCategoryList, getProductBrandList } = require('../../api/common')
 const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
 const minDate = new Date().getTime()
@@ -38,8 +38,8 @@ Page({
       'product_all_price': '', // 批发价
       'product_price': '', // 零售价
       'product_count': '', // 库存
-      'product_sale_at': '预售', // 预售时间(0代表预售)
-      ...mockData
+      'product_status': 0, // 状态
+      'product_sale_at': '预售' // 预售时间(0代表预售)
     },
     product_img_url_max: 1,
     product_rotation_img_list_max: 5,
@@ -65,16 +65,23 @@ Page({
    * 生命周期函数--监听页面加载
    */
   async onLoad(options) {
-    const { id } = options
+    const { product_id } = options
 
     await this.fetchProductCategoryList()
     await this.fetchProductBrandList()
-    if (id) {
+    if (product_id) {
       this.setData({
-        'form.id': id
+        'form.id': product_id
       }, () => {
         this.fetchProductDetail()
       })
+      wx.setNavigationBarTitle({
+        title: '产品编辑'
+      })
+    } else {
+      wx.setNavigationBarTitle({
+        title: '产品新增'
+      })
     }
   },
 
@@ -150,45 +157,22 @@ Page({
   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': ''
-      }
+      const { status, data, msg } = await getProductDetail(this.data.form.id)
       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 => {
+            if (key === 'product_img_url') {
+              value = [
+                {
+                  'formkey': key,
+                  'url': value
+                }
+              ]
+            }
+            if (key === 'product_rotation_img_list' || key === 'product_detail_img_list') {
+              value = JSON.parse(value).map(item => {
                 return {
                   'formkey': key,
                   'url': item
@@ -201,11 +185,6 @@ Page({
               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') {
@@ -213,11 +192,6 @@ Page({
               if (brand.length > 0) {
                 value = brand[0]
                 temp['brandInDefaultIndex'] = this.data.brandList.findIndex(item => item.id === value)
-              } else {
-                value = {
-                  'brand_name': '',
-                  'id': ''
-                }
               }
             }
 
@@ -234,8 +208,12 @@ Page({
 
             if (key === 'product_sale_at') {
               if (value === 0) {
-                temp['saleAtType'] = '0'
+                value = '预售'
               } else {
+                const { YYYY, MM, DD, HH, mm } = formatTs(value)
+
+                value = `${YYYY}年${MM}月${DD}日 ${HH}:${mm}`
+                temp['saleAtType'] = '1'
                 temp['currentDate'] = value
               }
             }

+ 1 - 1
htmldev/wxMini/pages/businessGoodsEdit/businessGoodsEdit.wxml

@@ -191,7 +191,7 @@
       <button
         class="btn-submit"
         type="primary"
-        form-type="submit">编辑/发布
+        form-type="submit">保存
       </button>
     </form>
   </view>

+ 1 - 1
htmldev/wxMini/pages/businessGoodsManage/businessGoodsManage.js

@@ -85,7 +85,7 @@ Page({
     const { item } = e.currentTarget.dataset
 
     wx.navigateTo({
-      url: '/pages/orderDetail/orderDetail?orderId=' + item.id
+      url: '/pages/businessGoodsEdit/businessGoodsEdit?product_id=' + item.id
     })
   },
   setOriginScrollViewData() {

+ 35 - 1
htmldev/wxMini/pages/businessHome/businessHome.js

@@ -29,7 +29,9 @@ Page({
       }
     ],
     shopInfo: {},
-    products: []
+    products: [],
+    isFetchLock: false, // 接口调用加锁
+    isRefresh: false // 是否下拉刷新
   },
 
   /**
@@ -65,6 +67,18 @@ Page({
    */
   onUnload() {
 
+  },
+  onPullDownRefresh() {
+    if (this.data.isRefresh) {
+      return
+    }
+    this.setData({
+      isRefresh: true
+    })
+    this.fetchShopInfo()
+  },
+  bindCallBack() {
+    this.fetchShopInfo()
   },
   jump(e) {
     const { path, tabvalue = '' } = e.currentTarget.dataset
@@ -82,6 +96,17 @@ Page({
     })
   },
   async fetchShopInfo() {
+    const that = this
+    const isRefresh = that.data.isRefresh
+
+    if (that.data.isFetchLock) {
+      return
+    }
+
+    that.setData({
+      isFetchLock: true
+    })
+
     try {
       const { status, data, msg } = await getShopInfo()
       if (status) {
@@ -96,5 +121,14 @@ Page({
         })
       }
     } catch (err) {}
+
+    this.setData({
+      isFetchLock: false,
+      isRefresh: false
+    })
+
+    if (isRefresh) {
+      wx.stopPullDownRefresh()
+    }
   }
 })

+ 6 - 2
htmldev/wxMini/pages/businessHome/businessHome.json

@@ -1,3 +1,7 @@
 {
-  "usingComponents": {}
-}
+  "usingComponents": {},
+  "backgroundColor": "#F6F6F6",
+  "backgroundTextStyle": "dark",
+  "enablePullDownRefresh": true,
+  "onReachBottomDistance": 50
+}

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

@@ -43,7 +43,7 @@
   <view class="main">
     <view
       class="business-account"
-      wx:if="{{userInfo.shop_status === 0}}">
+      wx:if="{{userInfo.shop_status === 1}}">
       <image src="../../image/mine/bg.png"></image>
       <view>
         <view class="describe">已有商家账号</view>
@@ -66,7 +66,7 @@
     </view>
     <view
       class="list"
-      wx:if="{{userInfo.shop_status !== 0}}"
+      wx:if="{{userInfo.shop_status !== 1}}"
       data-page="businessApply"
       bind:tap="jump">
       <image class="label" src="../../image/mine/user.png"></image>