index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // prsx/select/area/index.js
  2. const _Http = getApp().globalData.http;
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. popupShow: false,
  9. result: [], //返回结果
  10. radio: false, //是否为单选
  11. idname: "sa_saleareaid", //idkey
  12. showName: "sa_saleareaid", //表单用 显示名称
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. console.log(options, 'options数据')
  19. this.setData({
  20. popupShow: true
  21. })
  22. _Http.basic({
  23. "content": {},
  24. "classname": "webmanage.sale.salearea.salearea",
  25. "method": "query_area"
  26. }).then(res => {
  27. if (res.code != '1') return wx.showToast({
  28. title: res.msg,
  29. icon: "none"
  30. })
  31. console.log(res.data, '输出区域数据')
  32. let list = res.data.map(v => {
  33. v.subarea.unshift({
  34. areaname: v.areaname + ' (不含下级)',
  35. sa_saleareaid: v.sa_saleareaid
  36. })
  37. return {
  38. id: v.sa_saleareaid,
  39. text: v.areaname,
  40. children: v.subarea.map(value => {
  41. const text = value.areaname;
  42. if (value.sa_saleareaid == wx.getStorageSync('userMsg').sa_saleareaid) this.setData({
  43. sa_saleareaid: value.sa_saleareaid,
  44. activeId: value.sa_saleareaid,
  45. text: value.areaname,
  46. showText: value.areaname
  47. })
  48. return {
  49. id: value.sa_saleareaid,
  50. text
  51. }
  52. })
  53. }
  54. })
  55. this.setData({
  56. list,
  57. radio: options.radio ? true : false,
  58. idname: options.idname || this.data.idname,
  59. showName: options.showName || this.data.showName
  60. })
  61. });
  62. },
  63. onClickNav({
  64. detail
  65. }) {
  66. this.setData({
  67. mainActiveIndex: detail.index
  68. })
  69. },
  70. // onClickItem({
  71. // detail
  72. // }) {
  73. // this.setData({
  74. // sa_saleareaid: detail.id,
  75. // activeId: detail.id,
  76. // text: detail.text
  77. // })
  78. // },
  79. /* 选中 */
  80. onClickItem(e) {
  81. console.log(e,'输出e的数据')
  82. console.log(this.data.result,'输出result')
  83. let {
  84. id
  85. } = e.detail, result = this.data.result;
  86. console.log(id,'输出id的数据')
  87. if (this.data.radio) {
  88. result = [id];
  89. } else {
  90. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  91. }
  92. this.setData({
  93. sa_saleareaid: e.detail.id,
  94. activeId: e.detail.id,
  95. text: e.detail.text,
  96. popupShow:false,
  97. result
  98. });
  99. if (this.data.radio) this.submit();
  100. },
  101. /* 提交 */
  102. submit() {
  103. let result = this.data.result,
  104. obj = this.data.radio ? {
  105. id: result,
  106. item: this.data,
  107. value: [this.data.text, result]
  108. } : {
  109. result,
  110. list: result.map(v => this.data.list.find(value => value[this.data.idname] == v)),
  111. value: [result.map(v => {
  112. let data = this.data.list.find(value => value[this.data.idname] == v);
  113. return data ? data[this.data.showName] : ""
  114. }), result]
  115. }
  116. wx.navigateBack()
  117. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  118. },
  119. onClose() {
  120. this.setData({
  121. popupShow: false
  122. })
  123. wx.navigateBack()
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload() {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh() {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom() {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage() {
  159. }
  160. })