buildinglist.js 13 KB

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