index.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { priceCalc } from "../../../services/api/orders/index"
  2. import { hideLoading, showLoading } from "../../../utils/message/index"
  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. zscolors: [ { id: 1, name: 'D', isCheck: true },
  19. { id: 2, name: 'E', isCheck: false },
  20. { id: 3, name: 'F', isCheck: false },
  21. { id: 4, name: 'G', isCheck: false },
  22. { id: 5, name: 'H', isCheck: false },
  23. { id: 6, name: 'I', isCheck: false },
  24. { id: 7, name: 'J', isCheck: false },
  25. { id: 8, name: 'K', isCheck: false },
  26. { id: 9, name: 'L', isCheck: false },
  27. { id: 10, name: 'M', isCheck: false },
  28. { id: 11, name: 'N', isCheck: false }],
  29. /// 选中形状
  30. zscolor: 'D',
  31. /// 净度
  32. zsclaritys: [ { id: 2, name: 'IF', isCheck: true },
  33. { id: 3, name: 'VVS1', isCheck: false },
  34. { id: 4, name: 'VVS2', isCheck: false },
  35. { id: 5, name: 'VS1', isCheck: false },
  36. { id: 6, name: 'VS2', isCheck: false },
  37. { id: 7, name: 'SI1', isCheck: false },
  38. { id: 8, name: 'SI2', isCheck: false },
  39. { id: 9, name: 'SI3', isCheck: false },
  40. { id: 10, name: 'I1', isCheck: false },
  41. { id: 11, name: 'I2', isCheck: false },
  42. { id: 12, name: 'I3', isCheck: false }],
  43. /// 选中净度
  44. zsclarity: 'IF',
  45. /// 重量
  46. weight: 0.0,
  47. /// 汇率
  48. dayrate: 0.0,
  49. /// 折扣
  50. discount: 0.0,
  51. /// 国际报价
  52. doller: '0.0',
  53. /// 国际人民币报价
  54. rmb: '0.0',
  55. /// 选项值
  56. value: 1
  57. },
  58. /// 钻石价格计算器
  59. priceCalc() {
  60. /// showLoding....
  61. showLoading(()=>{
  62. /// 折扣
  63. const discount = Number((this.data.value === 0 ? '-' : '+')+this.data.discount.toString())
  64. const rate = Number(this.data.dayrate)
  65. const weight = Number(this.data.weight)
  66. /// 进行查询
  67. priceCalc({
  68. data: {
  69. zsshape: this.data.zsshape,
  70. zscolor: this.data.zscolor,
  71. zsclarity: this.data.zsclarity,
  72. weight: weight,
  73. rate: rate,
  74. discount: discount
  75. },
  76. /// 查询成功
  77. success: (res) => {
  78. if (res.code != 200) {
  79. hideLoading(()=>{}, '查询失败')
  80. return
  81. }
  82. hideLoading(()=>{
  83. const dollar = Number(res.data[0].dollar)
  84. this.setData({
  85. doller: dollar.toFixed(2),
  86. rmb: (dollar*rate).toFixed(2),
  87. })
  88. })
  89. },
  90. /// 查询失败
  91. fail: (emsg) => {
  92. hideLoading(()=>{}, '计算失败,原因:' + emsg)
  93. }
  94. })
  95. }, '计算中....')
  96. },
  97. setDisAccount() {
  98. if (this.data.value === 1) {
  99. this.setData({ value: 0 })
  100. } else {
  101. this.setData({ value: 1 })
  102. }
  103. },
  104. /**
  105. * 返回上层视图
  106. */
  107. backToParent() {
  108. /// 返回上层视图
  109. wx.navigateBack()
  110. },
  111. /**
  112. * 按钮点击响应事件
  113. */
  114. /// 形状按钮点击事件
  115. onButtonPressed(e: any) {
  116. /// 获取对应的id
  117. const ids = (<string> e.target.id).split(' ')
  118. let id = (<string> e.target.id).split(' ')[0]
  119. const index = <number> <unknown>ids[1]
  120. switch (id) {
  121. case 'zsshape': /// 形状
  122. this.setData({
  123. zsshapes: this.data.zsshapes.map(item => {
  124. if (item.id == index) {
  125. item.isCheck = true
  126. /// 设置形状
  127. this.setData({ zsshape: item.id })
  128. } else {
  129. item.isCheck = false
  130. }
  131. return item
  132. })
  133. })
  134. break;
  135. case 'zscolor': /// 颜色
  136. this.setData({
  137. zscolors: this.data.zscolors.map(item => {
  138. if (item.id == index) {
  139. item.isCheck = true
  140. /// 设置形状
  141. this.setData({ zscolor: item.name })
  142. } else {
  143. item.isCheck = false
  144. }
  145. return item
  146. }) })
  147. break;
  148. case 'zsclarity': /// 净度
  149. this.setData({
  150. zsclaritys: this.data.zsclaritys.map(item => {
  151. if (item.id == index) {
  152. item.isCheck = true
  153. /// 设置形状
  154. this.setData({ zsclarity: item.name })
  155. } else {
  156. item.isCheck = false
  157. }
  158. return item
  159. }) })
  160. break;
  161. default: /// 计算
  162. this.priceCalc()
  163. break;
  164. }
  165. },
  166. /**
  167. * 生命周期函数--监听页面加载
  168. */
  169. onLoad() {},
  170. /**
  171. * 生命周期函数--监听页面初次渲染完成
  172. */
  173. onReady() {},
  174. /**
  175. * 生命周期函数--监听页面显示
  176. */
  177. onShow() {},
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide() {},
  182. /**
  183. * 生命周期函数--监听页面卸载
  184. */
  185. onUnload() {},
  186. /**
  187. * 页面相关事件处理函数--监听用户下拉动作
  188. */
  189. onPullDownRefresh() {},
  190. /**
  191. * 页面上拉触底事件的处理函数
  192. */
  193. onReachBottom() {},
  194. /**
  195. * 用户点击右上角分享
  196. */
  197. onShareAppMessage() {}
  198. })