Ver código fonte

产品新增或修改

zhaoxiaohai 3 anos atrás
pai
commit
cdd451d424
1 arquivos alterados com 16 adições e 55 exclusões
  1. 16 55
      pages/productManagement/change.js

+ 16 - 55
pages/productManagement/change.js

@@ -20,7 +20,6 @@ Page({
         showSaleprod: "", //标签显示
         tagents_productid: 0, //识别产品ID
         checked: false, //开关控件
-        newAdd: false, //新增标识,新增时true,在保存后会更改为false 如果退出页面仍为true 改产品会被删除
         errTips: {
             fprodname: false,
             fprodnum: false,
@@ -74,12 +73,6 @@ Page({
                 tagents_productid: data.tagents_productid, //识别产品ID
                 showSaleprod, // 显示标签
             });
-        } else {
-            //新增产品,先新建一个产品,未保存退出页面会删除
-            this.submit();
-            this.setData({
-                newAdd: true
-            })
         }
     },
 
@@ -140,49 +133,30 @@ Page({
     /* 提交 */
     submit() {
         if (!this.formVerify()) return;
-        let content = {};
         //请求参数
-        if (this.data.tagents_productid != 0) {
-            content = {
+        _Http.basic({
+            "accesstoken": wx.getStorageSync('userData').token,
+            "classname": "customer.products.products",
+            "method": "insertOrModifyProducts",
+            "content": {
                 "tagents_productid": this.data.tagents_productid,
                 "fprodnum": this.data.fprodnum,
                 "fprodname": this.data.fprodname,
                 "fintroduction": this.data.fintroduction,
                 "ftag": this.data.ftag,
             }
-        } else {
-            content = {
-                "tagents_productid": 0
-            }
-        };
-        _Http.basic({
-            "accesstoken": wx.getStorageSync('userData').token,
-            "classname": "customer.products.products",
-            "method": "insertOrModifyProducts",
-            "content": content
         }).then(res => {
             console.log(res)
-            if (res.msg == "成功") {
-                if (this.data.tagents_productid != 0) {
-                    //非新增项目
-                    wx.showToast({
-                        title: '保存成功',
-                    })
-                    this.setData({
-                        newAdd: false
-                    })
-                    setTimeout(() => {
-                        wx.navigateBack({
-                            delta: 1,
-                        })
-                    }, 500)
-                } else {
-                    //新增未保存项目
-                    this.setData({
-                        tagents_productid: res.data[0].tagents_productid
-                    })
-                }
-            }
+            if (res.msg != "成功") return;
+            //非新增项目
+            wx.showToast({
+                title: '保存成功',
+            })
+            setTimeout(() => {
+                wx.navigateBack({
+                    delta: 1,
+                })
+            }, 500)
         })
     },
     /* 获取焦点 */
@@ -244,20 +218,7 @@ Page({
     /**
      * 生命周期函数--监听页面卸载
      */
-    onUnload: function () {
-        if (this.data.newAdd) {
-            _Http.basic({
-                "accesstoken": wx.getStorageSync('userData').token,
-                "classname": "customer.products.products",
-                "method": "deleteProducts",
-                "content": {
-                    "tagents_productid": this.data.tagents_productid
-                }
-            }).then(res => {
-                console.log(res)
-            })
-        }
-    },
+    onUnload: function () {},
 
     /**
      * 页面相关事件处理函数--监听用户下拉动作