C端小程序
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

194 linhas
4.6 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) * 2;
  2. const config = require("../../config/config");
  3. const Http = require("../../utils/HttpBasics");
  4. const imgurl = require("../../utils/imgurl");
  5. Page({
  6. data: {
  7. result: [],
  8. page: 1,
  9. navigationBarHeight,
  10. multiArray: [
  11. [], []
  12. ],
  13. searchText: "请输入",
  14. multiIndex: 0,
  15. buildingFloor: [],
  16. building: null,
  17. floor: null,
  18. teljpgUrl: imgurl.teljpg.url
  19. },
  20. lastSearch: Date.now(),
  21. onShow: function attached() {
  22. this.getbuildingfloorlist();
  23. if (this.data.focus) {
  24. this.setData({
  25. searchState: true
  26. });
  27. }
  28. },
  29. /**
  30. * 页面上拉触底事件的处理函数
  31. */
  32. onReachBottom: function () {
  33. let that = this;
  34. that.data.page++;
  35. that.setData({
  36. page: that.data.page
  37. });
  38. // 如果是最后一页
  39. //就不发送请求
  40. if (!that.data.isLastPage || that.data.isFirstPage && that.data.isLastPage) {
  41. this.getList(this.data.building.id, this.data.floor.id, that.data.page)
  42. }
  43. },
  44. phone: function (e) {
  45. let that = this;
  46. if (e.currentTarget.dataset.merchantlinkphone) {
  47. wx.makePhoneCall({
  48. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  49. })
  50. }
  51. },
  52. gotoDetail(e) {
  53. wx.navigateTo({
  54. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  55. })
  56. },
  57. bindMultiPickerColumnChange: function (e) {
  58. var data = {
  59. multiArray: this.data.multiArray,
  60. multiIndex: this.data.multiIndex
  61. };
  62. console.log(e)
  63. data.multiIndex[e.detail.column] = e.detail.value;
  64. switch (e.detail.column) {
  65. case 0:
  66. data.multiArray[1] = this.data.buildingFloor[e.detail.value].floors;
  67. break;
  68. }
  69. this.setData({
  70. multiArray: this.data.multiArray,
  71. multiIndex: this.data.multiIndex
  72. })
  73. },
  74. bindMultiPickerChange: function (e) {
  75. // 楼座 building
  76. // 楼层 floor
  77. this.setData({
  78. multiIndex: e.detail.value,
  79. building: this.data.multiArray[0][e.detail.value[0]],
  80. floor: this.data.multiArray[1][e.detail.value[1]],
  81. })
  82. this.getList(this.data.building.id, this.data.floor.id, 1);
  83. this.setData({
  84. searchText: this.data.building.name + this.data.floor.floorName
  85. })
  86. },
  87. //获取楼层楼座
  88. getbuildingfloorlist() {
  89. Http.get({
  90. url: config.api.getbuildingfloorlist,
  91. data: {
  92. }
  93. }).then(res => {
  94. if (res.data.length > 0) {
  95. res.data.map(file => {
  96. if (file.floors.length > 0) {
  97. file.floors.map(ever => {
  98. ever.name = ever.floorName
  99. })
  100. }
  101. })
  102. }
  103. this.setData({
  104. buildingFloor: res.data
  105. })
  106. this.setData({
  107. multiArray: [[...this.data.buildingFloor], [...this.data.buildingFloor[0].floors]]
  108. })
  109. })
  110. .catch(err => {
  111. wx.showToast({
  112. title: err.errMsg,
  113. icon: 'none',
  114. duration: 2000,
  115. mask: false
  116. });
  117. })
  118. },
  119. getList: function (building, floor, page) {
  120. let that = this;
  121. let data = {
  122. pageNum: page,
  123. pageSize: 10,
  124. building: building ? building : null,
  125. floor: floor ? floor : null,
  126. };
  127. Http.get({
  128. url: config.api.merchantList,
  129. data: data
  130. }).then(res => {
  131. if (page == 1) {
  132. that.setData({
  133. merchantVoList: [],
  134. })
  135. }
  136. var tmpArr = that.data.merchantVoList;
  137. tmpArr.push.apply(tmpArr, res.data.list);
  138. that.setData({
  139. merchantVoList: tmpArr,
  140. isFirstPage: res.data.isFirstPage,
  141. isLastPage: res.data.isLastPage
  142. })
  143. })
  144. .catch(err => {
  145. wx.showToast({
  146. title: err.errMsg,
  147. icon: 'none',
  148. duration: 2000,
  149. mask: false
  150. });
  151. })
  152. },
  153. clearInput: function clearInput() {
  154. this.setData({
  155. value: ''
  156. });
  157. this.triggerEvent('clear');
  158. },
  159. inputFocus: function inputFocus(e) {
  160. this.triggerEvent('focus', e.detail);
  161. },
  162. inputBlur: function inputBlur(e) {
  163. this.setData({
  164. focus: false
  165. });
  166. this.triggerEvent('blur', e.detail);
  167. },
  168. showInput: function showInput() {
  169. this.setData({
  170. focus: true,
  171. searchState: true
  172. });
  173. },
  174. hideInput: function hideInput() {
  175. this.setData({
  176. searchState: false
  177. });
  178. this.setData({
  179. searchText: "请输入",
  180. merchantVoList: []
  181. })
  182. },
  183. selectResult: function selectResult(e) {
  184. var index = e.currentTarget.dataset.index;
  185. var item = this.data.result[index];
  186. this.triggerEvent('selectresult', {
  187. index: index,
  188. item: item
  189. });
  190. }
  191. })