buildinglist.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. employeeflag:false,
  11. orderBuildType: 'new',
  12. unlogin: false,//默认未登录状态,false未登录,true登录成功,并是公司成员
  13. imgUrl: app.globalData.imgUrl,
  14. mattertype: '营销楼盘',
  15. datashow: false,
  16. filtrateflag: false,
  17. buildinglist: [],
  18. companyobj: {},
  19. shareobj: {},
  20. page: 1,
  21. buildVal: "",
  22. nowtype: '',
  23. nowid: '',
  24. nowtitle: '',
  25. nowimg: '',
  26. loginFlag: false,
  27. phoneFlag:false,
  28. canIUseGetUserProfile: false,
  29. otherarr: [
  30. { id: 1, name: '最新', type: 'time' },
  31. { id: 2, name: '最热', type: 'hot' }
  32. ],
  33. type:'',//3就是从首页跳转,不显示底部
  34. top:app.globalData.statusBarHeight,
  35. hgt:app.globalData.titleBarHeight,
  36. index:'',
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. var that = this;
  43. time = 0;
  44. wx.hideHomeButton();
  45. this.setData({
  46. index:options.index?options.index:''
  47. })
  48. if(options.type){
  49. this.setData({
  50. type:options.type
  51. })
  52. }
  53. if (wx.getUserProfile) {
  54. this.setData({
  55. canIUseGetUserProfile: true
  56. })
  57. }
  58. wx.showLoading({
  59. title: '加载中...',
  60. })
  61. if (!!options.scene) {
  62. options = unescape(options.scene);
  63. let arr = options.split('&');
  64. let obj = {};
  65. for (let i = 0; i < arr.length; i++) {
  66. let arr1 = arr[i].split('=');
  67. obj[arr1[0]] = arr1[1];
  68. }
  69. app.globalData.clientype = obj.ctp;
  70. app.globalData.shareuserid = obj.uid;
  71. app.globalData.currentUserId = obj.emid;
  72. } else {
  73. app.globalData.clientype = options.ctp;
  74. app.globalData.shareuserid = options.uid;
  75. app.globalData.currentUserId = options.emid;
  76. }
  77. this.login();
  78. },
  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/code2sessionmini',
  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(5);
  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. app.globalData.personMsg = r.data.user;
  115. app.globalData.userflag = false; //有个人信息
  116. var nickname = r.data.user.nickname;
  117. var phone = r.data.user.phone;
  118. app.globalData.phone = false; //没有手机号
  119. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  120. app.globalData.currentUserId = r.data.user.binded.id;
  121. }
  122. that.unreadMsg();
  123. } else {
  124. wx.hideLoading();
  125. that.unreadMsg();
  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. gobacktap(){
  143. wx.navigateBack({
  144. delta: 1,
  145. success:function(r){
  146. },
  147. fail:function(r){
  148. wx.reLaunch({
  149. url: '/pages/index/index?state=1',
  150. })
  151. },
  152. })
  153. },
  154. /**
  155. * 获取公司信息
  156. */
  157. sharecompany: function () {
  158. const that = this;
  159. utils.$post({
  160. url: app.globalData.webUrl + 'client/index/content_belong_company',
  161. header: {
  162. 'Authorization': 'bearer ' + app.globalData.token
  163. },
  164. data: {
  165. client_type: app.globalData.clientype,
  166. uid: app.globalData.shareuserid
  167. },
  168. success: function (res) {
  169. if (res.data.code == '0') {
  170. that.setData({
  171. companyobj: res.data.data
  172. })
  173. if (res.data.data.employee_id) {
  174. app.globalData.currentUserId = res.data.data.employee_id
  175. }
  176. app.globalData.companyobj=res.data.data;
  177. }
  178. },
  179. complete(res) {
  180. wx.hideLoading()
  181. }
  182. })
  183. },
  184. /**
  185. * 登录成功回调
  186. */
  187. unreadMsg: function () {
  188. this.getBuildingProgress();
  189. },
  190. /**
  191. * 筛选-最新|最热
  192. * @param {*} e
  193. */
  194. setBuildFilter(e) {
  195. wx.showLoading({
  196. title: '加载中...',
  197. })
  198. page = 1;
  199. this.setData({
  200. orderBuildType: e.currentTarget.dataset.type
  201. })
  202. this.getBuildingProgress();
  203. },
  204. dothis: function () { },
  205. buildValInput(e) {
  206. this.setData({
  207. buildVal:e.detail.value
  208. })
  209. },
  210. allfiltratetap: function () {
  211. this.data.filtrateflag = !this.data.filtrateflag;
  212. this.setData({
  213. filtrateflag: this.data.filtrateflag,
  214. })
  215. },
  216. searchFunc() {
  217. wx.showLoading({
  218. title: '加载中...',
  219. })
  220. page = 1;
  221. this.getBuildingProgress();
  222. },
  223. /**
  224. * 获取营销楼盘列表
  225. */
  226. getBuildingProgress() {
  227. var that = this;
  228. utils.$post({
  229. url: app.globalData.webUrl + 'client/building/index',
  230. header: {
  231. 'Authorization': 'bearer ' + app.globalData.token
  232. },
  233. data: {
  234. order: that.data.orderBuildType,
  235. page: page,
  236. limit: "10",
  237. name: that.data.buildVal
  238. },
  239. success: function (res) {
  240. wx.hideLoading()
  241. if (res.data.code == 0) {
  242. res.data.data.forEach(v => {
  243. v.areastr = v.area_list.map(v => `${v}㎡`);
  244. v.update_time = v.update_time ? v.update_time.split(' ')[0] : '';
  245. v.duetime = v.duetime ? v.duetime.split(' ')[0] : '';
  246. })
  247. that.setData({
  248. datashow: true,
  249. buildinglist: res.data.data
  250. })
  251. }
  252. }
  253. })
  254. },
  255. /**
  256. * 楼盘详情
  257. * @param {*} e
  258. */
  259. toPageDetail(e) {
  260. let id = e.currentTarget.dataset.id;
  261. wx.navigateTo({
  262. url: '/share/pages/buildprogress/buildprogress?type=3&cid=' + id + '&ctp=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId+'&index='+this.data.index,
  263. })
  264. },
  265. arrfun: function (str) {
  266. var that = this;
  267. let arr = str.split(',');
  268. return arr;
  269. },
  270. /**
  271. * 生命周期函数--监听页面初次渲染完成
  272. */
  273. onReady: function () {
  274. },
  275. goindextap:function(){
  276. if(!this.data.employeeflag){
  277. wx.reLaunch({
  278. url: '/pages/index/index?state=1',
  279. })
  280. }else{
  281. wx.reLaunch({
  282. url: '/pages/consoledesk/consoledesk',
  283. })
  284. }
  285. },
  286. /**
  287. * 生命周期函数--监听页面显示
  288. */
  289. onShow: function () {
  290. page = 1;
  291. timer = setInterval(function () {
  292. time = time * 1 + 1;
  293. }, 1000)
  294. },
  295. /**
  296. * 生命周期函数--监听页面隐藏
  297. */
  298. onHide: function () {
  299. page = 1;
  300. if (timer) {
  301. clearInterval(timer)
  302. }
  303. this.setimetap();
  304. },
  305. setimetap(){
  306. const that = this;
  307. if(!that.data.companyobj.employee_id){
  308. return false;
  309. }
  310. utils.$post({
  311. url: app.globalData.webUrl + 'client/index/visit_due_time',
  312. header: {
  313. 'Authorization': 'bearer ' + app.globalData.token
  314. },
  315. data: {
  316. id: that.data.companyobj.employee_id,
  317. pipe_type: 'toolAll',
  318. time: time,
  319. },
  320. success: function (res) {
  321. }
  322. })
  323. },
  324. /**
  325. * 生命周期函数--监听页面卸载
  326. */
  327. onUnload: function () {
  328. page = 1;
  329. this.setimetap();
  330. },
  331. /**
  332. * 页面相关事件处理函数--监听用户下拉动作
  333. */
  334. onPullDownRefresh: function () {
  335. var that = this;
  336. if (that.data.mattertype == '营销楼盘') {
  337. wx.showLoading({
  338. title: '加载中...',
  339. })
  340. page = 1;
  341. this.getBuildingProgress();
  342. wx.stopPullDownRefresh();
  343. }
  344. },
  345. /**
  346. * 页面上拉触底事件的处理函数
  347. */
  348. onReachBottom: function () {
  349. var that = this;
  350. if (that.data.mattertype == '营销楼盘') {
  351. wx.showLoading({
  352. title: '加载中...',
  353. })
  354. var that = this;
  355. page = page * 1 + 1;
  356. utils.$post({
  357. url: app.globalData.webUrl + 'client/building/index',
  358. header: {
  359. 'Authorization': 'bearer ' + app.globalData.token
  360. },
  361. data: {
  362. order: that.data.orderBuildType,
  363. page: page,
  364. limit: "10",
  365. },
  366. success: function (res) {
  367. wx.hideLoading()
  368. if (res.data.code == 0) {
  369. let list = that.data.buildinglist;
  370. res.data.data.forEach(v => {
  371. v.areastr = v.area_list.map(v => `${v}㎡`);
  372. v.update_time = v.update_time ? v.update_time.split(' ')[0] : '';
  373. v.duetime = v.duetime ? v.duetime.split(' ')[0] : '';
  374. })
  375. list = list.concat(res.data.data);
  376. that.setData({
  377. datashow: true,
  378. buildinglist: list
  379. })
  380. }
  381. }
  382. })
  383. }
  384. },
  385. addsharetap: function (type) {
  386. let that = this;
  387. utils.$post({
  388. url: app.globalData.webUrl + 'api/share/addlog',
  389. header: {
  390. 'Authorization': 'bearer ' + app.globalData.token
  391. },
  392. data: {
  393. id: '0',
  394. type: type,
  395. },
  396. success: function (r) {}
  397. })
  398. },
  399. /**
  400. * 用户点击右上角分享
  401. */
  402. onShareAppMessage: function () {
  403. let that = this;
  404. that.addsharetap('toolAll');
  405. return {
  406. title: "营销楼盘-"+that.data.companyobj.company_name,
  407. imageUrl: "https://o.nczyzs.com/xcx/aaa/buildcover.png",
  408. path: '/share/pages/buildinglist/buildinglist?uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&emid=' + app.globalData.currentUserId
  409. }
  410. }
  411. })