import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index" 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"; import { encryptBody } from "../../utils/websocket/crypto"; import { appConfig } from "../../config/index"; import { formatDateString, isnullstr } from "../../utils/util"; Page({ /** * 页面的初始数据 */ data: { /// top高度 topHeight: 64.0, /// 状态栏高度 statusBarHeight: getApp().globalData.statusBarHeight, /// 导航栏高度 navHeight: getApp().globalData.navHeight, /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// 窗口高度 windowHeight: getApp().globalData.windowHeight, /// tabs tabs: [{id: 1, name: '出售大厅'}, {id: 2, name: '求购大厅'}], /// 功能菜单 menus: [{id: "listing-buy", icon: appConfig.imgUrl+'trade-listingbuy', title: '求购', path: '/mTrade/pages/listingbuy/index'}, {id: "listing-sell", icon: appConfig.imgUrl+'trade-listingsell', title: '出售', path: '/mTrade/pages/listingsell/index'}, {id: "search", icon: appConfig.imgUrl+'trade-search', title: '筛选', path: '/mHome/pages/search/index'}], /// tab索引 active: Number(0), /// 钻石分类 categorys: [{ text: '单颗裸钻', value: 2 }, { text: '单颗彩钻', value: 5 }], category: 2, /// 钻石形状 shapes: [{ value: 0, text: '形状' }], shape: 0, /// 净度 claritys: [{ text: '净度', value: 0 }], clarity: 0, /// 切工 cuts: [{ text: '切工', value: 0 }], cut: 0, /// 荧光 fluorescences: [{ text: '荧光', value: 0 }], fluorescence: 0, ///出售大厅数据 sellOrders: [], /// 求购大厅数据 askOrders: [], /// 数据是否为空 isEmpty: true, /// 商品(查询字段-模糊查询) zsallproperties: '', /// 数据缓存 storge: {}, /// 当前资金账号 taaccountid: accountid(), /// 数据长度 length: 0 }, /** * tab触发事件 */ onTabChange(e: any) { this.setData({ active: Number(e.detail.index) }) /// 查询数据 e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder() }, /// 搜索按钮点击 onClick() { /// 查询求购数据 this.queryBuyOrder() }, /** * 下拉菜单触发时间 */ onDropdownChange() { /// 清楚缓存 removeDiamondFilters() /// 数据查询 this.queryDiamond() }, /** * 按钮点击响应事件 */ onButtonPressed(e: any){ /// 获取对应的id const ids = ( e.currentTarget.id).split(' ') let id = ( e.currentTarget.id).split(' ')[0] const index = ids[1] switch (id) { case 'favorite': /// 添加收藏 this.onAddFavorite(index) break case 'detail': /// 商品详情 const { ordertime, accountid } = this.data.active === 0 ? this.data.sellOrders[index] : this.data.askOrders[index] const show = accountid === this.data.taaccountid ? 0 : 1 /// 商品详情 if (this.data.active === 0) { const { goodsno } = this.data.sellOrders[index] wx.navigateTo({ url: '/mHome/pages/goodsdetail/index?goodsno='+goodsno+'&ordertime='+formatDateString(ordertime, 'YYYY/MM/DD')+'&showTrade='+`${ show }` }) } else { wx.navigateTo({ url: ('/mTrade/pages/orderdetail/index?item='+JSON.stringify(this.data.askOrders[index])) }) } break; case 'delisting': /// 摘牌 wx.navigateTo({ url: '/mTrade/pages/delistingsell/index?item='+JSON.stringify(this.data.askOrders[index])}) break; default: break; } }, onIconClick(e: any) { switch (e.currentTarget.id) { case 'listing-buy': /// 我要求购 wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' }) break; case 'listing-sell': /// 我要出售 wx.navigateTo({ url: '/mTrade/pages/listingsell/index' }) break; case 'search': /// 搜索 wx.navigateTo({ url: '/mHome/pages/search/index' }) break; default: break; } }, /** * 添加收藏 */ onAddFavorite(index: number) { /// loding..... showLoading(()=>{ /// 委托单号 const { wrtradeorderid, favorite } = this.data.sellOrders[index] /// 参数信息 const info = JSON.stringify({ UserID: userid(), OperateType: favorite ? 2 : 1, ClientType: clientType(), MarketID: marketID(67), ClientSerialNo: timetample().toString(), WRTradeOrderID: wrtradeorderid, Header: protoHeader(FunCode.GoodsFavoriteOperateReq, marketID(67)) }) /// 发送请求 sendMsgToMQ({ data: { data: encryptBody(info), funCodeReq: FunCode.GoodsFavoriteOperateReq, funCodeRsp: FunCode.GoodsFavoriteOperateRsp, isEncrypted: isEncrypted() }, success: (res) => { /// 解析对象 const data = JSON.parse(res.data.data) if (data.RetCode != 0) { hideLoading(() => {}, getErrorMsg(data.RetCode)) return } /// 对其进行操作 isMyFavorite(wrtradeorderid) ? removeMyFavorite(wrtradeorderid) : addMyFavotite(wrtradeorderid) /// 操作成功 hideLoading(()=>{ const t = this /// 更新数据 setTimeout(function () { t.queryDiamond()}, 300) }, '请求成功'+res.msg, 'success') }, fail: (emsg) => { /// 操作失败 hideLoading(()=>{}, emsg) }, complete: () => {} }) }) }, /// 查询出售大厅委托单 queryDiamond() { /// 数据存储 var data = { /// 钻石分类 zscategory: this.data.category, /// 形状 zsshapetype: this.data.shape === 0 ? [] : [this.data.shape.toString()], /// 净度 zsclaritytype: this.data.clarity === 0 ? [] : [this.data.clarity], /// 切工 zscuttype: this.data.cut === 0 ? [] : [this.data.cut], /// 荧光 zsfluorescencetype: this.data.fluorescence === 0 ? [] : [this.data.fluorescence], } /// 获取参数 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 }, /// 加载成功 success: (res) => { if (res.code != 200) { /// 加载失败 hideLoading(()=>{}, '请求失败,原因:'+res.msg) return } /// 加载失败 hideLoading(()=>{ /// 数据赋值 this.setData({ isEmpty: res.data.length === 0, length: res.data.length ?? 0, sellOrders: res.data.map(itm => { var obj = itm obj.zscuttype1display = isnullstr(itm.zscuttype1display) obj.zspolishtype1display = isnullstr(itm.zspolishtype1display) obj.zsfluorescencetype1display = isnullstr(itm.zsfluorescencetype1display) obj.zssymmetrytype1display = isnullstr(itm.zssymmetrytype1display) obj.favorite = isMyFavorite(obj.wrtradeorderid) return obj }) }) }) }, fail: (emsg) => { /// 加载失败 hideLoading(()=>{}, emsg) }, complete: () => { /// 停止下拉刷新 wx.stopPullDownRefresh() } }) }) }, /// 查询求购大厅委托单 queryBuyOrder() { /// loding..... showLoading(()=>{ /// loding.... queryBuyOrder({ data: { /// 模糊搜索 zsallproperties: this.data.zsallproperties }, /// 加载成功 success: (res) => { if (res.code != 200) { /// 加载失败 hideLoading(()=>{}, '请求失败,原因:'+res.msg) return } hideLoading(()=>{ /// 数据赋值 this.setData({ isEmpty: res.data.length === 0, length: res.data.length ?? 0, askOrders: res.data.map(itm => { var obj = itm obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay) obj.zssize = itm.zssize.replace(',', '-') obj.zsfluorescencetypedisplay = isnullstr(itm.zsfluorescencetypedisplay) obj.zssymmetrytypedisplay = isnullstr(itm.zssymmetrytypedisplay) obj.zsclaritytypedisplay = isnullstr(itm.zsclaritytypedisplay) obj.zscuttypedisplay = isnullstr(itm.zscuttypedisplay) obj.zscolortypedisplay = isnullstr(itm.zscolortypedisplay) obj.zspolishtypedisplay = isnullstr(itm.zspolishtypedisplay) obj.zssize = isnullstr(itm.zssize) return obj }) }) }) }, fail: (emsg) => { /// 加载失败 hideLoading(()=>{}, emsg) }, complete: () => { /// 停止下拉刷新 wx.stopPullDownRefresh() } }) }) }, /** * 生命周期函数--监听页面加载 */ onLoad() { const height = this.data.statusBarHeight+this.data.navHeight /// 显示默认数据 this.setData({ topHeight: height > 64 ? height : 74.0, /// 形状 shapes: [{ value: 0, text: '形状' }].concat(getEnumList('ZSShapeType').map(obj => { return { value: obj.enumitemname, text: obj.enumdicname } })), /// 净度 claritys: [{ value: 0, text: '净度' }].concat(getEnumList('ZSClarityType').map(obj => { return { value: obj.enumitemname, text: obj.enumdicname } })), /// 切工 cuts: [{ value: 0, text: '切工' }].concat(getEnumList('ZSCutType').map(obj => { return { value: obj.enumitemname, text: obj.enumdicname } })), /// 荧光 fluorescences: [{ value: 0, text: '荧光' }].concat(getEnumList('ZSFluorescenceType').map(obj => { return { value: obj.enumitemname, text: obj.enumdicname } })), }) }, onShow() { /// 获取激活想 this.setData({ active: getTradeActive() }) /// 更新数据 const t = this setTimeout(function () { t.data.active == 0 ? t.queryDiamond() : t.queryBuyOrder() }, 300) /// 初始化Tabbar this.getTabBar().init() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { /// 查询数据 this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })