Browse Source

新旧值公共方法

Qukatie 1 day ago
parent
commit
ef208ad07d
2 changed files with 98 additions and 7 deletions
  1. 26 7
      pages/home/store/details.vue
  2. 72 0
      utils/contrastData.js

+ 26 - 7
pages/home/store/details.vue

@@ -266,10 +266,10 @@
 		<view v-if="form.enableOrNot!=1" class="nav-bottom-height">
 		</view>
 		<view v-if="form.enableOrNot!=1&&!popupShow" class="goods-nav-bottom">
-			<uni-goods-nav v-if="form.checkStatus=='录入'||form.checkStatus=='审核驳回'" :fill="true" :options="[]" :buttonGroup="buttonGroup"
-				@buttonClick="buttonClick" />
-			<uni-goods-nav v-if="!(form.checkStatus=='录入'||form.checkStatus=='审核驳回')" :fill="true" :options="[]" :buttonGroup="buttonGroup2"
-				@buttonClick="buttonClick2" />
+			<uni-goods-nav v-if="form.checkStatus=='录入'||form.checkStatus=='审核驳回'" :fill="true" :options="[]"
+				:buttonGroup="buttonGroup" @buttonClick="buttonClick" />
+			<uni-goods-nav v-if="!(form.checkStatus=='录入'||form.checkStatus=='审核驳回')" :fill="true" :options="[]"
+				:buttonGroup="buttonGroup2" @buttonClick="buttonClick2" />
 		</view>
 	</view>
 </template>
@@ -291,10 +291,13 @@
 		storageList,
 		brandDesc
 	} from '@/api/home/store.js'
+	import {
+		contrastObj
+	} from '@/utils/contrastData.js'
 	export default {
 		data() {
 			return {
-				popupShow:false,
+				popupShow: false,
 				buttonGroup: [{
 						text: '通过',
 						backgroundColor: '#18bc37',
@@ -333,6 +336,21 @@
 					corpsFilesList: [],
 					businessLicense: {}
 				},
+				oldForm: {
+					corpsTypeId: null,
+					corpsTypeName: null,
+					storeAttributes: null,
+					chainAttribute: null,
+					signingLevel: null,
+					dimension: null,
+					longitude: null,
+					address: null,
+					detailedAddress: null,
+					label: [],
+					brandName: [],
+					corpsFilesList: [],
+					businessLicense: {}
+				},
 				imageStyles: {
 					width: 46,
 					height: 46
@@ -386,9 +404,9 @@
 			uni.$off();
 		},
 		methods: {
-			popupChange(e){
+			popupChange(e) {
 				console.log(e)
-				this.popupShow=e.show
+				this.popupShow = e.show
 			},
 			buttonClick(e) {
 				if (e.index == 0) {
@@ -770,6 +788,7 @@
 						res.data.label = res.data.label ? res.data.label.split(",") : []
 						res.data.brandName = res.data.brandName ? res.data.brandName.split(",") : []
 						this.form = res.data
+						this.oldForm = res.data
 					})
 					.finally(() => {
 						uni.hideLoading()

+ 72 - 0
utils/contrastData.js

@@ -0,0 +1,72 @@
+//比较对象的值
+export function contrastObj(newval, oldval) {
+  let reg = /^[A-Za-z]+$/;
+  for (let key in newval) {
+    if(typeof newval[key]=='string'){
+      if (reg.test(key) && !(newval[key] instanceof Array) && (newval[key] != oldval[key] && (newval[key] || oldval[key]))) {
+        return true
+      }
+    }
+  }
+  return false
+}
+
+//比较数组的值(有序)
+export function contrastList(newlist, oldlist) {
+  if (newlist.length != oldlist.length) {
+    return true
+  }
+  let reg = /^[A-Za-z]+$/;
+  for (var i = 0; i < newlist.length; i++) {
+    for (let newitem in newlist[i]) {
+      for (let olditem in oldlist[i]) {
+        if (!reg.test(newitem)) {
+          delete newlist[i].newitem
+        }
+        if (!reg.test(oldlist[i])) {
+          delete oldlist[i].olditem
+        }
+        if (newitem == olditem) {
+          if (!(newlist[i][newitem] instanceof Array)) {
+            if (newlist[i][newitem] != oldlist[i][olditem]) {
+              console.log(newitem, i, newlist[i][newitem], oldlist[i][olditem])
+              return true
+            }
+          }
+        }
+      }
+    }
+  }
+  return false;
+}
+//比较数组的值(无序)
+export function contrastList2(newlist, oldlist) {
+  if (newlist.length != oldlist.length) {
+    return true
+  }
+  let reg = /^[A-Za-z]+$/;
+  for (var i = 0; i < newlist.length; i++) {
+    for (var j = 0; j < oldlist.length; j++) {
+      for (let newitem in newlist[i]) {
+        for (let olditem in oldlist[j]) {
+          if (newlist[i].id == oldlist[j].id) {
+            if (!reg.test(newitem)) {
+              delete newlist[i].newitem
+            }
+            if (!reg.test(oldlist[j])) {
+              delete oldlist[j].olditem
+            }
+            if (newitem == olditem) {
+              if (!(newlist[i][newitem] instanceof Array)) {
+                if (newlist[i][newitem] != oldlist[j][olditem]) {
+                  return true
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  return false;
+}