constructsitelist.js 13 KB

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