Browse Source

始宁农业小程序:新增全部产品

panyong 2 years ago
parent
commit
8acd768c1c

+ 16 - 0
htmldev/shiningWxMini/pages/businessGoodsManage/api/index.js

@@ -27,3 +27,19 @@ export const postProductDelete = (id) => request({
   },
   showLoading: true
 })
+
+/**
+ * 商品上下架
+ * @param id
+ * @param productStatus
+ * @returns {Promise<*>}
+ */
+export const postProductUp = (id, productStatus) => request({
+  url: '/api/shop/product/up',
+  method: 'POST',
+  data: {
+    id,
+    'product_status': productStatus // 状态(0下架1上架)
+  },
+  showLoading: true
+})

+ 56 - 3
htmldev/shiningWxMini/pages/businessGoodsManage/businessGoodsManage.js

@@ -1,4 +1,4 @@
-const { getProductList, postProductDelete } = require('./api/index')
+const { getProductList, postProductDelete, postProductUp } = require('./api/index')
 
 Page({
 
@@ -24,14 +24,15 @@ Page({
         value: '3'
       }
     ],
-    active: '0', // 顶部菜单栏默认选中,商品状态:(0全部1待支付2待出发3进行中4已结束)
+    active: '0',
     current: 0, // 轮播图默认选中
     pageSize: 20,
     originScrollViewData: [],
     booDeleteOrder: false,
     booLock: false,
     refresherThreshold: 60, // 自定义下拉刷新阈值
-    itemData: {} // 当前选中的商品
+    itemData: {}, // 当前选中的商品
+    booProductUp: false
   },
   // 下拉刷新加锁
   freshing: false,
@@ -230,6 +231,58 @@ Page({
       itemData: {}
     })
   },
+  handleProductUp(e) {
+    const { item } = e.currentTarget.dataset
+
+    this.setData({
+      booProductUp: true,
+      itemData: item
+    })
+  },
+  hideProductUp() {
+    this.setData({
+      booProductUp: false,
+      itemData: {}
+    })
+  },
+  async confirmProductUp() {
+    const { id, product_status } = this.data.itemData
+
+    this.setData({
+      booLock: true
+    })
+    try {
+      const { status, msg } = await postProductUp(id, product_status === 0 ? 1 : 0)
+      let _msg = ''
+      if (status) {
+        _msg = '商品' + (product_status === 0 ? '上架' : '下架') + '成功'
+        // 更新全部:去除各个列表中有相同id的
+        const originScrollViewData = this.data.originScrollViewData
+        for (let i = 0; i < originScrollViewData.length; i++) {
+          const _list = originScrollViewData[i].list
+          const _delIndex = _list.findIndex(item => item.id === id)
+          if (_delIndex > -1) {
+            _list.splice(_delIndex, 1, { ...this.data.itemData, product_status: product_status === 0 ? 1 : 0 })
+            this.setData({
+              ['originScrollViewData[' + i + '].list']: _list
+            })
+          }
+        }
+
+        this.hideProductUp()
+      } else {
+        _msg = msg
+      }
+      wx.showToast({
+        title: _msg,
+        icon: 'none'
+      })
+    } catch (err) {}
+
+    this.setData({
+      booLock: false
+    })
+  },
   async confirmDeleteOrder() {
     const { id } = this.data.itemData
 

+ 28 - 0
htmldev/shiningWxMini/pages/businessGoodsManage/businessGoodsManage.wxml

@@ -71,6 +71,12 @@
               data-item="{{order}}"
               catch:tap="showDeleteOrder">删除产品
             </button>
+            <button
+              type="default"
+              data-item="{{order}}"
+              catch:tap="handleProductUp"
+              wx:if="{{order.product_check_status === 1 && (order.product_status === 0 || order.product_status === 1)}}">{{order.product_status === 0 ? '上架' : '下架'}}
+            </button>
             <button
               type="default"
               style="color: rgba(107, 133, 89, 1);"
@@ -123,5 +129,27 @@
             bind:tap="confirmDeleteOrder">确定
     </button>
   </view>
+</van-popup>
+  <!-- 弹窗:商品上架下架二次确认 -->
+<van-popup
+  custom-class="customer-van-model"
+  show="{{ booProductUp }}"
+  bind:close="hideProductUp">
+  <view class="customer-van-model_body">
+    <view class="content">确认{{itemData.product_status === 0 ? '上架' : '下架'}}上架吗?</view>
+  </view>
+  <view class="customer-van-model_footer">
+    <button class="customer-van-model_cancel"
+            hover-class="none"
+            type="default"
+            bind:tap="hideProductUp">取消
+    </button>
+    <button class="customer-van-model_confirm"
+            hover-class="none"
+            type="primary"
+            disabled="{{booLock}}"
+            bind:tap="confirmProductUp">确定
+    </button>
+  </view>
 </van-popup>
 <wxs src="../../components/wxs/index.wxs" module="tools"></wxs>