site.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. const app = getApp();
  2. var utils = require("../../../utils/http");
  3. const util = require("../../../utils/util");
  4. let page = 1;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ordertype: 'time',
  11. imgUrl: app.globalData.imgUrl,
  12. list: [],
  13. filtrateflag: false,
  14. nowfirst: '',
  15. nowtitbtn: '',
  16. nowtitle: '',
  17. nowimg: '',
  18. titlist: [],
  19. indexList: [],
  20. constructlist: [],
  21. casecommunitylist: [],
  22. site_id: '',
  23. sitename: '',
  24. datashow: false,
  25. type: ''
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad(options) {
  31. wx.showLoading({
  32. title: '加载中...',
  33. })
  34. if (options.type) {
  35. this.setData({
  36. type: options.type
  37. })
  38. }
  39. this.constructfun();
  40. },
  41. setordertypetap(e) {
  42. this.setData({
  43. ordertype: e.currentTarget.dataset.type
  44. })
  45. this.constructfun();
  46. },
  47. allfiltratetap: function () {
  48. this.setData({
  49. filtrateflag: true
  50. })
  51. },
  52. constructfun() {
  53. this.casecommunityfun();
  54. const that = this;
  55. page = 1;
  56. utils.$post({
  57. url: app.globalData.webUrl + 'client/construction/index',
  58. header: {
  59. 'Authorization': 'bearer ' + app.globalData.token
  60. },
  61. data: {
  62. page: 1,
  63. limit: 10,
  64. community_id: this.data.site_id,
  65. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  66. },
  67. success: function (res) {
  68. wx.hideLoading();
  69. that.setData({
  70. datashow: true
  71. })
  72. if (res.data.code == 0) {
  73. that.setData({
  74. constructlist: res.data.data,
  75. })
  76. }
  77. }
  78. })
  79. },
  80. onChoose(e) {
  81. var that = this;
  82. that.setData({
  83. site_id: e.detail.item.currentTarget.dataset.cid,
  84. sitename: e.detail.item.currentTarget.dataset.item.name
  85. })
  86. that.constructfun();
  87. },
  88. deltap(e) {
  89. var that = this;
  90. that.setData({
  91. site_id: '',
  92. sitename: ''
  93. })
  94. that.constructfun();
  95. },
  96. casecommunityfun: function () {
  97. var that = this;
  98. utils.$get({
  99. url: app.globalData.webUrl + 'api/construction/communitylist',
  100. header: {
  101. 'Authorization': 'bearer ' + app.globalData.token
  102. },
  103. data: {},
  104. success: function (res) {
  105. if (res.data.code == '0') {
  106. that.setData({
  107. casecommunitylist: res.data.data
  108. })
  109. that.getCitys();
  110. }
  111. }
  112. })
  113. },
  114. sitetap(e) {
  115. wx.navigateTo({
  116. url: '/customer/pages/sitemsg/sitemsg?cid=' + e.currentTarget.dataset.cid + '&type=' + this.data.type,
  117. })
  118. },
  119. getCitys() {
  120. const _this = this
  121. const cities = this.data.casecommunitylist;
  122. // 按拼音排序
  123. cities.sort((c1, c2) => {
  124. let pinyin1 = c1.pinyin;
  125. let pinyin2 = c2.pinyin;
  126. return pinyin1.localeCompare(pinyin2)
  127. })
  128. // 添加首字母
  129. const map = new Map()
  130. for (const city of cities) {
  131. const alpha = city.pinyin.charAt(0).toUpperCase()
  132. if (!map.has(alpha)) map.set(alpha, [])
  133. map.get(alpha).push({
  134. name: city.name,
  135. id: city.id
  136. })
  137. }
  138. const keys = []
  139. for (const key of map.keys()) {
  140. keys.push(key)
  141. }
  142. keys.sort()
  143. const list = []
  144. for (const key of keys) {
  145. list.push({
  146. alpha: key,
  147. subItems: map.get(key)
  148. })
  149. }
  150. for (let i = 0; i < list.length; i++) {
  151. for (let k = 0; k < list[i].subItems.length; k++) {
  152. for (let j = 0; j < cities.length; j++) {
  153. if (list[i].subItems[k].name == cities[j].name) {
  154. list[i].subItems[k].case_num = cities[j].construction_count;
  155. list[i].id = cities[j].id;
  156. }
  157. }
  158. }
  159. }
  160. _this.setData({
  161. list: list
  162. })
  163. },
  164. /**
  165. * 生命周期函数--监听页面初次渲染完成
  166. */
  167. onReady() {
  168. },
  169. closefiltratetap: function () {
  170. this.setData({
  171. filtrateflag: false
  172. })
  173. },
  174. dothis: function () {},
  175. /**
  176. * 生命周期函数--监听页面显示
  177. */
  178. onShow() {
  179. },
  180. /**
  181. * 生命周期函数--监听页面隐藏
  182. */
  183. onHide() {
  184. },
  185. /**
  186. * 生命周期函数--监听页面卸载
  187. */
  188. onUnload() {
  189. },
  190. /**
  191. * 页面相关事件处理函数--监听用户下拉动作
  192. */
  193. onPullDownRefresh() {
  194. this.constructfun();
  195. wx.stopPullDownRefresh();
  196. },
  197. /**
  198. * 页面上拉触底事件的处理函数
  199. */
  200. onReachBottom() {
  201. const that = this;
  202. page = page * 1 + 1;
  203. utils.$post({
  204. url: app.globalData.webUrl + 'api/construction/index',
  205. header: {
  206. 'Authorization': 'bearer ' + app.globalData.token
  207. },
  208. data: {
  209. page: page,
  210. limit: 10,
  211. community_id: this.data.site_id,
  212. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  213. },
  214. success: function (res) {
  215. wx.hideLoading();
  216. let constructlist = that.data.constructlist;
  217. if (res.data.code == 0) {
  218. constructlist = that.data.constructlist;
  219. constructlist = constructlist.concat(res.data.data);
  220. that.setData({
  221. constructlist: constructlist,
  222. })
  223. }
  224. }
  225. })
  226. },
  227. addsharetap: function (type) {
  228. let that = this;
  229. utils.$post({
  230. url: app.globalData.webUrl + 'api/share/addlog',
  231. header: {
  232. 'Authorization': 'bearer ' + app.globalData.token
  233. },
  234. data: {
  235. id: '0',
  236. type: type,
  237. },
  238. success: function (r) {}
  239. })
  240. },
  241. /**
  242. * 用户点击右上角分享
  243. */
  244. onShareAppMessage: function() {
  245. this.addsharetap('toolAll');
  246. return {
  247. title: '在施工地-'+app.globalData.companyobj.company_name,
  248. imageUrl: app.globalData.imgUrl + 'xcx/aaa/constructcover.png',
  249. path: '/share/pages/constructsitelist/constructsitelist?uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  250. }
  251. }
  252. })