import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast" import { priceCalc } from "../../../services/api/orders/index" // mHome/pages/calculator/calculator.ts Page({ /** * 页面的初始数据 */ data: { /// 底部安全区域 safeBottom: getApp().globalData.safeBottom, /// 窗口高度 windowHeight: getApp().globalData.windowHeight, /// 形状 zsshapes: [{id: 1, name: '圆形', isCheck: true}, {id: 2, name: '异性', isCheck: false}], /// 选中形状 zsshape: 1, /// 当前日期 date: Date(), /// 颜色 zscolors: [{id: 1, name: 'D', isCheck: true}, {id: 2, name: 'E', isCheck: false}, {id: 3, name: 'F', isCheck: false}, {id: 4, name: 'G', isCheck: false}, {id: 5, name: 'H', isCheck: false}, {id: 6, name: 'I', isCheck: false}, {id: 7, name: 'J', isCheck: false}, {id: 8, name: 'K', isCheck: false}, {id: 9, name: 'L', isCheck: false}], /// 选中形状 zscolor: 'D', /// 净度 zsclaritys: [{id: 1, name: 'IF', isCheck: true}, {id: 2, name: 'VVS1', isCheck: false}, {id: 3, name: 'VVS2', isCheck: false}, {id: 4, name: 'VS1', isCheck: false}, {id: 5, name: 'VS2', isCheck: false}, {id: 6, name: 'SL1', isCheck: false}, {id: 7, name: 'SL2', isCheck: false}, {id: 8, name: 'SL3', isCheck: false}, {id: 9, name: 'I1', isCheck: false}, {id: 10, name: 'I2', isCheck: false}, {id: 11, name: 'I3', isCheck: false}], /// 选中净度 zsclarity: 'IF', /// 重量 weight: 1.0, /// 汇率 dayrate: 1.0, /// 折扣 discount: 10.0, /// 美元 doller: 0.0, /// 人民币 rmb: 0.0, /// 克拉单价 unitPrice: 0.0, }, /// 钻石价格计算器 priceCalc() { /// showLoding.... Toast.loading({ message: '计算中....'}) /// 进行查询 priceCalc({ data: { zsshape: this.data.zsshape, zscolor: 'D', zsclarity: this.data.zsclarity, weight: this.data.weight, rate: this.data.dayrate, discount: this.data.discount }, /// 查询成功 success: (res) => { console.log(res) }, /// 查询失败 fail: (emsg) => { Toast('请求失败,原因:' + emsg) }, complete: () => { /// 清除Toast Toast.clear() } }) }, /** * 返回上层视图 */ backToParent() { /// 返回上层视图 wx.navigateBack() }, /** * 按钮点击响应事件 */ /// 形状按钮点击事件 onButtonPressed(e: any) { /// 获取对应的id const ids = ( e.target.id).split(' ') let id = ( e.target.id).split(' ')[0] const index = ids[1] switch (id) { case 'zsshape': /// 形状 this.setData({ zsshapes: this.data.zsshapes.map(item => { if (item.id == index) { item.isCheck = true /// 设置形状 this.setData({ zsshape: item.id }) } else { item.isCheck = false } return item }) }) break; case 'zscolor': /// 颜色 this.setData({ colors: this.data.zscolors.map(item => { if (item.id == index) { item.isCheck = true /// 设置形状 this.setData({ zscolor: item.name }) } else { item.isCheck = false } return item }) }) break; case 'zsclarity': /// 净度 this.setData({ neatness: this.data.zsclaritys.map(item => { if (item.id == index) { item.isCheck = true /// 设置形状 this.setData({ zsclarity: item.name }) } else { item.isCheck = false } return item }) }) break; default: /// 计算 this.priceCalc() break; } }, /** * 生命周期函数--监听页面加载 */ onLoad() {}, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() {}, /** * 生命周期函数--监听页面显示 */ onShow() {}, /** * 生命周期函数--监听页面隐藏 */ onHide() {}, /** * 生命周期函数--监听页面卸载 */ onUnload() {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom() {}, /** * 用户点击右上角分享 */ onShareAppMessage() {} })