index.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. import { priceCalc } from "../../../services/api/orders/index"
  2. import { hideLoading, showLoading } from "../../../utils/message/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. showLoading(()=>{
  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: () => {
  75. hideLoading(()=>{})
  76. },
  77. /// 查询失败
  78. fail: (emsg) => {
  79. hideLoading(()=>{}, '计算失败,原因:' + emsg, 'error')
  80. }
  81. })
  82. }, '计算中....')
  83. },
  84. /**
  85. * 返回上层视图
  86. */
  87. backToParent() {
  88. /// 返回上层视图
  89. wx.navigateBack()
  90. },
  91. /**
  92. * 按钮点击响应事件
  93. */
  94. /// 形状按钮点击事件
  95. onButtonPressed(e: any) {
  96. /// 获取对应的id
  97. const ids = (<string> e.target.id).split(' ')
  98. let id = (<string> e.target.id).split(' ')[0]
  99. const index = <number> <unknown>ids[1]
  100. switch (id) {
  101. case 'zsshape': /// 形状
  102. this.setData({
  103. zsshapes: this.data.zsshapes.map(item => {
  104. if (item.id == index) {
  105. item.isCheck = true
  106. /// 设置形状
  107. this.setData({ zsshape: item.id })
  108. } else {
  109. item.isCheck = false
  110. }
  111. return item
  112. })
  113. })
  114. break;
  115. case 'zscolor': /// 颜色
  116. this.setData({
  117. zscolors: this.data.zscolors.map(item => {
  118. if (item.id == index) {
  119. item.isCheck = true
  120. /// 设置形状
  121. this.setData({ zscolor: item.name })
  122. } else {
  123. item.isCheck = false
  124. }
  125. return item
  126. }) })
  127. break;
  128. case 'zsclarity': /// 净度
  129. this.setData({
  130. zsclaritys: this.data.zsclaritys.map(item => {
  131. if (item.id == index) {
  132. item.isCheck = true
  133. /// 设置形状
  134. this.setData({ zsclarity: item.name })
  135. } else {
  136. item.isCheck = false
  137. }
  138. return item
  139. }) })
  140. break;
  141. default: /// 计算
  142. this.priceCalc()
  143. break;
  144. }
  145. },
  146. /**
  147. * 生命周期函数--监听页面加载
  148. */
  149. onLoad() {},
  150. /**
  151. * 生命周期函数--监听页面初次渲染完成
  152. */
  153. onReady() {},
  154. /**
  155. * 生命周期函数--监听页面显示
  156. */
  157. onShow() {},
  158. /**
  159. * 生命周期函数--监听页面隐藏
  160. */
  161. onHide() {},
  162. /**
  163. * 生命周期函数--监听页面卸载
  164. */
  165. onUnload() {},
  166. /**
  167. * 页面相关事件处理函数--监听用户下拉动作
  168. */
  169. onPullDownRefresh() {},
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom() {},
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage() {}
  178. })