calculator.ts 4.8 KB

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