Răsfoiți Sursa

新增商品档案时 关闭开关删除对应表单数据

liuyao 1 an în urmă
părinte
comite
a6b99e81cd

+ 1 - 3
components/dkbase/dk-form/dk-form.js

@@ -651,13 +651,11 @@ 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) {
+      if (item && item.readonly) {
         return
       }
       form[key] = !checkFlag

+ 1 - 1
components/dkbase/dk-form/dk-form.wxml

@@ -28,7 +28,7 @@
       <!--开关-->
       <van-field wx:if="{{item.type=='switch'}}" input-width="200rpx" input-class="dk-cell-value-class" label-class="nomal-label" input-align="right" label="{{item.title?item.title:$t[item.code]}}" autosize border="{{ false }}" readonly="{{true}}" errorMessage="{{item.errMsg}}">
         <van-icon wx:if="{{item.tip}}" slot="label-icon" name="question-o" data-item="{{item}}" catchtap="showTip" />
-        <view slot="inputbefor" style="width:100%;text-align: left;padding-top: 5rpx;" bindtap="onChange">
+        <view slot="inputbefor" style="width:100%;text-align: left;padding-top: 5rpx;">
           <van-switch size="20px" checked="{{ form[item.code]}}" bind:change="onChange" active-color="#3E69F6" data-item="{{item}}" data-index="{{index}}" data-card="{{card}}" data-value="{{form[item.code]}}" data-key="{{item.code}}"disabled="{{item.disabled}}" />
         </view>
       </van-field> 

+ 28 - 0
package-basic-data/pages/product-file/add/add.js

@@ -292,6 +292,7 @@ Page({
    */
   onSwitchChange(e) {
     console.log("Switch", e);
+
     let code = e.detail.code
     let checkFlag = !e.detail.checkFlag
     let contentObj = this.data.contentObj
@@ -345,6 +346,17 @@ Page({
           }
         ]
       } else {
+        let formDataJson = JSON.parse(this.data.formData)
+        if (formDataJson) {  
+          ['subUnitName', 'calculationFormula', 'packBox'].forEach(key => {  
+            if (formDataJson.hasOwnProperty(key)) {  
+              delete formDataJson[key];
+            } 
+          });  
+        }
+        this.setData({
+          formData: JSON.stringify(formDataJson)
+        })
         contentObj.unit = [{ //基本单位
           code: 'unitId',
           name: 'unitName',
@@ -452,6 +464,22 @@ Page({
         }
 
       } else {
+        /**
+         * 关闭初期按钮后删除对应的初期数据
+         * @author 刘尧
+         * @data 2024.06.04
+         */
+        let formData = JSON.parse(this.data.formData)
+        if (formData) {  
+          ['packageBox', 'priceInto', 'intoQty', 'nonStdCode', 'whName', 'whId'].forEach(key => {  
+            if (formData.hasOwnProperty(key)) {  
+              delete formData[key];
+            } 
+          });  
+        }
+        this.setData({
+          formData: JSON.stringify(formData)
+        })
         contentObj.warehouse = [{ //期初库存标识
           type: 'switch',
           title: mixins.$t("openingInv"),