index.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. import Toast from "../../../miniprogram_npm/@vant/weapp/toast/toast"
  2. import { priceCalc } from "../../../services/api/orders/index"
  3. // mHome/pages/calculator/index.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. console.log(id, index)
  104. switch (id) {
  105. case 'zsshape': /// 形状
  106. this.setData({
  107. zsshapes: this.data.zsshapes.map(item => {
  108. if (item.id == index) {
  109. item.isCheck = true
  110. /// 设置形状
  111. this.setData({ zsshape: item.id })
  112. } else {
  113. item.isCheck = false
  114. }
  115. return item
  116. })
  117. })
  118. break;
  119. case 'zscolor': /// 颜色
  120. this.setData({
  121. zscolors: 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({
  134. zsclaritys: this.data.zsclaritys.map(item => {
  135. if (item.id == index) {
  136. item.isCheck = true
  137. /// 设置形状
  138. this.setData({ zsclarity: item.name })
  139. } else {
  140. item.isCheck = false
  141. }
  142. return item
  143. }) })
  144. break;
  145. default: /// 计算
  146. this.priceCalc()
  147. break;
  148. }
  149. },
  150. /**
  151. * 生命周期函数--监听页面加载
  152. */
  153. onLoad() {},
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady() {},
  158. /**
  159. * 生命周期函数--监听页面显示
  160. */
  161. onShow() {},
  162. /**
  163. * 生命周期函数--监听页面隐藏
  164. */
  165. onHide() {},
  166. /**
  167. * 生命周期函数--监听页面卸载
  168. */
  169. onUnload() {},
  170. /**
  171. * 页面相关事件处理函数--监听用户下拉动作
  172. */
  173. onPullDownRefresh() {},
  174. /**
  175. * 页面上拉触底事件的处理函数
  176. */
  177. onReachBottom() {},
  178. /**
  179. * 用户点击右上角分享
  180. */
  181. onShareAppMessage() {}
  182. })