import { getEnumList, saveDiamondFilters } from "../../../services/utils" Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// tabs tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}], /// tab索引 active: 0, /// 形状 shapes: [{ id: 1, name: '圆明亮形', isCheck: false }], /// 选中形状 zsshapetype: [], /// 颜色 colors: [{id: 1, name: 'D', isCheck: false}], /// 选中形状 zscolortype: [], /// 净度 neatness: [{ id: 1, name: 'FL', isCheck: false }], /// 选中净度 zsclaritytype: [], /// 切工 qiegongs: [{ id: 1, name: 'EX', isCheck: false }], /// 选中切工 zscuttype: [], /// 对称 duichengs: [{ id: 1, name: 'EX', isCheck: false }], zssymmetrytype: [], /// 抛光 paoguangs: [{ id: 1, name: 'EX', isCheck: false }], zspolishtype: [], /// 莹光 yingguangs: [{ id: 1, name: '无', isCheck: false }], /// 选中莹光 zsfluorescencetype: [], /// 证书 certificates: [{ id: 1, name: 'GIA', isCheck: false }], /// 选中证书 zscerttype: [], /// 币种 currencys: [{id: 1, name: '人民币(¥)', isCheck: false}, {id: 2, name: '美元($)', isCheck: false}], zscurrencytype: [], /// 最小重量 minweight: '0.00', /// 最大重量 maxweight: '0.00' }, /** * tab触发事件 */ onTabChange(e: any) { /// 设置激活项 this.setData({ active: e.detail.index }) }, /** * 返回上层视图 */ backToParent() { /// 返回上层视图 wx.navigateBack() }, /// 按钮点击事件 onButtonPressed(e: any) { /// 数据拼接 const ids = ( e.target.id).split(' ') const id = ( e.target.id).split(' ')[0] const index = ids[1] switch (id) { case 'shape': /// 形状 this.setData({ shapes: this.data.shapes.map(item => { if (item.id == index) { item.isCheck = !item.isCheck } return 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 = !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({ 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 = !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 = !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 = !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 = !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 = !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 = !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': /// 搜索页面跳转 this.goToSearch() break; case 'clear': break default: break; } }, /// 重量范围值更改 syncNumRange(e: any) {1234 this.setData({ minweight: e.detail.value[0], maxweight: e.detail.value[1], }) }, /// 搜索页面跳转 goToSearch() { /// 数据拼接 const info = { 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) } /// 页面跳转 wx.switchTab({ url: '/pages/trade/index', /// 加载成功 success: () => { /// 缓存数据 saveDiamondFilters(info) } }) }, /** * 生命周期函数--监听页面加载 */ onLoad() { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { /// 显示默认数据 this.setData({ /// 形状 shapes: getEnumList('ZSShapeType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 颜色 colors: getEnumList('ZSColorType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 净度 neatness: getEnumList('ZSClarityType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 切工 qiegongs: getEnumList('ZSCutType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 对称 duichengs: getEnumList('ZSSymmetryType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 抛光 paoguangs: getEnumList('ZSPolishType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 荧光 yingguangs: getEnumList('ZSFluorescenceType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), /// 证书 certificates: getEnumList('ZSCertType').map(obj => { return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false } }), }) }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })