import { queryBuyOrder, queryDiamond } from "../../services/api/orders/index" import Toast from "../../miniprogram_npm/@vant/weapp/toast/toast" import { clientType, isEncrypted, marketid, protoHeader, userid, timetample } from "../../services/utils"; import { FunCode } from "../../constants/enum/funcode"; import { sendMsgToMQ } from "../../services/api/common/index"; import { isnullstr } from "../../utils/util"; // pages/trade/index.ts Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// tabs tabs: [{id: 1, name: '出售大厅'}, {id: 2, name: '求购大厅'}], /// tab索引 active: 0, /// 出售大厅列头 asktitles: [['形状', '尺寸', '分类'], ['颜色 | 净度 | 切工 | 对称 | 抛光 | 荧光 | 证书', '']], /// 求购大厅列头 selltitles: [['重量', '形状', '尺寸', '分类'], ['颜色 | 净度 | 切工 | 对称 | 抛光 | 荧光', '价格']], /// 钻石分类 categorys: [{ text: '单颗裸钻', value: 2 }, { text: '单颗彩钻', value: 5 }], category: 2, /// 钻石形状 shapes: [{ text: '圆明亮形', value: '1' }, { text: '公主方形', value: '2' }, { text: '心形', value: '3' }, { text: '马眼形', value: '4' }, { text: '三角形', value: '5' }, { text: '垫形', value: '6' }, { text: '祖母绿形', value: '7' }, { text: '梨形', value: '8' }, { text: '椭圆形', value: '9' }, { text: '长方形', value: '10' }, { text: '雷迪恩形', value: '11' }, { text: '阿斯切形', value: '12' }, { text: '其他', value: '13' }], shape: ['1'], /// 净度 claritys: [{ text: 'FL', value: 1 }, { text: 'IF', value: 2 }, { text: 'VVS1', value: 3 }, { text: 'VVS2', value: 4 }, { text: 'VS1', value: 5 }, { text: 'VS2', value: 6 }, { text: 'SI1', value: 7 }, { text: 'SI2', value: 8 }, { text: 'SI3', value: 9 }, { text: 'I1', value: 10 }, { text: 'I2', value: 11 }, { text: 'I3', value: 12 }], clarity: 1, /// 切工 cuts: [{ text: 'EX', value: 1 }, { text: 'VG', value: 2 }, { text: 'G', value: 3 }, { text: 'F', value: 4 }, { text: 'P', value: 5 }], cut: 1, /// 荧光 fluorescences: [{ text: '无', value: 1 }, { text: '微弱', value: 2 }, { text: '中等', value: 3 }, { text: '强', value: 4 }, { text: '极强', value: 5 }], fluorescence: 1, /// 卖大厅数据 sellOrders: [], /// 买大厅数据 askOrders: [], /// 显示的值 values: [{ up: [''], dwn: [''] }], /// 左滑宽度 width: 100, /// 数据是否为空 isEmpty: true, /// 商品(查询字段-模糊查询) zsallproperties: '', /// 数据缓存 storge: {} }, /** * tab触发事件 */ onTabChange(e: any) { this.setData({ active: e.detail.index }) /// 查询数据 e.detail.index == 0 ? this.queryDiamond() : this.queryBuyOrder() /// 清空搜索条件 const info = wx.getStorageSync('TradeParams') if (info) { wx.removeStorageSync('TradeParams') } }, /// 搜索按钮点击 onClick() { /// 查询求购数据 this.queryBuyOrder() }, /** * 下拉菜单触发时间 */ onDropdownChange(e: any) { switch (e.target.id) { case "categorys": /// 钻石分类 this.setData({ category: e.detail }) break; case "shapes": /// 形状 this.setData({ shape: [e.detail.toString()] }) break; case "claritys": /// 钻石净度 this.setData({ clarity: e.detail }) break; case "cuts": /// 切工 this.setData({ cut: e.detail }) break; default: /// 荧光 this.setData({ fluorescence: e.detail }) break; } /// 数据查询 this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder() }, /** * 按钮点击响应事件 */ onButtonPressed(e: any){ /// 获取对应的id const ids = ( e.target.id).split(' ') let id = ( e.target.id).split(' ')[0] const index = ids[1] switch (id) { case 'favorite': /// 添加收藏 this.onAddFavorite(index) break case 'goods-info': /// 商品详情 wx.navigateTo({ url: '/mHome/pages/goodsdetail/index?goodsno='+ this.data.sellOrders[index].goodsno}) break; case 'search': wx.navigateTo({ url: '/mHome/pages/search/index' }) break; case 'delisting': /// 摘牌 wx.navigateTo({ url: '/mTrade/pages/delistingbuy/index?item='+JSON.stringify(this.data.sellOrders[index]) }) break; case 'listing-buy': /// 我要求购 wx.navigateTo({ url: '/mTrade/pages/listingbuy/index' }) break; case 'listing-sell': /// 我要出售 wx.navigateTo({ url: '/mTrade/pages/listingsell/index' }) break; case 'buy-inquiry': /// 我要询价 wx.navigateTo({ url: '/mTrade/pages/buyinquiry/index' }) break; case 'order-detail': /// 挂牌详情 wx.navigateTo({ url: '/mTrade/pages/orderdetail/index' }) break; case 'ask-buy': /// 求购信息 wx.navigateTo({ url: '/mTrade/pages/orderdetail/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..... Toast.loading({ message: '请求中.....'}) /// 委托单号 const wrtradeorderid = this.data.sellOrders[index].wrtradeorderid /// 参数信息 const info = { UserID: userid(), OperateType: 1, ClientType: clientType(), MarketID: marketid(), ClientSerialNo: timetample().toString(), WRTradeOrderID: wrtradeorderid, Header: protoHeader(FunCode.GoodsFavoriteOperateReq) } /// 发送请求 sendMsgToMQ({ data: { data: JSON.stringify(info), funCodeReq: FunCode.GoodsFavoriteOperateReq, funCodeRsp: FunCode.GoodsFavoriteOperateRsp, isEncrypted: isEncrypted() }, success: (res) => { /// 操作失败 if (res.code != 0) { Toast.fail({message: '请求失败,原因:'+res.msg}) return } /// 操作成功 Toast.success({message: '请求成功'}) }, fail: (emsg) => { /// 操作失败 Toast.fail({ message: '请求失败,原因:'+emsg}) }, complete: () => {} }) }, /// 查询出售大厅委托单 queryDiamond() { /// loding..... Toast.loading({message: '加载中...'}); /// 获取参数 const storge = wx.getStorageSync('TradeParams') /// 数据存储 var info if (this.data.storge) { info = JSON.parse(storge) } /// 钻石查询 queryDiamond({ data: { /// 钻石分类 zscategory: this.data.category, /// 形状 zsshapetype: this.data.shape, /// 净度 zsclaritytype: [this.data.clarity], /// 切工 zscuttype: [this.data.cut], /// 荧光 zsfluorescencetype: [this.data.fluorescence], /// 颜色 zscolortype: info ? info.zscolortype : [null], /// 货币类型 zscurrencytype: info ? [info.zscurrencytype.toString()] : [null], /// 证书类型 zscerttype: info ? [info.zscerttype.toString()] : [null], /// 抛光 zspolishtype: info ? [info.zspolishtype] : [null], /// 对称 zssymmetrytype: info ? [info.zssymmetrytype] : [null], /// 总重量(克拉重量)-从 weight1: info ? info.weight1 : null, /// 总重量(克拉重量)-至 weight2: info ? info.weight2 : null }, /// 加载成功 success: (res) => { if (res.code != 200) { /// 加载失败 Toast.fail({ message: '加载失败,原因:'+res.msg}); return } /// 数据赋值 this.setData({ sellOrders: res.data, /// 显示的值 values: res.data.map(obj => { return {up: [obj.kpweight.toString()+'ct', isnullstr(obj.zsshapetypedisplay), isnullstr(obj.sizedisplay), isnullstr(obj.zscategorydisplay)], dwn: [isnullstr(obj.zscolortype1display)+' | '+ isnullstr(obj.zsclaritytype1display)+' | '+ isnullstr(obj.zscuttype1display)+' | '+ isnullstr(obj.zssymmetrytype1display)+' | '+isnullstr(obj.zspolishtype1display)+' | '+ isnullstr(obj.zsfluorescencetype1display), obj.zscurrencytypedisplayunit+obj.price]} }) }) }, fail: (emsg) => { /// 加载失败 Toast.fail({ message: '加载失败,原因:'+emsg}); }, complete: () => { /// Toast Toast.clear() /// 数据赋值 this.setData({ isEmpty: this.data.values.length == 0 }) /// 停止下拉刷新 wx.stopPullDownRefresh() } }) }, /// 查询求购大厅委托单 queryBuyOrder() { /// loding..... Toast.loading({message: '加载中...'}); /// loding.... queryBuyOrder({ data: { /// 模糊搜索 zsallproperties: this.data.zsallproperties }, /// 加载成功 success: (res) => { if (res.code != 200) { /// 加载失败 Toast.success({ message: '加载失败...'}); return } /// 数据赋值 this.setData({ buyOrders: res.data, /// 显示的值 values: res.data.map(obj => { return {up: [isnullstr(obj.zsshapetypedisplay), obj.zssize, isnullstr(obj.zscategorydisplay)], dwn: [isnullstr(obj.zscolortypedisplay)+' | '+ isnullstr(obj.zsclaritytypedisplay)+' | '+ isnullstr(obj.zscuttypedisplay)+' | '+ isnullstr(obj.zssymmetrytypedisplay)+' | '+ isnullstr(obj.zspolishtypedisplay)+' | '+ isnullstr(obj.zsfluorescencetypedisplay), '']} }) }) }, fail: (emsg) => { /// 加载失败 Toast.fail({ message: '加载失败...'+emsg}); }, complete: () => { /// Toast Toast.clear() /// 数据赋值 this.setData({ isEmpty: this.data.values.length == 0 }) /// 停止下拉刷新 wx.stopPullDownRefresh() } }) }, /** * 生命周期函数--监听页面加载 */ onLoad() {}, onShow() { /// 获取参数 const storge = wx.getStorageSync('TradeParams') if (storge) { try { /// 数据存储 const info = JSON.parse(storge) /// 数据缓存 this.setData({ storge: info }) /// 数据赋值 if (info) { this.setData({ category: info.category, cut: info.zscuttype, shape: info.zsshapetype, clarity: info.zsclaritytype, fluorescence: info.zsfluorescencetype }) } } catch (error) {} } /// 查询出售大厅委托单 this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { /// 查询数据 this.data.active == 0 ? this.queryDiamond() : this.queryBuyOrder() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })