site.js 9.5 KB

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