| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- import { queryMyFavorite } 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 { sendMsgToMQ } from "../../services/api/common/index";
- import { FunCode } from "../../constants/enum/funcode";
- import { isnullstr } from "../../utils/util";
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- /// 底部安全区域
- safeBottom: getApp().globalData.safeBottom,
- /// 窗口高度
- windowHeight: getApp().globalData.windowHeight,
- /// tabs
- tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}],
- /// tab索引
- active: 0,
- /// 列头
- titles: [['重量', '形状', '尺寸', '编号'],
- ['颜色 | 净度 | 切工 | 对称 | 抛光 | 荧光 | 证书', '价格']],
- /// 我的收藏
- favorites: <GuangZuan.MyFavorite[]>[],
- /// 是否空数据
- isEmpty: true,
- /// 显示的值
- values: [{ up: [''], dwn: [''] }],
- /// 左滑宽度
- width: 50,
- },
- /**
- * 每行选中触发事件
- */
- onSelectItem(e: any) {
- var obj = this.data.favorites[e.currentTarget.id]
- obj.isChecked = !obj.isChecked
- this.data.favorites[e.currentTarget.id] = obj
- /// 数据赋值
- this.setData({ favorites: this.data.favorites })
- },
- /**
- * tab触发事件
- */
- onTabChange(e: any) {
- this.setData({ active: e.detail.index })
- /// 查询数据
- this.queryMyFavorite()
- },
- /**
- * 按钮点击事件
- */
- onButtonPressed() {
- /// 数据过滤
- const objs = this.data.favorites.filter(itm => {
- return itm.isChecked
- })
- /// 对比最多不能超过3项
- if (objs.length < 2 || objs.length > 3) {
- Toast('对比不能少于2项、最多不能超过3项')
- return
- }
- /// 页面跳转
- wx.navigateTo({
- url: '/mCircle/pages/contrast/index?params='+JSON.stringify(objs)
- })
- },
-
- /**
- * tab触发事件
- */
- onCancelFavorite(e: any) {
- /// loding.....
- Toast.loading({ message: '请求中.....'})
- /// 获取对应的id
- const ids = (<string> e.target.id).split(' ')
- const index = <number> <unknown>ids[1]
- const wrtradeorderid = this.data.favorites[index].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
- }
- /// 操作成功
- Toast.success({message: '请求成功'})
- /// 更新数据
- this.queryMyFavorite()
- },
- fail: (emsg) => {
- /// 操作失败
- Toast.fail({ message: '请求失败,原因:'+emsg})
- }, complete: () => {
- /// 清楚Toast
- Toast.clear()
- }
- })
- },
- /// 查询我的收藏数据信息
- queryMyFavorite() {
- /// 发送查询
- 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,
- /// 显示的值
- values: res.data.map(obj => {
- return {up: [obj.weight.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: () => {
- /// 数据赋值
- this.setData({ isEmpty: this.data.values.length == 0 })
- /// 停止下拉刷新
- wx.stopPullDownRefresh()
- }
- })
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- /// 查询数据
- this.queryMyFavorite()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- this.getTabBar().init()
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- /// 查询数据
- this.queryMyFavorite()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|