Browse Source

始宁农业小程序:商品新增、编辑发售时间选择

panyong 2 years ago
parent
commit
916017cb52

+ 24 - 23
htmldev/shiningWxMini/pages/businessGoodsEdit/businessGoodsEdit.js

@@ -1,9 +1,10 @@
 const uploadJS = require('../../mixin/upload.js')
 const { postAddProduct, postModifyProduct, getProductDetail } = require('./api/index')
 const { getProductCategoryList, getProductBrandList } = require('../../api/common')
-const { formatTs, yuan2Fen, fen2Yuan } = require('../../utils/util')
+const { formatTs, yuan2Fen, fen2Yuan, getTs } = require('../../utils/util')
 const minDate = new Date().getTime()
 const objMinDate = formatTs(minDate)
+const app = getApp()
 
 Page({
 
@@ -11,14 +12,6 @@ Page({
    * 页面的初始数据
    */
   data: {
-    // * 商品品牌:下拉选择
-    // * 单位:下拉选择
-    // * 商品货号:系统自动生成(只读)
-    // * 批发价
-    // * 零售价
-    // * 库存
-    // * 状态:现售产品有上架、下架状态
-    // * 发售时间:不能低于当前创建时间
     form: {
       'product_img_url': [], // 商品主图
       'product_rotation_img_list': [], // 商品轮播图
@@ -38,8 +31,7 @@ Page({
       'product_all_price': '', // 批发价
       'product_price': '', // 零售价
       'product_count': '', // 库存
-      'product_status': 0, // 状态
-      'product_sale_at': '预售' // 预售时间(0代表预售)
+      'product_sale_at': '现货' // 预售时间(0代表预售)
     },
     product_img_url_max: 1,
     product_rotation_img_list_max: 5,
@@ -52,7 +44,7 @@ Page({
     brandList: [],
     booUnit: false,
     unitInDefaultIndex: 0,
-    unitInColumns: ['件', '只', '个'],
+    unitInColumns: [],
     booSaleAtType: false,
     saleAtType: '0',
     booSaleAt: false,
@@ -94,6 +86,9 @@ Page({
         title: '产品新增'
       })
     }
+    app.fetchSystemConfigCallback = () => {
+      this.setUnitInColumns()
+    }
   },
 
   /**
@@ -107,7 +102,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    this.setUnitInColumns()
   },
 
   /**
@@ -219,13 +214,13 @@ Page({
 
             if (key === 'product_sale_at') {
               if (value === 0) {
-                value = '预售'
+                value = '现货'
               } else {
-                const { YYYY, MM, DD, HH, mm } = formatTs(value * 1000)
+                const { YYYY, MM, DD} = formatTs(value * 1000)
 
                 temp['saleAtType'] = '1'
                 temp['currentDate'] = value * 1000
-                value = `${YYYY}年${MM}月${DD}日 ${HH}:${mm}`
+                value = `${YYYY}年${MM}月${DD}日`
               }
             }
 
@@ -388,7 +383,7 @@ Page({
     tempForm['booSaleAtType'] = false
 
     if (this.data.saleAtType === '0') {
-      tempForm['form.product_sale_at'] = '预售'
+      tempForm['form.product_sale_at'] = '现货'
     } else {
       tempForm['form.product_sale_at'] = ''
       tempForm['booSaleAt'] = true
@@ -411,11 +406,11 @@ Page({
     })
   },
   saleAtConfirm(event) {
-    const { YYYY, MM, DD, HH, mm } = formatTs(event.detail)
+    const { YYYY, MM, DD } = formatTs(event.detail)
 
     this.setData({
       currentDate: event.detail,
-      'form.product_sale_at': `${YYYY}年${MM}月${DD}日 ${HH}:${mm}`
+      'form.product_sale_at': `${YYYY}年${MM}月${DD}日`
     })
 
     this.saleAtHide()
@@ -434,7 +429,6 @@ Page({
       product_all_price,
       product_price,
       product_count,
-      product_status,
       product_sale_at
     } = this.data.form
 
@@ -451,8 +445,7 @@ Page({
       product_all_price: yuan2Fen(product_all_price),
       product_price: yuan2Fen(product_price),
       product_count,
-      product_status,
-      product_sale_at: product_sale_at === '预售' ? 0 : Math.round(this.data.currentDate / 1000)
+      product_sale_at: product_sale_at === '现货' ? 0 : (product_sale_at ? getTs(product_sale_at, 'YYYY年MM月DD日', 's') : '')
     }
   },
   verify() {
@@ -507,8 +500,9 @@ Page({
     if (!product_count) {
       errorList.push('请输入库存')
     }
+
     if (product_sale_at !== 0 && !product_sale_at) {
-      errorList.push('请选择售时间')
+      errorList.push('请选择售时间')
     }
 
     return errorList
@@ -543,5 +537,12 @@ Page({
         })
       }
     } catch (err) {}
+  },
+  setUnitInColumns() {
+    const { product_unit_list } = app.globalData.objSystemConfig
+
+    this.setData({
+      unitInColumns: Array.isArray(product_unit_list) && product_unit_list.length > 0 ? product_unit_list : []
+    })
   }
 })

+ 13 - 28
htmldev/shiningWxMini/pages/businessGoodsEdit/businessGoodsEdit.wxml

@@ -14,6 +14,7 @@
               max-count="{{product_img_url_max}}"
               multiple="{{false}}"
               accept="image"
+              image-fit="widthFix"
               data-formkey="product_img_url"
               bind:click-preview="uploadImg"
               bind:after-read="afterRead"
@@ -34,6 +35,7 @@
               max-count="{{product_rotation_img_list_max}}"
               multiple="{{true}}"
               accept="image"
+              image-fit="widthFix"
               data-formkey="product_rotation_img_list"
               bind:click-preview="uploadImg"
               bind:after-read="afterRead"
@@ -54,6 +56,7 @@
               max-count="{{product_detail_img_list_max}}"
               multiple="{{true}}"
               accept="image"
+              image-fit="widthFix"
               data-formkey="product_detail_img_list"
               bind:click-preview="uploadImg"
               bind:after-read="afterRead"
@@ -176,30 +179,6 @@
             bind:input="setFormValue"></input>
         </view>
       </view>
-
-      <view class="form-item" wx:if="{{productCheckStatus === 1}}">
-        <label>
-          <text>状 态</text>
-        </label>
-        <view class="value">
-          <view
-            class="select-options"
-            wx:for="{{productStatus}}"
-            wx:key="value"
-            data-formkey="product_status"
-            data-item="{{item}}"
-            bind:tap="handleRadio">
-            <image
-              hidden="{{ index === 0 ? form.product_status === 0 : form.product_status === 1}}"
-              src="../../image/common/unselected.png"></image>
-            <image
-              hidden="{{index === 0 ? form.product_status !== 0 : form.product_status !== 1}}"
-              src="../../image/common/selected.png"></image>
-            <text>{{item.name}}</text>
-          </view>
-        </view>
-      </view>
-
       <view
         class="form-item border-bottom-2"
         bind:tap="saleAtTypeShow">
@@ -207,7 +186,13 @@
           <text>发售时间</text>
         </label>
         <view class="value">
-          <view class="{{!!form.product_sale_at ? '' : 'placeholder'}}">{{form.product_sale_at || '请选择发售时间'}}
+          <view
+            class="{{!!form.product_sale_at ? '' : 'placeholder'}}">
+            <block
+              wx:if="{{!!form.product_sale_at}}">
+              {{form.product_sale_at === '现货' ? form.product_sale_at : '预售时间:' + form.product_sale_at}}
+            </block>
+            <block wx:else>请选择预售时间</block>
           </view>
           <image class="arrow" src="../../image/businessGoodsEdit/arrow.png"></image>
         </view>
@@ -290,7 +275,7 @@
           wx:if="{{saleAtType === '0'}}"
           src="../../image/common/selected.png"></image>
       </view>
-      <text>预售</text>
+      <text>现货</text>
       <view
         class="arrow-wrap"
         style="visibility:hidden;">
@@ -314,7 +299,7 @@
           src="../../image/common/selected.png"></image>
       </view>
       <text
-        class="placeholder">{{form.product_sale_at === '预售' || form.product_sale_at === '' ? '选择售卖时间' : form.product_sale_at}}
+        class="placeholder">{{form.product_sale_at === '现货' || form.product_sale_at === '' ? '选择预售时间' : '预售时间:' + form.product_sale_at}}
       </text>
       <view class="arrow-wrap">
         <image
@@ -334,7 +319,7 @@
   bind:click-overlay="saleAtHide">
   <van-datetime-picker
     id="picker-datetime"
-    type="datetime"
+    type="date"
     value="{{ currentDate }}"
     min-date="{{ minDate }}"
     max-date="{{ maxDate }}"

+ 21 - 1
htmldev/shiningWxMini/utils/util.js

@@ -374,6 +374,25 @@ function getDayList(startTs, duration) {
   return result.concat(getDayList(endTs + 1000, duration - 1000))
 }
 
+function getTs(val, polyfill, type = 'ts') {
+  const { ios } = platform()
+  if (!val) {
+    return 0
+  }
+  if (polyfill === 'YYYY年MM月DD日') {
+    if (ios) {
+      val = val.replace('年', '/').replace('月', '/').replace('日', '')
+    } else {
+      val = val.replace('年', '-').replace('月', '-').replace('日', '')
+    }
+    if (type === 's') {
+      return Math.round(new Date(`${val} 00:00:00`).getTime() / 1000)
+    }
+    return new Date(`${val} 00:00:00`).getTime()
+  }
+  return 0
+}
+
 module.exports = {
   platform,
   formatTime,
@@ -387,5 +406,6 @@ module.exports = {
   toHideToast,
   fen2Yuan,
   yuan2Fen,
-  getDayList
+  getDayList,
+  getTs
 }