calculator.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
  2. import { priceCalc } from "../../../services/api/orders/index"
  3. // mHome/pages/calculator/calculator.ts
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. /// 底部安全区域
  10. safeBottom: getApp().globalData.safeBottom,
  11. /// 窗口高度
  12. windowHeight: getApp().globalData.windowHeight,
  13. /// 形状
  14. zsshapes: [{id: 1, name: '圆形', isCheck: true},
  15. {id: 2, name: '异性', isCheck: false}],
  16. /// 选中形状
  17. zsshape: 1,
  18. /// 当前日期
  19. date: Date(),
  20. /// 颜色
  21. zscolors: [{id: 1, name: 'D', isCheck: true},
  22. {id: 2, name: 'E', isCheck: false},
  23. {id: 3, name: 'F', isCheck: false},
  24. {id: 4, name: 'G', isCheck: false},
  25. {id: 5, name: 'H', isCheck: false},
  26. {id: 6, name: 'I', isCheck: false},
  27. {id: 7, name: 'J', isCheck: false},
  28. {id: 8, name: 'K', isCheck: false},
  29. {id: 9, name: 'L', isCheck: false}],
  30. /// 选中形状
  31. zscolor: 'D',
  32. /// 净度
  33. zsclaritys: [{id: 1, name: 'IF', isCheck: true},
  34. {id: 2, name: 'VVS1', isCheck: false},
  35. {id: 3, name: 'VVS2', isCheck: false},
  36. {id: 4, name: 'VS1', isCheck: false},
  37. {id: 5, name: 'VS2', isCheck: false},
  38. {id: 6, name: 'SL1', isCheck: false},
  39. {id: 7, name: 'SL2', isCheck: false},
  40. {id: 8, name: 'SL3', isCheck: false},
  41. {id: 9, name: 'I1', isCheck: false},
  42. {id: 10, name: 'I2', isCheck: false},
  43. {id: 11, name: 'I3', isCheck: false}],
  44. /// 选中净度
  45. zsclarity: 'IF',
  46. /// 重量
  47. weight: 1.0,
  48. /// 汇率
  49. dayrate: 1.0,
  50. /// 折扣
  51. discount: 10.0,
  52. /// 美元
  53. doller: 0.0,
  54. /// 人民币
  55. rmb: 0.0,
  56. /// 克拉单价
  57. unitPrice: 0.0,
  58. },
  59. /// 钻石价格计算器
  60. priceCalc() {
  61. /// showLoding....
  62. Toast.loading({ message: '计算中....'})
  63. /// 进行查询
  64. priceCalc({
  65. data: {
  66. zsshape: this.data.zsshape,
  67. zscolor: 'D',
  68. zsclarity: this.data.zsclarity,
  69. weight: this.data.weight,
  70. rate: this.data.dayrate,
  71. discount: this.data.discount
  72. },
  73. /// 查询成功
  74. success: (res) => {
  75. console.log(res)
  76. },
  77. /// 查询失败
  78. fail: (emsg) => {
  79. Toast('请求失败,原因:' + emsg)
  80. },
  81. complete: () => {
  82. /// 清除Toast
  83. Toast.clear()
  84. }
  85. })
  86. },
  87. /**
  88. * 返回上层视图
  89. */
  90. backToParent() {
  91. /// 返回上层视图
  92. wx.navigateBack()
  93. },
  94. /**
  95. * 按钮点击响应事件
  96. */
  97. /// 形状按钮点击事件
  98. onButtonPressed(e: any) {
  99. /// 获取对应的id
  100. const ids = (<string> e.target.id).split(' ')
  101. let id = (<string> e.target.id).split(' ')[0]
  102. const index = <number> <unknown>ids[1]
  103. switch (id) {
  104. case 'zsshape': /// 形状
  105. this.setData({
  106. zsshapes: this.data.zsshapes.map(item => {
  107. if (item.id == index) {
  108. item.isCheck = true
  109. /// 设置形状
  110. this.setData({ zsshape: item.id })
  111. } else {
  112. item.isCheck = false
  113. }
  114. return item
  115. })
  116. })
  117. break;
  118. case 'zscolor': /// 颜色
  119. this.setData({ colors: this.data.zscolors.map(item => {
  120. if (item.id == index) {
  121. item.isCheck = true
  122. /// 设置形状
  123. this.setData({ zscolor: item.name })
  124. } else {
  125. item.isCheck = false
  126. }
  127. return item
  128. }) })
  129. break;
  130. case 'zsclarity': /// 净度
  131. this.setData({ neatness: this.data.zsclaritys.map(item => {
  132. if (item.id == index) {
  133. item.isCheck = true
  134. /// 设置形状
  135. this.setData({ zsclarity: item.name })
  136. } else {
  137. item.isCheck = false
  138. }
  139. return item
  140. }) })
  141. break;
  142. default: /// 计算
  143. this.priceCalc()
  144. break;
  145. }
  146. },
  147. /**
  148. * 生命周期函数--监听页面加载
  149. */
  150. onLoad() {},
  151. /**
  152. * 生命周期函数--监听页面初次渲染完成
  153. */
  154. onReady() {},
  155. /**
  156. * 生命周期函数--监听页面显示
  157. */
  158. onShow() {},
  159. /**
  160. * 生命周期函数--监听页面隐藏
  161. */
  162. onHide() {},
  163. /**
  164. * 生命周期函数--监听页面卸载
  165. */
  166. onUnload() {},
  167. /**
  168. * 页面相关事件处理函数--监听用户下拉动作
  169. */
  170. onPullDownRefresh() {},
  171. /**
  172. * 页面上拉触底事件的处理函数
  173. */
  174. onReachBottom() {},
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage() {}
  179. })