Przeglądaj źródła

dk-stepper自定义组件提交

liuyao 1 rok temu
rodzic
commit
c4938cdfbc

+ 2 - 0
components/dkbase/dk-form/dk-form.js

@@ -651,10 +651,12 @@ Component({
      * @date   : 2024/1/26 11:46
      */
     onChange(e) {
+      console.log('onChange', e);
       let key = e.currentTarget.dataset.key
       let item = e.currentTarget.dataset.item
       let checkFlag = e.currentTarget.dataset.value
       let form = this.data.form
+
       if (item.readonly) {
         return
       }

+ 5 - 1
components/dkbase/dk-popup/dk-popup.wxml

@@ -69,9 +69,13 @@
       <!--数量step-->  
       <van-cell wx:if="{{item.type=='step'}}" border="{{ false }}" title-class="cell_title"  title="{{item.title?item.title:'数量'}}" required="{{item.required?true:false }}">
         <van-stepper wx:if="{{item.code == 'box'}}"input-width="50px" value="{{form[item.code]}}" integer="{{true}}"  data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" min="{{form[item.code + '_min']?form[item.code + '_min']:( item.min?item.min:-9999999999)}}" max="{{form[item.code + '_max']?form[item.code + '_max']:( item.max?item.max:999999999)}}" bind:change="changeStep" disabled="{{!!readonly}}" />
-        <dk-stepper wx:elif="{{item.code == 'itemQty'}}" value="{{form[item.code]}}" input-width="50px" integer="{{ form[stepperDecimal]==0}}"decimal-length="{{ form[stepperDecimal] }}" data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" min="{{form[item.code + '_min']?form[item.code + '_min']:( item.min?item.min:-99999999999)}}" max="{{form[item.code + '_max']?form[item.code + '_max']:( item.max?item.max:999999999)}}" bind:change="changeStep" disabled="{{!!readonly}}" />
+        <dk-stepper wx:elif="{{item.code == 'itemQty'}}" value="{{form[item.code]}}" input-width="60px" integer="{{ form[stepperDecimal]==0}}"decimal-length="{{ form[stepperDecimal] }}" data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" min="{{form[item.code + '_min']?form[item.code + '_min']:( item.min?item.min:-99999999999)}}" max="{{form[item.code + '_max']?form[item.code + '_max']:( item.max?item.max:999999999)}}" bind:change="changeStep" disabled="{{!!readonly}}" />
         <van-stepper wx:else value="{{form[item.code]}}" input-width="50px" integer="{{ form[stepperDecimal]==0}}"decimal-length="{{ form[stepperDecimal] }}" data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" min="{{form[item.code + '_min']?form[item.code + '_min']:( item.min?item.min:-99999999999)}}" max="{{form[item.code + '_max']?form[item.code + '_max']:( item.max?item.max:999999999)}}" bind:change="changeStep" disabled="{{!!readonly}}"/>
       </van-cell>
+      <!--显示负数step-->  
+      <van-cell wx:if="{{item.type=='negativeStep'}}" border="{{ false }}" title-class="cell_title"  title="{{item.title?item.title:'数量'}}" required="{{item.required?true:false }}">
+        <dk-stepper value="{{form[item.code]}}" input-width="60px" integer="{{ form[stepperDecimal]==0}}"decimal-length="{{ form[stepperDecimal] }}" data-index="{{index}}" data-item="{{item}}" data-key="{{item.code}}" min="{{form[item.code + '_min']?form[item.code + '_min']:( item.min?item.min:-99999999999)}}" max="{{form[item.code + '_max']?form[item.code + '_max']:( item.max?item.max:999999999)}}" bind:change="changeStep" disabled="{{!!readonly}}" />
+      </van-cell>
       <!--数字类-->
       <dk-number-input wx:if="{{item.type=='number'}}" sign="{{(item.sign || item.sign == '')?item.sign:'¥'}}" digits="{{(item.digits || item.digits == 0)?item.digits:2}}" fontSize="14" left="30rpx" data-key="{{item.code}}" data-item="{{item}}" max="{{(item.max || item.max == '')?item.max:10000000}}" min="{{(item.min || item.min == '')?item.min:-10000000}}"  data-index="{{index}}" center="{{'right'}}" readonly="{{!!readonly || !!item.readonly}}" 
       placeholder="{{wxmlUtil.setPlaceholder($t,item.title?item.title:item.code)}}" errorMessage="{{item.errMsg}}" contentRight="{{true}}" titleValue="{{item.title?item.title:$t[item.code]}}" inputColor="#FF7B1A" titleFontWeight="normal" required="{{item.required?true:false }}" requiredLeft="15rpx" titleColor="#95A8CB" inputValue="{{form[item.code]}}" titleWidth = "174px"bind:triggerBindValue="changeNumberField" bind:triggerBindBlur="blurNumberField"></dk-number-input>

+ 23 - 9
components/dkbase/dk-stepper/dk-stepper.js

@@ -88,7 +88,8 @@ Component({
       // 组件内容显示
       inputValue: '-' + '1',
       shieldWidth: '',
-      shieldRight: ''
+      shieldRight: '',
+      inputTimer: null
     },
 
     /**
@@ -100,8 +101,12 @@ Component({
        * @author 刘尧
        */
       changeStep(e){
+        console.log('e', e);
+        if(Number(e.detail) < 0){
+          e.detail = Number(e.detail) * -1
+        }
         this.setData({
-          inputValue: '-' + e.detail,
+          inputValue: e.detail * -1,
           value: e.detail
         })
         // 触发自定义事件  
@@ -155,10 +160,19 @@ Component({
        * @author : 刘尧
        * @date : 2024/6/3 08:44
        *  */
-      onBlur(e){
-        this.setData({
-          checkFocus:false
-        })
+      onBlur(e){        
+        // 清除之前的定时器  
+        if (this.data.inputTimer) {  
+          clearTimeout(this.data.inputTimer);  
+        }  
+        // 设置新的定时器,等待一段时间来判断输入是否停止  
+        this.setData({  
+          inputTimer: setTimeout(() => {  
+            this.setData({  
+              checkFocus: false  
+            });  
+          }, 500)
+        });  
       },
       /** 
        * 步进器获取焦点
@@ -177,9 +191,9 @@ Component({
          * 数据监听当组件被赋予value值或最小值时执行
          * @author 刘尧
          */
-        this.setData({
-          inputValue: '-' + value || min
-        })
+          this.setData({
+            inputValue: value * -1 || min
+          })
       },
       'inputWidth, buttonSize': function(inputWidth, buttonSize){
         let deviceWidth = wx.getSystemInfoSync().windowWidth; //获取设备屏幕宽度

+ 3 - 3
components/dkbase/dk-stepper/dk-stepper.wxml

@@ -2,11 +2,11 @@
   <view class="com-content">
     <!-- 将文字显示上方获取焦点相关事件处理遮罩文字显隐 -->
     <view class="number-view" style="width: {{inputWidth}};margin-right:{{buttonSize}};">
-      <view class="number-content" style="width: {{inputWidth ? inputWidth: ''}};" bindtap="inputOnFocus" wx:if="{{ !checkFocus && shieldShow }}">{{ inputValue }}</view>
+      <input disabled class="number-content" style="width: {{inputWidth ? inputWidth: ''}};" bindtap="inputOnFocus" wx:if="{{ !checkFocus && shieldShow }}" value="{{ inputValue }}"></input>
     </view>
     <!-- 原始步进器组件 -->
-    <van-stepper bind:blur="onBlur"
+    <van-stepper
     value="{{value}}"
-    input-width="{{inputWidth}}" async-change="{{asyncChange}}" button-size="{{buttonSize}}" show-plus="{{showPlus}}" min="{{min}}" max="{{max}}" bind:focus="onFocus" step="{{step}}" disabled="{{disabled}}" disableInput="{{disableInput}}" integer="{{integer}}" show-minus="{{showMinus}}" decimal-length="{{decimalLength}}" theme="{{theme}}" disable-plus="{{disablePlus}}" disable-minus="{{disableMinus}}" long-press="{{longPress}}" always-embed="{{alwaysEmbed}}" bind:plus="bindPlus" bind:minus="bindMinus" bind:change="changeStep"></van-stepper>
+    input-width="{{inputWidth}}" async-change="{{asyncChange}}" button-size="{{buttonSize}}" show-plus="{{showPlus}}" min="{{min}}" max="{{max}}" step="{{step}}" disabled="{{disabled}}" disableInput="{{disableInput}}" integer="{{integer}}" show-minus="{{showMinus}}" decimal-length="{{decimalLength}}" theme="{{theme}}" disable-plus="{{disablePlus}}" disable-minus="{{disableMinus}}" long-press="{{longPress}}" always-embed="{{alwaysEmbed}}" bind:plus="bindPlus" bind:minus="bindMinus" bind:focus="onFocus" bind:blur="onBlur" bind:change="changeStep"></van-stepper>
   </view>
 </view>

+ 1 - 1
package-base-select/pages/select-goods/select-goods.js

@@ -40,7 +40,7 @@ Page({
     active: 0,
     popContent: [{
       code: 'itemQty',
-      type: 'step',
+      type: 'negativeStep',
       title: '数量',
       required: true
     },

+ 1 - 1
package-sales/pages/order-return/add/add.js

@@ -158,7 +158,7 @@ Page({
     ],
     popContent: [{
         code: 'outingQty',
-        type: 'step',
+        type: 'negativeStep',
         title: mixins.$t("count"),
         required: true
       },