constructsitelist.js 13 KB

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