index.ts 5.1 KB

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