| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import { priceCalc } from "../../../services/api/orders/index"
- import { hideLoading, showLoading } from "../../../utils/message/index"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- /// 底部安全区域
- safeBottom: getApp().globalData.safeBottom,
- /// 窗口高度
- windowHeight: getApp().globalData.windowHeight,
- /// 形状
- zsshapes: [{ id: 1, name: '圆形', isCheck: true },
- { id: 2, name: '异性', isCheck: false }],
- /// 选中形状
- zsshape: 1,
- /// 颜色
- 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 },
- { id: 10, name: 'M', isCheck: false },
- { id: 11, name: 'N', isCheck: false }],
- /// 选中形状
- zscolor: 'D',
- /// 净度
- zsclaritys: [ { id: 2, name: 'IF', isCheck: true },
- { id: 3, name: 'VVS1', isCheck: false },
- { id: 4, name: 'VVS2', isCheck: false },
- { id: 5, name: 'VS1', isCheck: false },
- { id: 6, name: 'VS2', isCheck: false },
- { id: 7, name: 'SI1', isCheck: false },
- { id: 8, name: 'SI2', isCheck: false },
- { id: 9, name: 'SI3', isCheck: false },
- { id: 10, name: 'I1', isCheck: false },
- { id: 11, name: 'I2', isCheck: false },
- { id: 12, name: 'I3', isCheck: false }],
- /// 选中净度
- zsclarity: 'IF',
- /// 重量
- weight: 0.0,
- /// 汇率
- dayrate: 0.0,
- /// 折扣
- discount: 0.0,
- /// 国际报价
- doller: '0.0',
- /// 国际人民币报价
- rmb: '0.0',
- /// 选项值
- value: 1
- },
- /// 钻石价格计算器
- priceCalc() {
- /// showLoding....
- showLoading(()=>{
- /// 折扣
- const discount = Number((this.data.value === 0 ? '-' : '+')+this.data.discount.toString())
- const rate = Number(this.data.dayrate)
- const weight = Number(this.data.weight)
- /// 进行查询
- priceCalc({
- data: {
- zsshape: this.data.zsshape,
- zscolor: this.data.zscolor,
- zsclarity: this.data.zsclarity,
- weight: weight,
- rate: rate,
- discount: discount
- },
- /// 查询成功
- success: (res) => {
- if (res.code != 200) {
- hideLoading(()=>{}, '查询失败')
- return
- }
- hideLoading(()=>{
- const dollar = Number(res.data[0].dollar)
- this.setData({
- doller: dollar.toFixed(2),
- rmb: (dollar*rate).toFixed(2),
- })
- })
- },
- /// 查询失败
- fail: (emsg) => {
- hideLoading(()=>{}, '计算失败,原因:' + emsg)
- }
- })
- }, '计算中....')
- },
- setDisAccount() {
- if (this.data.value === 1) {
- this.setData({ value: 0 })
- } else {
- this.setData({ value: 1 })
- }
- },
-
- /**
- * 返回上层视图
- */
- backToParent() {
- /// 返回上层视图
- wx.navigateBack()
- },
- /**
- * 按钮点击响应事件
- */
- /// 形状按钮点击事件
- onButtonPressed(e: any) {
- /// 获取对应的id
- const ids = (<string> e.target.id).split(' ')
- let id = (<string> e.target.id).split(' ')[0]
- const index = <number> <unknown>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({
- zscolors: 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({
- zsclaritys: 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() {}
- })
|