Handy_Cao 2 年之前
父節點
當前提交
e8de707427

+ 83 - 134
GuangZuan/miniprogram/mHome/pages/search/index.ts

@@ -1,4 +1,4 @@
-import { getEnumList } from "../../../services/utils"
+import { getEnumList, saveDiamondFilters } from "../../../services/utils"
 
 Page({
 
@@ -13,39 +13,39 @@ Page({
     /// tab索引
     active: 0,
     /// 形状
-    shapes: [{ id: 1, name: '圆明亮形', isCheck: true }],
+    shapes: [{ id: 1, name: '圆明亮形', isCheck: false }],
     /// 选中形状         
-    shape: ['1'],
+    zsshapetype: [],
     /// 颜色
-    colors: [{id: 1, name: 'D', isCheck: true}],
+    colors: [{id: 1, name: 'D', isCheck: false}],
     /// 选中形状
-    color: [1],
+    zscolortype: [],
     /// 净度
-    neatness: [{ id: 1, name: 'FL', isCheck: true }],
+    neatness: [{ id: 1, name: 'FL', isCheck: false }],
     /// 选中净度
-    neatnes: 1,
+    zsclaritytype: [],
     /// 切工 
-    qiegongs: [{ id: 1, name: 'EX', isCheck: true }],
+    qiegongs: [{ id: 1, name: 'EX', isCheck: false }],
     /// 选中切工
-    qiegong: 1,
+    zscuttype: [],
     /// 对称
-    duichengs: [{ id: 1, name: 'EX', isCheck: true }],
-    duicheng: 1,
+    duichengs: [{ id: 1, name: 'EX', isCheck: false }],
+    zssymmetrytype: [],
     /// 抛光
-    paoguangs: [{ id: 1, name: 'EX', isCheck: true }],
-    paoguang: 1,
+    paoguangs: [{ id: 1, name: 'EX', isCheck: false }],
+    zspolishtype: [],
     /// 莹光
-    yingguangs: [{ id: 1, name: '无', isCheck: true }],
+    yingguangs: [{ id: 1, name: '无', isCheck: false }],
     /// 选中莹光
-    yingguang: 1,
+    zsfluorescencetype: [],
     /// 证书
-    certificates: [{ id: 1, name: 'GIA', isCheck: true }],
+    certificates: [{ id: 1, name: 'GIA', isCheck: false }],
     /// 选中证书
-    certificate: 1,
+    zscerttype: [],
     /// 币种
-    currencys: [{id: 1, name: '人民币(¥)', isCheck: true}, 
+    currencys: [{id: 1, name: '人民币(¥)', isCheck: false}, 
                 {id: 2, name: '美元($)', isCheck: false}],
-    currency: 1,
+    zscurrencytype: [],
     /// 最小重量
     minweight: '0.00',
     /// 最大重量
@@ -81,108 +81,89 @@ Page({
           if (item.id == index) { item.isCheck = !item.isCheck } 
           return item
         }) })
-        /// 赋值
-        this.setData({ shape: this.data.shapes.map(item => {
+        this.setData({ zsshapetype: this.data.shapes.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => {
           return item.id.toString()
-        }) })
+        })  })
         break;
       case 'currency': 
         this.setData({ currencys: this.data.currencys.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ currency: item.id })
-          } else {
-            item.isCheck = false
-          }
+          if (item.id == index) { item.isCheck = !item.isCheck } 
           return item
         }) })
+        this.setData({ zscurrencytype: this.data.currencys.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id.toString() }) })
         break;
       case 'color':   /// 颜色
         this.setData({ colors: this.data.colors.map(item => {
           if (item.id == index) { item.isCheck = !item.isCheck } 
           return item
         }) })
-        /// 赋值
-        this.setData({ color: this.data.colors.map(item => { return item.id }) })
+        this.setData({ zscolortype: this.data.colors.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'neatness':   /// 净度
         this.setData({ neatness: this.data.neatness.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ neatnes: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
-        }) })
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
+          })
+        })
+        this.setData({ zsclaritytype: this.data.neatness.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'qiegong':   /// 切工
         this.setData({ qiegongs: this.data.qiegongs.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ qiegong: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
         }) })
+        this.setData({ zscuttype: this.data.qiegongs.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'duicheng':   /// 对称
         this.setData({ duichengs: this.data.duichengs.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ duicheng: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
         }) })
+        this.setData({ zssymmetrytype: this.data.duichengs.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'polishing':   /// 抛光
         this.setData({ paoguangs: this.data.paoguangs.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ polishing: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
         }) })
+        this.setData({ zspolishtype: this.data.paoguangs.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'yingguang':   /// 荧光
         this.setData({ yingguangs: this.data.yingguangs.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ yingguang: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
         }) })
+        this.setData({ zsfluorescencetype: this.data.yingguangs.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id }) })
         break;
       case 'certificate':   /// 证书
         this.setData({ certificates: this.data.certificates.map(item => {
-          if (item.id == index) {
-            item.isCheck = true
-            /// 赋值
-            this.setData({ certificate: item.id })
-          } else {
-            item.isCheck = false
-          }
-          return item
+            if (item.id == index) { item.isCheck = !item.isCheck } 
+            return item
         }) })
+        this.setData({ zscerttype: this.data.certificates.filter(obj => {
+          return obj.isCheck === true
+        }).map(item => { return item.id.toString() }) })
         break;
-      case 'search':   /// 搜索
-        /// 搜索页面跳转
+      case 'search':   /// 搜索页面跳转
         this.goToSearch()
         break;
-      case 'clear': break;
+      case 'clear': break
       default: break;
     }
   },
@@ -199,16 +180,16 @@ Page({
   goToSearch() {
     /// 数据拼接
     const info = {
-      category: this.data.tabs[this.data.active].id,
-      zsshapetype: this.data.shape,
-      zsclaritytype: this.data.neatnes,
-      zscuttype: this.data.qiegong,
-      zssymmetrytype: this.data.duicheng,
-      zspolishtype: this.data.paoguang,
-      zsfluorescencetype: this.data.yingguang,
-      zscurrencytype: this.data.currency,
-      zscerttype: this.data.certificate,
-      zscolortype: this.data.color,
+      zscategory: this.data.tabs[this.data.active].id,
+      zsshapetype: this.data.zsshapetype,
+      zsclaritytype: this.data.zsclaritytype,
+      zscuttype: this.data.zscuttype,
+      zssymmetrytype: this.data.zssymmetrytype,
+      zspolishtype: this.data.zspolishtype,
+      zsfluorescencetype: this.data.zsfluorescencetype,
+      zscurrencytype: this.data.zscurrencytype,
+      zscerttype: this.data.zscerttype,
+      zscolortype: this.data.zscolortype,
       weight1: Number(this.data.minweight),
       weight2: Number(this.data.maxweight)
     }
@@ -218,7 +199,7 @@ Page({
       /// 加载成功
       success: () => {
         /// 缓存数据
-        wx.setStorageSync('TradeParams', JSON.stringify(info))
+        saveDiamondFilters(info)
       }
     })
   },
@@ -238,67 +219,35 @@ Page({
     this.setData({
       /// 形状
       shapes: getEnumList('ZSShapeType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname.toString() === this.data.shape[0]
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 颜色
       colors: getEnumList('ZSColorType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.color[0]
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 净度
       neatness: getEnumList('ZSClarityType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.neatnes
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 切工
       qiegongs: getEnumList('ZSCutType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.qiegong
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 对称
       duichengs: getEnumList('ZSSymmetryType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.duicheng
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 抛光
       paoguangs: getEnumList('ZSPolishType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.paoguang
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 荧光
       yingguangs: getEnumList('ZSFluorescenceType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.yingguang
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
       /// 证书
       certificates: getEnumList('ZSCertType').map(obj => {
-        return {
-          id: obj.enumitemname,
-          name: obj.enumdicname,
-          isCheck: obj.enumitemname === this.data.certificate
-        }
+        return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
       }),
     })
   },

+ 51 - 41
GuangZuan/miniprogram/pages/trade/index.ts

@@ -1,5 +1,5 @@
 import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index"
-import { clientType, isEncrypted, protoHeader, userid, timetample, getEnumList, getErrorMsg, isMyFavorite, accountid, marketID, addMyFavotite, removeMyFavorite, getTradeActive } from "../../services/utils";
+import { clientType, isEncrypted, protoHeader, userid, timetample, getEnumList, getErrorMsg, isMyFavorite, accountid, marketID, addMyFavotite, removeMyFavorite, getTradeActive, diamondFilters, removeDiamondFilters } from "../../services/utils";
 import { FunCode } from "../../constants/enum/funcode";
 import { sendMsgToMQ } from "../../services/api/common/index";
 import { hideLoading, showLoading } from "../../utils/message/index";
@@ -32,8 +32,7 @@ Page({
     /// tab索引
     active: Number(0),
     /// 钻石分类
-    categorys: [{ text: '单颗裸钻', value: 2 },
-                { text: '单颗彩钻', value: 5 }],
+    categorys: [{ text: '单颗裸钻', value: 2 }, { text: '单颗彩钻', value: 5 }],
     category: 2,
     /// 钻石形状
     shapes: [{ value: 0, text: '形状' }],
@@ -82,8 +81,10 @@ Page({
    * 下拉菜单触发时间
    */
   onDropdownChange() {
+    /// 清楚缓存
+    removeDiamondFilters()
     /// 数据查询
-    this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder()
+    this.queryDiamond()
   },
 
   /**
@@ -204,26 +205,54 @@ Page({
       zsfluorescencetype: this.data.fluorescence === 0 ? [] : [this.data.fluorescence],
     }
     /// 获取参数
-    // const info = JSON.parse(wx.getStorageSync('TradeParams')) 
+    const info = diamondFilters()
+    /// 动态添加数据
+    if (info != undefined) {
+      /// 类型
+      data.zscategory = info.zscategory
+      this.setData({ category: info.zscategory })
+      /// 形状
+      if (info.zsshapetype.length != 0) {
+        data.zsshapetype = info.zsshapetype
+        this.setData({ shape: Number(info.zsshapetype[0]) })
+      }
+      /// 净度
+      if (info.zsclaritytype.length != 0) {
+        data.zsclaritytype = info.zsclaritytype
+        this.setData({ clarity: info.zsclaritytype[0] })
+      }
+      /// 切工
+      if (info.zscuttype.length != 0) {
+        data.zscuttype = info.zscuttype
+        this.setData({ cut: info.zscuttype[0] })
+      }
+      /// 荧光
+      if (info.zsfluorescencetype.length != 0) {
+        data.zsfluorescencetype = info.zsfluorescencetype
+        this.setData({ fluorescence: info.zsfluorescencetype[0] })
+      }
+      /// 总重量(克拉重量)-从
+      if (info.weight1 != 0) { data.weight1 = info.weight1 }
+      /// 总重量(克拉重量)-至
+      if (info.weight2 != 0) { data.weight2 = info.weight2 }
+      /// 对称
+      if (info.zssymmetrytype.length != 0) { data.zssymmetrytype = info.zssymmetrytype }
+      /// 抛光
+      if (info.zspolishtype.length != 0) { data.zspolishtype = info.zspolishtype }
+      /// 证书类型
+      if (info.zscerttype.length != 0) { data.zscerttype = info.zscerttype }
+      /// 货币类型
+      if (info.zscurrencytype.length != 0) { data.zscurrencytype = info.zscurrencytype }
+      /// 颜色
+      if (info.zscolortype.length != 0) { data.zscolortype = info.zscolortype }
+    }
+
+    /// showLoading
     showLoading(() => {
       /// 钻石查询
       queryDiamond({
         data: {
-          ...data,
-          // /// 颜色
-          // zscolortype: info ? info.zscolortype : [],
-          // /// 货币类型
-          // zscurrencytype: info ? [info.zscurrencytype.toString()] : [],
-          // /// 证书类型
-          // zscerttype: info ? [info.zscerttype.toString()] : [],
-          // /// 抛光
-          // zspolishtype: info ? [info.zspolishtype] : [],
-          // /// 对称
-          // zssymmetrytype: info ? [info.zssymmetrytype] : [],
-          // /// 总重量(克拉重量)-从
-          // weight1: info ? info.weight1 : 0.0,
-          // /// 总重量(克拉重量)-至
-          // weight2: info ? info.weight2 : 0
+          ...data
         },
         /// 加载成功
         success: (res) => {
@@ -352,30 +381,11 @@ Page({
   },
 
   onShow() {
-    // /// 获取参数
-    // const storge = wx.getStorageSync('TradeParams')
-    // if (storge) {
-    //   try {
-    //     const info = JSON.parse(storge)
-    //     if (storge) {
-    //       /// 数据缓存
-    //       this.setData({ 
-    //         storge: info,
-    //         category: info.category,
-    //         cut: info.zscuttype,
-    //         shape: info.zsshapetype,
-    //         clarity: info.zsclaritytype,
-    //         fluorescence: info.zsfluorescencetype
-    //       })
-    //     }
-    //   } catch (error) {}
-    // }
+    /// 获取激活想
     this.setData({ active: getTradeActive() })
-    
     /// 更新数据
     const t = this
     setTimeout(function () { t.data.active == 0 ? t.queryDiamond() : t.queryBuyOrder() }, 300)
-
     /// 初始化Tabbar
     this.getTabBar().init()
   },
@@ -391,7 +401,7 @@ Page({
    * 生命周期函数--监听页面隐藏
    */
   onHide() {
-
+    
   },
 
   /**

+ 18 - 1
GuangZuan/miniprogram/services/utils.ts

@@ -3,7 +3,6 @@ import { getTaAccounts } from './api/account/index';
 import { v4 } from "../utils/uuid/index";
 import { IMessageHead } from './../services/socket/trade/protobuf/proto';
 import Toast from "../miniprogram_npm/@vant/weapp/toast/toast";
-import { Mode } from "fs";
 
 /// 获取履约步骤类型ID
 export function getSteptype(typeid: number): string {
@@ -410,4 +409,22 @@ export function deleteWrUserReceiptInfo() {
   if (obj) {
     wx.removeStorageSync('WrUserReceiptInfo')
   }
+}
+
+/// 保存查询钻石条件
+export function saveDiamondFilters(info: any) {
+  const jsonStr = JSON.stringify(info)
+  wx.setStorageSync('TradeParams', jsonStr)
+}
+
+export function diamondFilters() {
+  const jsonStr = wx.getStorageSync('TradeParams') ?? ''
+  if (jsonStr != '' ) {
+    return JSON.parse(jsonStr)
+  }
+  return undefined
+}
+
+export function removeDiamondFilters() {
+  wx.removeStorageSync('TradeParams')
 }