constructsitelist.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. const app=getApp();
  2. var utils = require("../../../utils/http");
  3. const util = require("../../../utils/util");
  4. let page=1,time = 0,timer = null;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. ordertype:'time',
  11. constructlist:[],
  12. site_id:'',
  13. sitename:'',
  14. casecommunitylist:[],
  15. list: [],
  16. filtrateflag:false,
  17. datashow:false,
  18. loginFlag:false,
  19. phoneFlag:false,
  20. isAgree: false,
  21. canIUseGetUserProfile: false,
  22. shareobj:{},
  23. employeeflag:false,//false是用户,true是员工
  24. top:app.globalData.statusBarHeight,
  25. hgt:app.globalData.titleBarHeight,
  26. companyobj:{},
  27. imgUrl:app.globalData.imgUrl
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad(options) {
  33. const that=this;
  34. wx.hideHomeButton();
  35. time = 0;
  36. this.setData({
  37. top:app.globalData.statusBarHeight,
  38. hgt:app.globalData.titleBarHeight,
  39. })
  40. app.globalData.clientype=options.ctp;
  41. app.globalData.shareuserid = options.uid;
  42. if (wx.getUserProfile) {
  43. this.setData({
  44. canIUseGetUserProfile: true
  45. })
  46. }
  47. },
  48. //用户同意隐私协议
  49. agreePrivacy() {
  50. this.setData({
  51. isAgree: true
  52. })
  53. wx.showLoading({
  54. title: '加载中...',
  55. })
  56. this.login();
  57. },
  58. sharecompany:function (){
  59. const that=this;
  60. utils.$post({
  61. url: app.globalData.webUrl + 'client/index/content_belong_company',
  62. header: {
  63. 'Authorization':'bearer '+app.globalData.token
  64. },
  65. data:{
  66. client_type:app.globalData.clientype,
  67. uid: app.globalData.shareuserid
  68. },
  69. success: function (res) {
  70. if(res.data.code=='0'){
  71. app.globalData.companyobj=res.data.data;
  72. that.setData({
  73. companyobj:res.data.data
  74. })
  75. }
  76. },
  77. complete(res) {
  78. wx.hideLoading()
  79. }
  80. })
  81. },
  82. login: function () {
  83. var that = this;
  84. wx.login({
  85. success: function (data) {
  86. if (data.errMsg == 'login:ok') {
  87. utils.$post({
  88. method: "POST", //TESTAPIURL APIURL/users/auth
  89. url: app.globalData.webUrl + 'api/users/code2session',
  90. data: {
  91. code: data.code,
  92. share: app.globalData.shareuserid,
  93. client_type:app.globalData.clientype
  94. },
  95. success: function (r) {
  96. if (r.data.code == '0') {
  97. app.globalData.sharepersonobj = r.data.share;
  98. app.globalData.token = r.data.token;
  99. that.sharecompany();
  100. that.setData({
  101. shareobj:app.globalData.sharepersonobj
  102. })
  103. util.toolfun(4);
  104. app.globalData.personMsg = r.data.user;
  105. app.globalData.companyname=r.data.company;
  106. app.globalData.official_openid = r.data.official_openid;
  107. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  108. if (!!r.data.user.phone) {
  109. that.setData({
  110. loginFlag: false,
  111. phoneFlag:false,
  112. employeeflag:(!!r.data.user.binded&&r.data.user.binded.state=='在职')?true:false
  113. })
  114. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  115. app.globalData.currentUserId = r.data.user.binded.id;
  116. }
  117. app.globalData.personMsg = r.data.user;
  118. app.globalData.userflag = false; //有个人信息
  119. var nickname = r.data.user.nickname;
  120. var phone = r.data.user.phone;
  121. app.globalData.phone = false; //没有手机号
  122. that.unreadMsg();
  123. } else {
  124. that.unreadMsg();
  125. wx.hideLoading();
  126. that.setData({
  127. loginFlag: false,
  128. phoneFlag: true
  129. })
  130. }
  131. } else {
  132. setTimeout(function () {
  133. wx.hideLoading()
  134. }, 500)
  135. }
  136. }
  137. })
  138. }
  139. }
  140. })
  141. },
  142. prelooktap(){
  143. if(!app.globalData.sharepersonobj.qrcode){
  144. wx.showToast({
  145. title: "当前专属客服的二维码为空!",
  146. icon: 'none',
  147. duration: 2000
  148. })
  149. return false;
  150. }
  151. wx.previewImage({
  152. current: app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  153. urls: [app.globalData.imgUrl+app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  154. })
  155. },
  156. unreadMsg(){
  157. this.constructfun();
  158. this.casecommunityfun();
  159. },
  160. golastap:function(){
  161. wx.navigateBack({
  162. delta: 1,
  163. success:function(r){
  164. },
  165. fail:function(r){
  166. wx.reLaunch({
  167. url: '/pages/index/index?state=1',
  168. })
  169. },
  170. })
  171. },
  172. goindextap:function(){
  173. if(!this.data.employeeflag){
  174. wx.reLaunch({
  175. url: '/pages/index/index?state=1',
  176. })
  177. }else{
  178. wx.reLaunch({
  179. url: '/pages/consoledesk/consoledesk',
  180. })
  181. }
  182. },
  183. callphonetap:function(){
  184. console.log()
  185. wx.makePhoneCall({
  186. phoneNumber: app.globalData.sharepersonobj.phone //仅为示例,并非真实的电话号码
  187. })
  188. },
  189. constructfun() {
  190. const that = this;
  191. page = 1;
  192. wx.showLoading({
  193. title: '加载中...',
  194. })
  195. utils.$post({
  196. url: app.globalData.webUrl + 'client/construction/index',
  197. header: {
  198. 'Authorization': 'bearer ' + app.globalData.token
  199. },
  200. data: {
  201. page: 1,
  202. limit: 10,
  203. community_id: this.data.site_id,
  204. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  205. },
  206. success: function (res) {
  207. wx.hideLoading();
  208. if (res.data.code == 0) {
  209. that.setData({
  210. datashow: true,
  211. constructlist: res.data.data,
  212. })
  213. }
  214. }
  215. })
  216. },
  217. casecommunityfun: function () {
  218. var that = this;
  219. utils.$get({
  220. url: app.globalData.webUrl + 'client/construction/communitylist',
  221. header: {
  222. 'Authorization': 'bearer ' + app.globalData.token
  223. },
  224. data: {},
  225. success: function (res) {
  226. if (res.data.code == '0') {
  227. that.setData({
  228. casecommunitylist: res.data.data
  229. })
  230. that.getCitys();
  231. }
  232. }
  233. })
  234. },
  235. getCitys() {
  236. const _this = this
  237. const cities = this.data.casecommunitylist;
  238. // 按拼音排序
  239. cities.sort((c1, c2) => {
  240. let pinyin1 = c1.pinyin;
  241. let pinyin2 = c2.pinyin;
  242. return pinyin1.localeCompare(pinyin2)
  243. })
  244. // 添加首字母
  245. const map = new Map()
  246. for (const city of cities) {
  247. const alpha = city.pinyin.charAt(0).toUpperCase()
  248. if (!map.has(alpha)) map.set(alpha, [])
  249. map.get(alpha).push({ name: city.name, id: city.id })
  250. }
  251. const keys = []
  252. for (const key of map.keys()) {
  253. keys.push(key)
  254. }
  255. keys.sort()
  256. const list = []
  257. for (const key of keys) {
  258. list.push({
  259. alpha: key,
  260. subItems: map.get(key)
  261. })
  262. }
  263. for (let i = 0; i < list.length; i++) {
  264. list[i].subItems[0].case_num = '0';
  265. for (let k = 0; k < list[i].subItems.length; k++) {
  266. for (let j = 0; j < cities.length; j++) {
  267. if (list[i].subItems[k].name == cities[j].name) {
  268. list[i].subItems[k].case_num = cities[j].construction_count;
  269. list[i].id = cities[j].id;
  270. }
  271. }
  272. }
  273. }
  274. _this.setData({ list: list })
  275. },
  276. onChoose(e) {
  277. var that = this;
  278. console.log(e)
  279. that.setData({
  280. site_id: e.detail.item.currentTarget.dataset.cid,
  281. sitename: e.detail.item.currentTarget.dataset.item.name
  282. })
  283. that.constructfun();
  284. },
  285. setordertypetap(e) {
  286. this.setData({
  287. ordertype: e.currentTarget.dataset.type
  288. })
  289. this.constructfun();
  290. },
  291. allfiltratetap: function () {
  292. this.casecommunityfun();
  293. this.setData({
  294. filtrateflag: true
  295. })
  296. },
  297. sitetap(e) {
  298. wx.navigateTo({
  299. url: '/share/pages/constructsite/constructsite?type=3&cid=' + e.currentTarget.dataset.cid+'&uid='+app.globalData.shareuserid+'&ctp='+app.globalData.clientype,
  300. })
  301. },
  302. closefiltratetap: function () {
  303. this.setData({
  304. filtrateflag: false
  305. })
  306. },
  307. dothis(){},
  308. deltap(e) {
  309. var that = this;
  310. that.setData({
  311. site_id: '',
  312. sitename: ''
  313. })
  314. that.constructfun();
  315. },
  316. /**
  317. * 生命周期函数--监听页面初次渲染完成
  318. */
  319. onReady() {
  320. },
  321. /**
  322. * 生命周期函数--监听页面显示
  323. */
  324. onShow() {
  325. timer = setInterval(function () {
  326. time = time * 1 + 1;
  327. }, 1000)
  328. },
  329. /**
  330. * 生命周期函数--监听页面隐藏
  331. */
  332. onHide() {
  333. if (timer) {
  334. clearInterval(timer)
  335. }
  336. this.setimetap();
  337. },
  338. setimetap(){
  339. if (!this.data.isAgree) {
  340. return false;
  341. }
  342. const that = this;
  343. utils.$post({
  344. url: app.globalData.webUrl + 'client/index/visit_due_time',
  345. header: {
  346. 'Authorization': 'bearer ' + app.globalData.token
  347. },
  348. data: {
  349. id: that.data.companyobj.employee_id,
  350. pipe_type: 'toolAll',
  351. time: time,
  352. },
  353. success: function (res) {
  354. }
  355. })
  356. },
  357. /**
  358. * 生命周期函数--监听页面卸载
  359. */
  360. onUnload() {
  361. this.setimetap();
  362. },
  363. /**
  364. * 页面相关事件处理函数--监听用户下拉动作
  365. */
  366. onPullDownRefresh() {
  367. this.constructfun();
  368. setTimeout(() => {
  369. wx.stopPullDownRefresh()
  370. }, 1000)
  371. },
  372. /**
  373. * 页面上拉触底事件的处理函数
  374. */
  375. onReachBottom() {
  376. const that = this;
  377. page = page * 1 + 1;
  378. wx.showLoading({
  379. title: '加载中...',
  380. })
  381. utils.$post({
  382. url: app.globalData.webUrl + 'client/construction/index',
  383. header: {
  384. 'Authorization': 'bearer ' + app.globalData.token
  385. },
  386. data: {
  387. page: page,
  388. limit: 10,
  389. community_id: this.data.site_id,
  390. order: this.data.ordertype == 'time' ? 'new' : 'hot'
  391. },
  392. success: function (res) {
  393. wx.hideLoading();
  394. let constructlist = that.data.constructlist;
  395. if (res.data.code == 0) {
  396. constructlist = that.data.constructlist;
  397. constructlist = constructlist.concat(res.data.data);
  398. that.setData({
  399. constructlist: constructlist,
  400. })
  401. }
  402. }
  403. })
  404. },
  405. addsharetap: function (type) {
  406. let that = this;
  407. utils.$post({
  408. url: app.globalData.webUrl + 'api/share/addlog',
  409. header: {
  410. 'Authorization': 'bearer ' + app.globalData.token
  411. },
  412. data: {
  413. id: '0',
  414. type: type,
  415. },
  416. success: function (r) {}
  417. })
  418. },
  419. /**
  420. * 用户点击右上角分享
  421. */
  422. onShareAppMessage() {
  423. this.addsharetap('toolAll');
  424. return {
  425. title: '在施工地-'+this.data.companyobj.company_name,
  426. imageUrl: app.globalData.imgUrl + 'xcx/aaa/constructcover.png',
  427. path: '/share/pages/constructsitelist/constructsitelist?uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  428. }
  429. }
  430. })