index.ts 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. import { getEnumList, saveDiamondFilters } from "../../../services/utils"
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. /// 底部安全区域
  8. safeBottom: getApp().globalData.safeBottom,
  9. /// tabs
  10. tabs: [{id: 2, name: '单颗裸钻'}, {id: 5, name: '单颗彩钻'}],
  11. /// tab索引
  12. active: 0,
  13. /// 形状
  14. shapes: [{ id: 1, name: '圆明亮形', isCheck: false }],
  15. /// 选中形状
  16. zsshapetype: [],
  17. /// 颜色
  18. colors: [{id: 1, name: 'D', isCheck: false}],
  19. /// 选中形状
  20. zscolortype: [],
  21. /// 净度
  22. neatness: [{ id: 1, name: 'FL', isCheck: false }],
  23. /// 选中净度
  24. zsclaritytype: [],
  25. /// 切工
  26. qiegongs: [{ id: 1, name: 'EX', isCheck: false }],
  27. /// 选中切工
  28. zscuttype: [],
  29. /// 对称
  30. duichengs: [{ id: 1, name: 'EX', isCheck: false }],
  31. zssymmetrytype: [],
  32. /// 抛光
  33. paoguangs: [{ id: 1, name: 'EX', isCheck: false }],
  34. zspolishtype: [],
  35. /// 莹光
  36. yingguangs: [{ id: 1, name: '无', isCheck: false }],
  37. /// 选中莹光
  38. zsfluorescencetype: [],
  39. /// 证书
  40. certificates: [{ id: 1, name: 'GIA', isCheck: false }],
  41. /// 选中证书
  42. zscerttype: [],
  43. /// 币种
  44. currencys: [{id: 1, name: '人民币(¥)', isCheck: false},
  45. {id: 2, name: '美元($)', isCheck: false}],
  46. zscurrencytype: [],
  47. /// 最小重量
  48. minweight: '0.00',
  49. /// 最大重量
  50. maxweight: '0.00'
  51. },
  52. /**
  53. * tab触发事件
  54. */
  55. onTabChange(e: any) {
  56. /// 设置激活项
  57. this.setData({ active: e.detail.index })
  58. },
  59. /**
  60. * 返回上层视图
  61. */
  62. backToParent() {
  63. /// 返回上层视图
  64. wx.navigateBack()
  65. },
  66. /// 按钮点击事件
  67. onButtonPressed(e: any) {
  68. /// 数据拼接
  69. const ids = (<string> e.target.id).split(' ')
  70. const id = (<string> e.target.id).split(' ')[0]
  71. const index = <number> <unknown>ids[1]
  72. switch (id) {
  73. case 'shape': /// 形状
  74. this.setData({ shapes: this.data.shapes.map(item => {
  75. if (item.id == index) { item.isCheck = !item.isCheck }
  76. return item
  77. }) })
  78. this.setData({ zsshapetype: this.data.shapes.filter(obj => {
  79. return obj.isCheck === true
  80. }).map(item => {
  81. return item.id.toString()
  82. }) })
  83. break;
  84. case 'currency':
  85. this.setData({ currencys: this.data.currencys.map(item => {
  86. if (item.id == index) { item.isCheck = !item.isCheck }
  87. return item
  88. }) })
  89. this.setData({ zscurrencytype: this.data.currencys.filter(obj => {
  90. return obj.isCheck === true
  91. }).map(item => { return item.id.toString() }) })
  92. break;
  93. case 'color': /// 颜色
  94. this.setData({ colors: this.data.colors.map(item => {
  95. if (item.id == index) { item.isCheck = !item.isCheck }
  96. return item
  97. }) })
  98. this.setData({ zscolortype: this.data.colors.filter(obj => {
  99. return obj.isCheck === true
  100. }).map(item => { return item.id }) })
  101. break;
  102. case 'neatness': /// 净度
  103. this.setData({ neatness: this.data.neatness.map(item => {
  104. if (item.id == index) { item.isCheck = !item.isCheck }
  105. return item
  106. })
  107. })
  108. this.setData({ zsclaritytype: this.data.neatness.filter(obj => {
  109. return obj.isCheck === true
  110. }).map(item => { return item.id }) })
  111. break;
  112. case 'qiegong': /// 切工
  113. this.setData({ qiegongs: this.data.qiegongs.map(item => {
  114. if (item.id == index) { item.isCheck = !item.isCheck }
  115. return item
  116. }) })
  117. this.setData({ zscuttype: this.data.qiegongs.filter(obj => {
  118. return obj.isCheck === true
  119. }).map(item => { return item.id }) })
  120. break;
  121. case 'duicheng': /// 对称
  122. this.setData({ duichengs: this.data.duichengs.map(item => {
  123. if (item.id == index) { item.isCheck = !item.isCheck }
  124. return item
  125. }) })
  126. this.setData({ zssymmetrytype: this.data.duichengs.filter(obj => {
  127. return obj.isCheck === true
  128. }).map(item => { return item.id }) })
  129. break;
  130. case 'polishing': /// 抛光
  131. this.setData({ paoguangs: this.data.paoguangs.map(item => {
  132. if (item.id == index) { item.isCheck = !item.isCheck }
  133. return item
  134. }) })
  135. this.setData({ zspolishtype: this.data.paoguangs.filter(obj => {
  136. return obj.isCheck === true
  137. }).map(item => { return item.id }) })
  138. break;
  139. case 'yingguang': /// 荧光
  140. this.setData({ yingguangs: this.data.yingguangs.map(item => {
  141. if (item.id == index) { item.isCheck = !item.isCheck }
  142. return item
  143. }) })
  144. this.setData({ zsfluorescencetype: this.data.yingguangs.filter(obj => {
  145. return obj.isCheck === true
  146. }).map(item => { return item.id }) })
  147. break;
  148. case 'certificate': /// 证书
  149. this.setData({ certificates: this.data.certificates.map(item => {
  150. if (item.id == index) { item.isCheck = !item.isCheck }
  151. return item
  152. }) })
  153. this.setData({ zscerttype: this.data.certificates.filter(obj => {
  154. return obj.isCheck === true
  155. }).map(item => { return item.id.toString() }) })
  156. break;
  157. case 'search': /// 搜索页面跳转
  158. this.goToSearch()
  159. break;
  160. case 'clear': break
  161. default: break;
  162. }
  163. },
  164. /// 重量范围值更改
  165. syncNumRange(e: any) {1234
  166. this.setData({
  167. minweight: e.detail.value[0],
  168. maxweight: e.detail.value[1],
  169. })
  170. },
  171. /// 搜索页面跳转
  172. goToSearch() {
  173. /// 数据拼接
  174. const info = {
  175. zscategory: this.data.tabs[this.data.active].id,
  176. zsshapetype: this.data.zsshapetype,
  177. zsclaritytype: this.data.zsclaritytype,
  178. zscuttype: this.data.zscuttype,
  179. zssymmetrytype: this.data.zssymmetrytype,
  180. zspolishtype: this.data.zspolishtype,
  181. zsfluorescencetype: this.data.zsfluorescencetype,
  182. zscurrencytype: this.data.zscurrencytype,
  183. zscerttype: this.data.zscerttype,
  184. zscolortype: this.data.zscolortype,
  185. weight1: Number(this.data.minweight),
  186. weight2: Number(this.data.maxweight)
  187. }
  188. /// 页面跳转
  189. wx.switchTab({
  190. url: '/pages/trade/index',
  191. /// 加载成功
  192. success: () => {
  193. /// 缓存数据
  194. saveDiamondFilters(info)
  195. }
  196. })
  197. },
  198. /**
  199. * 生命周期函数--监听页面加载
  200. */
  201. onLoad() {
  202. },
  203. /**
  204. * 生命周期函数--监听页面初次渲染完成
  205. */
  206. onReady() {
  207. /// 显示默认数据
  208. this.setData({
  209. /// 形状
  210. shapes: getEnumList('ZSShapeType').map(obj => {
  211. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  212. }),
  213. /// 颜色
  214. colors: getEnumList('ZSColorType').map(obj => {
  215. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  216. }),
  217. /// 净度
  218. neatness: getEnumList('ZSClarityType').map(obj => {
  219. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  220. }),
  221. /// 切工
  222. qiegongs: getEnumList('ZSCutType').map(obj => {
  223. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  224. }),
  225. /// 对称
  226. duichengs: getEnumList('ZSSymmetryType').map(obj => {
  227. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  228. }),
  229. /// 抛光
  230. paoguangs: getEnumList('ZSPolishType').map(obj => {
  231. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  232. }),
  233. /// 荧光
  234. yingguangs: getEnumList('ZSFluorescenceType').map(obj => {
  235. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  236. }),
  237. /// 证书
  238. certificates: getEnumList('ZSCertType').map(obj => {
  239. return { id: obj.enumitemname, name: obj.enumdicname, isCheck: false }
  240. }),
  241. })
  242. },
  243. /**
  244. * 生命周期函数--监听页面显示
  245. */
  246. onShow() {
  247. },
  248. /**
  249. * 生命周期函数--监听页面隐藏
  250. */
  251. onHide() {
  252. },
  253. /**
  254. * 生命周期函数--监听页面卸载
  255. */
  256. onUnload() {
  257. },
  258. /**
  259. * 页面相关事件处理函数--监听用户下拉动作
  260. */
  261. onPullDownRefresh() {
  262. },
  263. /**
  264. * 页面上拉触底事件的处理函数
  265. */
  266. onReachBottom() {
  267. },
  268. /**
  269. * 用户点击右上角分享
  270. */
  271. onShareAppMessage() {
  272. }
  273. })