site.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. bType: '',
  19. titlist: [],
  20. indexList: [],
  21. constructlist: [],
  22. casecommunitylist: [],
  23. site_id: '',
  24. sitename: '',
  25. datashow: false,
  26. type: '',
  27. wshareshow:false,
  28. nowtype: '',
  29. nowid: '',
  30. nowtitle: '',
  31. nowimg: '',
  32. islist: false,
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad(options) {
  38. wx.showLoading({
  39. title: '加载中...',
  40. })
  41. if (options.type) {
  42. this.setData({
  43. type: options.type
  44. })
  45. }
  46. if (!!options.ty) {
  47. wx.hideShareMenu();
  48. this.setData({
  49. bType: options.ty
  50. })
  51. }
  52. this.constructfun();
  53. },
  54. setordertypetap(e) {
  55. this.setData({
  56. ordertype: e.currentTarget.dataset.type
  57. })
  58. this.constructfun();
  59. },
  60. allfiltratetap: function () {
  61. this.setData({
  62. filtrateflag: true
  63. })
  64. },
  65. constructfun() {
  66. this.casecommunityfun();
  67. const that = this;
  68. page = 1;
  69. utils.$post({
  70. url: app.globalData.webUrl + 'client/construction/index',
  71. header: {
  72. 'Authorization': 'bearer ' + app.globalData.token
  73. },
  74. data: {
  75. page: 1,
  76. limit: 10,
  77. community_id: this.data.site_id,
  78. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  79. },
  80. success: function (res) {
  81. wx.hideLoading();
  82. that.setData({
  83. datashow: true
  84. })
  85. if (res.data.code == 0) {
  86. that.setData({
  87. constructlist: res.data.data,
  88. })
  89. }
  90. }
  91. })
  92. },
  93. onChoose(e) {
  94. var that = this;
  95. that.setData({
  96. site_id: e.detail.item.currentTarget.dataset.cid,
  97. sitename: e.detail.item.currentTarget.dataset.item.name
  98. })
  99. that.constructfun();
  100. },
  101. deltap(e) {
  102. var that = this;
  103. that.setData({
  104. site_id: '',
  105. sitename: ''
  106. })
  107. that.constructfun();
  108. },
  109. casecommunityfun: function () {
  110. var that = this;
  111. utils.$get({
  112. url: app.globalData.webUrl + 'api/construction/communitylist',
  113. header: {
  114. 'Authorization': 'bearer ' + app.globalData.token
  115. },
  116. data: {},
  117. success: function (res) {
  118. if (res.data.code == '0') {
  119. that.setData({
  120. casecommunitylist: res.data.data
  121. })
  122. that.getCitys();
  123. }
  124. }
  125. })
  126. },
  127. sitetap(e) {
  128. wx.navigateTo({
  129. url: '/customer/pages/sitemsg/sitemsg?cid=' + e.currentTarget.dataset.cid + '&type=' + this.data.type + '&ty=' + this.data.bType,
  130. })
  131. },
  132. getCitys() {
  133. const _this = this
  134. const cities = this.data.casecommunitylist;
  135. // 按拼音排序
  136. cities.sort((c1, c2) => {
  137. let pinyin1 = c1.pinyin;
  138. let pinyin2 = c2.pinyin;
  139. return pinyin1.localeCompare(pinyin2)
  140. })
  141. // 添加首字母
  142. const map = new Map()
  143. for (const city of cities) {
  144. const alpha = city.pinyin.charAt(0).toUpperCase()
  145. if (!map.has(alpha)) map.set(alpha, [])
  146. map.get(alpha).push({
  147. name: city.name,
  148. id: city.id
  149. })
  150. }
  151. const keys = []
  152. for (const key of map.keys()) {
  153. keys.push(key)
  154. }
  155. keys.sort()
  156. const list = []
  157. for (const key of keys) {
  158. list.push({
  159. alpha: key,
  160. subItems: map.get(key)
  161. })
  162. }
  163. for (let i = 0; i < list.length; i++) {
  164. for (let k = 0; k < list[i].subItems.length; k++) {
  165. for (let j = 0; j < cities.length; j++) {
  166. if (list[i].subItems[k].name == cities[j].name) {
  167. list[i].subItems[k].case_num = cities[j].construction_count;
  168. list[i].id = cities[j].id;
  169. }
  170. }
  171. }
  172. }
  173. _this.setData({
  174. list: list
  175. })
  176. },
  177. setpostertap: function () {
  178. wx.navigateTo({
  179. url: '/index/pages/setposter/setposter?type=Construction&aid=' + this.data.nowid + "&listshare=",
  180. })
  181. },
  182. sitesharetap(e) {
  183. var that = this;
  184. let num = e.currentTarget.dataset.idx;
  185. let str = this.data.constructlist[num];
  186. that.setData({
  187. nowtype: 'Construction',
  188. nowid: str.id,
  189. nowtitle: str.name,
  190. nowimg: str.cover_share_img?str.cover_share_img:str.cover,
  191. islist: false,
  192. wshareshow: true
  193. })
  194. },
  195. sendfriendtap() {
  196. this.addsharetap1();
  197. },
  198. addsharetap1: function () {
  199. let that = this;
  200. utils.$post({
  201. url: app.globalData.webUrl + 'api/share/addlog',
  202. header: {
  203. 'Authorization': 'bearer ' + app.globalData.token
  204. },
  205. data: {
  206. id: that.data.nowid,
  207. type: 'Construction',
  208. },
  209. success: function (r) {}
  210. })
  211. },
  212. shareurltap: function () {
  213. wx.showLoading({
  214. title: '加载中...',
  215. })
  216. this.addsharetap1();
  217. util.schemefun('/share/pages/constructsite/constructsite', 'cid=' + this.data.nowid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, this.data.nowid, 'Construction', '');
  218. },
  219. /**
  220. * 生命周期函数--监听页面初次渲染完成
  221. */
  222. onReady() {
  223. },
  224. closefiltratetap: function () {
  225. this.setData({
  226. filtrateflag: false
  227. })
  228. },
  229. dothis: function () {},
  230. /**
  231. * 生命周期函数--监听页面显示
  232. */
  233. onShow() {
  234. },
  235. /**
  236. * 生命周期函数--监听页面隐藏
  237. */
  238. onHide() {
  239. },
  240. /**
  241. * 生命周期函数--监听页面卸载
  242. */
  243. onUnload() {
  244. },
  245. /**
  246. * 页面相关事件处理函数--监听用户下拉动作
  247. */
  248. onPullDownRefresh() {
  249. this.constructfun();
  250. wx.stopPullDownRefresh();
  251. },
  252. /**
  253. * 页面上拉触底事件的处理函数
  254. */
  255. onReachBottom() {
  256. const that = this;
  257. page = page * 1 + 1;
  258. utils.$post({
  259. url: app.globalData.webUrl + 'client/construction/index',
  260. header: {
  261. 'Authorization': 'bearer ' + app.globalData.token
  262. },
  263. data: {
  264. page: page,
  265. limit: 10,
  266. community_id: this.data.site_id,
  267. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  268. },
  269. success: function (res) {
  270. wx.hideLoading();
  271. let constructlist = that.data.constructlist;
  272. if (res.data.code == 0) {
  273. constructlist = that.data.constructlist;
  274. constructlist = constructlist.concat(res.data.data);
  275. that.setData({
  276. constructlist: constructlist,
  277. })
  278. }
  279. }
  280. })
  281. },
  282. addsharetap: function (type) {
  283. let that = this;
  284. utils.$post({
  285. url: app.globalData.webUrl + 'api/share/addlog',
  286. header: {
  287. 'Authorization': 'bearer ' + app.globalData.token
  288. },
  289. data: {
  290. id: '0',
  291. type: type,
  292. },
  293. success: function (r) {}
  294. })
  295. },
  296. shareaddlog:function(){
  297. var that=this;
  298. utils.$post({
  299. url: app.globalData.webUrl + 'api/share/addlog',
  300. header: {
  301. 'Authorization':'bearer '+app.globalData.token
  302. },
  303. data: {
  304. id:that.data.nowid,
  305. type:'Construction'
  306. },
  307. success: function (r) {
  308. }
  309. })
  310. },
  311. /**
  312. * 用户点击右上角分享
  313. */
  314. onShareAppMessage: function(e) {
  315. if(e.from=='button'){
  316. this.shareaddlog();
  317. return {
  318. title: this.data.nowtitle,
  319. imageUrl: this.data.nowimg,
  320. path: '/share/pages/constructsite/constructsite?cid='+this.data.nowid+'&uid='+app.globalData.personMsg.id+'&ctp='+app.globalData.clientype
  321. }
  322. }else{
  323. this.addsharetap('toolAll');
  324. return {
  325. title: '在施工地-'+app.globalData.companyobj.company_name,
  326. imageUrl: app.globalData.imgUrl + 'xcx/aaa/constructcover.png',
  327. path: '/share/pages/constructsitelist/constructsitelist?uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype
  328. }
  329. }
  330. }
  331. })