import { getEnumList } from "../../../services/utils" // pages/search/index.ts Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// tabs tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}], /// tab索引 active: 0, /// 形状 shapes: [{ id: 1, name: '圆明亮形', isCheck: true }], /// 选中形状 shape: ['1'], /// 颜色 colors: [{id: 1, name: 'D', isCheck: true}], /// 选中形状 color: [1], /// 净度 neatness: [{ id: 1, name: 'FL', isCheck: true }], /// 选中净度 neatnes: 1, /// 切工 qiegongs: [{ id: 1, name: 'EX', isCheck: true }], /// 选中切工 qiegong: 1, /// 对称 duichengs: [{ id: 1, name: 'EX', isCheck: true }], duicheng: 1, /// 抛光 paoguangs: [{ id: 1, name: 'EX', isCheck: true }], paoguang: 1, /// 莹光 yingguangs: [{ id: 1, name: '无', isCheck: true }], /// 选中莹光 yingguang: 1, /// 证书 certificates: [{ id: 1, name: 'GIA', isCheck: true }], /// 选中证书 certificate: 1, /// 币种 currencys: [{id: 1, name: '人民币(¥)', isCheck: true}, {id: 2, name: '美元($)', isCheck: false}], currency: 1, /// 最小重量 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({ shape: this.data.shapes.map(item => { return item.id.toString() }) }) break; case 'currency': this.setData({ currencys: this.data.currencys.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ currency: item.id }) } else { item.isCheck = false } return item }) }) break; case 'color': /// 颜色 this.setData({ colors: this.data.colors.map(item => { if (item.id == index) { item.isCheck = !item.isCheck } return item }) }) /// 赋值 this.setData({ color: this.data.colors.map(item => { return item.id }) }) break; case 'neatness': /// 净度 this.setData({ neatness: this.data.neatness.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ neatnes: item.id }) } else { item.isCheck = false } return item }) }) break; case 'qiegong': /// 切工 this.setData({ qiegongs: this.data.qiegongs.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ qiegong: item.id }) } else { item.isCheck = false } return item }) }) break; case 'duicheng': /// 对称 this.setData({ duichengs: this.data.duichengs.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ duicheng: item.id }) } else { item.isCheck = false } return item }) }) break; case 'polishing': /// 抛光 this.setData({ paoguangs: this.data.paoguangs.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ polishing: item.id }) } else { item.isCheck = false } return item }) }) break; case 'yingguang': /// 荧光 this.setData({ yingguangs: this.data.yingguangs.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ yingguang: item.id }) } else { item.isCheck = false } return item }) }) break; case 'certificate': /// 证书 this.setData({ certificates: this.data.certificates.map(item => { if (item.id == index) { item.isCheck = true /// 赋值 this.setData({ certificate: item.id }) } else { item.isCheck = false } return item }) }) break; case 'search': /// 搜索 /// 搜索页面跳转 this.goToSearch() break; case 'clear': break; default: break; } }, /// 重量范围值更改 syncNumRange(e: any) { this.setData({ minweight: e.detail.value[0], maxweight: e.detail.value[1], }) }, /// 搜索页面跳转 goToSearch() { /// 数据拼接 const info = { category: this.data.tabs[this.data.active].id, zsshapetype: this.data.shape, zsclaritytype: this.data.neatnes, zscuttype: this.data.qiegong, zssymmetrytype: this.data.duicheng, zspolishtype: this.data.paoguang, zsfluorescencetype: this.data.yingguang, zscurrencytype: this.data.currency, zscerttype: this.data.certificate, zscolortype: this.data.color, weight1: this.data.minweight, weight2: this.data.maxweight } /// 页面跳转 wx.switchTab({ url: '/pages/trade/index', /// 加载成功 success: () => { /// 缓存数据 wx.setStorageSync('TradeParams', JSON.stringify(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() { } })