抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

195 lines
4.6 KiB

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