import { queryMyFavorite } from "../../services/api/orders/index" import Toast from '@vant/weapp/toast/toast'; import { clientType, isEncrypted, marketid, protoHeader, userid, timetample } from "../../services/utils"; import { sendMsgToMQ } from "../../services/api/common/index"; import { FunCode } from "../../constants/enum/funcode"; // pages/circle/circle.ts Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// 窗口高度 windowHeight: getApp().globalData.windowHeight, /// tabs tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}], /// tab索引 active: 0, /// 列头 titles: [['重量', '形状', '尺寸', '编号'], ['颜色', '净度', '切工', '对称', '抛光', '荧光', '证书', '价格']], /// 我的收藏 favorites: [], /// 是否空数据 isEmpty: true }, /** * tab触发事件 */ onTabChange(e: any) { this.setData({ active: e.detail.index }) /// 查询数据 this.queryMyFavorite() }, /** * 按钮点击事件 */ onButtonPressed(e: any) { console.log(e) /// 页面跳转 wx.navigateTo({ url: '/mCircle/pages/contrast/contrast' }) }, /** * tab触发事件 */ onCancelFavorite(e: any) { /// loding..... Toast.loading({ message: '请求中.....'}) const wrtradeorderid = this.data.favorites[e.target.id].wrtradeorderid /// 参数信息 const info = { UserID: userid(), OperateType: 2, 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 } console.log(res) /// 操作成功 Toast.success({message: '请求成功'}) /// 更新数据 this.queryMyFavorite() }, fail: (emsg) => { /// 操作失败 Toast.fail({ message: '请求失败,原因:'+emsg}) }, complete: () => {} }) }, /// 查询我的收藏数据信息 queryMyFavorite() { /// loding..... Toast.loading({message: '加载中...'}); /// 发送查询 queryMyFavorite({ data: { userid: userid(), zscategorys: this.data.active == 0 ? '2' : '5' }, /// 加载成功 success: (res) => { if (res.code != 200) { /// 加载失败 Toast.fail({ message: '加载失败...'}); return } /// 数据赋值 this.setData({ favorites: res.data, isEmpty: res.data.length == 0 }) }, fail: (emsg) => { /// 加载失败 Toast.fail({ message: '加载失败...'+emsg}); }, complete: () => {} }) }, /** * 生命周期函数--监听页面加载 */ onLoad() { /// 查询数据 this.queryMyFavorite() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { this.getTabBar().init() }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { /// 查询数据 this.queryMyFavorite() }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })