Jelajahi Sumber

花卉宝-订单列表数据bug处理

ouyang 1 hari lalu
induk
melakukan
7763002f4c

+ 67 - 0
mallApp/src/pages/home/order.vue

@@ -125,7 +125,17 @@ export default {
       this.applyPageQuery(tabQuery);
       queryUpdated = true;
     }
+
+    // 未带店铺筛选参数时(底栏点「订单」、从 recent 回来等)恢复全部店铺;
+    // 从订单详情返回(refreshPage=1)保留当前筛选。
+    const hasShopFilterQuery = this.hasShopFilterInQuery(tabQuery);
+    const shouldResetStoreFilter =
+      !hasShopFilterQuery && Number(this.refreshPage) !== 1;
+
     if (queryUpdated) {
+      if (shouldResetStoreFilter) {
+        this.resetStoreFilter({ reload: false });
+      }
       this.init();
       this.orderListBooted = true;
       return;
@@ -137,8 +147,16 @@ export default {
     }
     // 首次 onLoad 时可能尚未登录而跳过 init;登录后回到本 Tab 补初始化
     if (!this.orderListBooted) {
+      if (shouldResetStoreFilter) {
+        this.resetStoreFilter({ reload: false });
+      }
       this.init();
       this.orderListBooted = true;
+      return;
+    }
+    // Tab 页常驻:进过某店后再回总订单,清筛选并强制重拉全部
+    if (shouldResetStoreFilter) {
+      this.resetStoreFilter({ reload: true });
     }
   },
   methods: {
@@ -152,12 +170,56 @@ export default {
         url: "/pages/login/index?needBack=1" + (account ? "&account=" + account : "")
       });
     },
+    /**
+     * switchTab / 路由是否显式指定店铺筛选(hdId 或兼容字段 id/ghsId)
+     * @param {Object} query
+     * @returns {boolean}
+     */
+    hasShopFilterInQuery(query) {
+      if (!query || typeof query !== "object") {
+        return false;
+      }
+      return Number(query.hdId || query.id || query.ghsId || 0) > 0;
+    },
+    /**
+     * 去掉 option 上残留的店铺筛选字段,避免 init 再次锁到某店
+     */
+    stripShopFilterFromOption() {
+      if (!this.option || typeof this.option !== "object") {
+        return;
+      }
+      this.$delete(this.option, "hdId");
+      this.$delete(this.option, "id");
+      this.$delete(this.option, "ghsId");
+      this.$delete(this.option, "hdName");
+      this.$delete(this.option, "name");
+    },
+    /**
+     * 恢复「全部店铺」:清页面筛选与 option 残留。
+     * @param {{ reload?: boolean }} opts reload=true 时强制重拉(已 boot 且随后不会再 init)
+     */
+    resetStoreFilter(opts) {
+      const reload = !opts || opts.reload !== false;
+      this.stripShopFilterFromOption();
+      this.hdName = "";
+      this.hdId = 0;
+      // 进店后 storage 仍有 hdId;请求层已尊重显式 hdId=0,这里刷新 UI 列表
+      if (reload && this.orderListBooted && this.$refs.orderList) {
+        this.$nextTick(() => {
+          this.$refs.orderList.pullRefresh && this.$refs.orderList.pullRefresh();
+        });
+      }
+    },
     /** 合并 switchTab / 路由 query */
     applyPageQuery(query) {
       if (!query || typeof query !== "object") {
         return;
       }
       this.option = Object.assign({}, this.option || {}, query);
+      // 本次未指定店铺时清掉历史 option 店铺字段,防止 init 继续锁店
+      if (!this.hasShopFilterInQuery(query)) {
+        this.stripShopFilterFromOption();
+      }
       if (query.account) {
         uni.setStorageSync("account", String(query.account));
       }
@@ -182,6 +244,7 @@ export default {
     },
     syncHdNameFromList() {
       if (!this.hdId) {
+        this.hdName = "";
         return;
       }
       const matched = this.storeList.find((item) => Number(item.id) === Number(this.hdId));
@@ -222,6 +285,10 @@ export default {
       if (optionHdId > 0) {
         this.hdId = optionHdId;
         this.hdName = opt.hdName || opt.name || "";
+      } else {
+        // 无店铺参数时强制全部,避免 Tab 常驻导致上次筛选残留
+        this.hdId = 0;
+        this.hdName = "";
       }
       this.loadStoreList();
       this.$nextTick(() => {

+ 2 - 0
mallApp/src/pages/home/recent.vue

@@ -283,6 +283,8 @@ export default {
     },
   },
   onShow() {
+    // 从店铺返回总首页:清掉未消费的 switchTabQuery,避免再次点「订单」仍带上次店铺筛选
+    uni.removeStorageSync("switchTabQuery");
     // 从店铺订单 Tab 返回时恢复原生底栏,并清除店铺导航标记
     uni.removeStorageSync(SHOP_NAV_ACTIVE_KEY);
     uni.showTabBar({ animation: false });

+ 17 - 21
mallApp/src/plugins/luch-request_0.0.7/request.js

@@ -244,23 +244,15 @@ class Request {
 	}
 
 	get(url, data = {}, options = {}, config = {}) {
-		const account = uni.getStorageSync('account') || 0;
-		const hdId = uni.getStorageSync('hdId') || 0;
-		if(account != 0 && hdId != 0){
-			options.url = url + parse({...data,'account':account,'hdId':hdId})
-		} else {
-			// console.log("-----get----- data: ", data);
-			// 判断data中有无account和hdId
-			if(data.account && data.hdId){
-				options.url = url + parse({...data})
-			} else if(data.account && !data.hdId){
-				options.url = url + parse({...data, 'hdId':hdId})
-			} else if(!data.account && data.hdId){
-				options.url = url + parse({...data, 'account':account})
-			} else {
-				options.url = url + parse({...data, 'account':account, 'hdId':hdId})
-			}
-		}
+		const storageAccount = uni.getStorageSync('account') || 0
+		const storageHdId = uni.getStorageSync('hdId') || 0
+		// 调用方显式传了 account/hdId(含 hdId=0 表示跨店全部)时以调用方为准。
+		// 进店后 storage 常有门店 hdId,若一律用 storage 覆盖,订单 Tab「全部店铺」会仍被锁成单店。
+		const hasExplicitAccount = data && Object.prototype.hasOwnProperty.call(data, 'account')
+		const hasExplicitHdId = data && Object.prototype.hasOwnProperty.call(data, 'hdId')
+		const account = hasExplicitAccount ? data.account : storageAccount
+		const hdId = hasExplicitHdId ? data.hdId : storageHdId
+		options.url = url + parse({ ...data, account, hdId })
 		options.data = {}
 		options.method = 'GET'
 		return this.request(options, config)
@@ -270,14 +262,18 @@ class Request {
 	 * POST 请求:query 仅附带 account/hdId(店铺上下文),业务参数只放 body
 	 * 避免把 mobile/password 等敏感字段拼进 URL(日志、代理、Referer 可能泄漏)
 	 * @param {string} url 接口路径
-	 * @param {Object} data 业务请求体;若含 account/hdId 则优先用于 query
+	 * @param {Object} data 业务请求体;若显式含 account/hdId 则优先用于 query(含 hdId=0)
 	 * @param {Object} options uni.request 额外选项
 	 * @param {Object} config 业务控制参数 { loading?, hideError? }
 	 */
 	post(url, data = {}, options = {}, config = {}) {
-		// 优先用调用方传入的 account/hdId,否则回退本地缓存,无则 0
-		const account = (data && data.account) || uni.getStorageSync('account') || 0
-		const hdId = (data && data.hdId) || uni.getStorageSync('hdId') || 0
+		const storageAccount = uni.getStorageSync('account') || 0
+		const storageHdId = uni.getStorageSync('hdId') || 0
+		const hasExplicitAccount = data && Object.prototype.hasOwnProperty.call(data, 'account')
+		const hasExplicitHdId = data && Object.prototype.hasOwnProperty.call(data, 'hdId')
+		// 与 get 一致:显式 0 不能被 || storage 吃掉
+		const account = hasExplicitAccount ? data.account : storageAccount
+		const hdId = hasExplicitHdId ? data.hdId : storageHdId
 		options.url = url + '?account=' + account + '&hdId=' + hdId
 		options.data = data
 		options.method = 'POST'