buildinglist.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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. orderBuildType: 'new',
  11. unlogin: false,//默认未登录状态,false未登录,true登录成功,并是公司成员
  12. imgUrl: app.globalData.imgUrl,
  13. mattertype: '热装楼盘',
  14. datashow: false,
  15. buildinglist: [],
  16. companyobj: {},
  17. shareobj: {},
  18. page: 1,
  19. nowtype: '',
  20. nowid: '',
  21. nowtitle: '',
  22. nowimg: '',
  23. loginFlag: false,
  24. canIUseGetUserProfile: false,
  25. otherarr: [
  26. { id: 1, name: '最新', type: 'time' },
  27. { id: 2, name: '最热', type: 'hot' }
  28. ],
  29. type:'',//3就是从首页跳转,不显示底部
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. var that = this;
  36. time = 0;
  37. wx.hideHomeButton();
  38. if(options.type){
  39. this.setData({
  40. type:options.type
  41. })
  42. }
  43. if (wx.getUserProfile) {
  44. this.setData({
  45. canIUseGetUserProfile: true
  46. })
  47. }
  48. wx.showLoading({
  49. title: '加载中...',
  50. })
  51. if (!!options.scene) {
  52. options = unescape(options.scene);
  53. let arr = options.split('&');
  54. let obj = {};
  55. for (let i = 0; i < arr.length; i++) {
  56. let arr1 = arr[i].split('=');
  57. obj[arr1[0]] = arr1[1];
  58. }
  59. app.globalData.clientype = obj.ctp;
  60. app.globalData.shareuserid = obj.uid;
  61. app.globalData.currentUserId = obj.emid;
  62. } else {
  63. app.globalData.clientype = options.ctp;
  64. app.globalData.shareuserid = options.uid;
  65. app.globalData.currentUserId = options.emid;
  66. }
  67. this.login();
  68. },
  69. /**
  70. * 客户授权登录
  71. */
  72. login: function () {
  73. var that = this;
  74. wx.login({
  75. success: function (data) {
  76. if (data.errMsg == 'login:ok') {
  77. utils.$post({
  78. method: "POST", //TESTAPIURL APIURL/users/auth
  79. url: app.globalData.webUrl + 'api/users/code2session',
  80. data: {
  81. code: data.code,
  82. share: app.globalData.shareuserid,
  83. client_type:app.globalData.clientype
  84. },
  85. success: function (r) {
  86. if (r.data.code == '0') {
  87. app.globalData.sharepersonobj = r.data.share;
  88. app.globalData.token = r.data.token;
  89. that.sharecompany();
  90. that.setData({
  91. shareobj: app.globalData.sharepersonobj
  92. })
  93. util.toolfun(5);
  94. 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 != '游客')) {
  95. that.setData({
  96. datashow: true,
  97. loginFlag: false,
  98. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  99. })
  100. app.globalData.personMsg = r.data.user;
  101. app.globalData.userflag = false; //有个人信息
  102. var nickname = r.data.user.nickname;
  103. var phone = r.data.user.phone;
  104. app.globalData.phone = false; //没有手机号
  105. if (r.data.user.phone == '') {
  106. wx.hideLoading();
  107. app.globalData.phone = false; //没有手机号
  108. that.loginbox = that.selectComponent("#loginbox");
  109. that.loginbox.loginfun();
  110. } else {
  111. app.globalData.phone = true; //有手机号
  112. }
  113. that.unreadMsg();
  114. } else {
  115. wx.hideLoading();
  116. that.setData({
  117. loginFlag: true
  118. })
  119. }
  120. } else {
  121. setTimeout(function () {
  122. wx.hideLoading()
  123. }, 500)
  124. }
  125. }
  126. })
  127. }
  128. }
  129. })
  130. },
  131. /**
  132. * 获取公司信息
  133. */
  134. sharecompany: function () {
  135. const that = this;
  136. utils.$post({
  137. url: app.globalData.webUrl + 'client/index/content_belong_company',
  138. header: {
  139. 'Authorization': 'bearer ' + app.globalData.token
  140. },
  141. data: {
  142. client_type: app.globalData.clientype,
  143. uid: app.globalData.shareuserid
  144. },
  145. success: function (res) {
  146. if (res.data.code == '0') {
  147. that.setData({
  148. companyobj: res.data.data
  149. })
  150. if (res.data.data.employee_id) {
  151. app.globalData.currentUserId = res.data.data.employee_id
  152. }
  153. app.globalData.companyobj=res.data.data;
  154. }
  155. },
  156. complete(res) {
  157. wx.hideLoading()
  158. }
  159. })
  160. },
  161. /**
  162. * 登录成功回调
  163. */
  164. unreadMsg: function () {
  165. this.getBuildingProgress();
  166. },
  167. /**
  168. * 筛选-最新|最热
  169. * @param {*} e
  170. */
  171. setBuildFilter(e) {
  172. page = 1;
  173. this.setData({
  174. orderBuildType: e.currentTarget.dataset.type
  175. })
  176. this.getBuildingProgress();
  177. },
  178. dothis: function () { },
  179. /**
  180. * 获取热装楼盘列表
  181. */
  182. getBuildingProgress() {
  183. var that = this;
  184. utils.$post({
  185. url: app.globalData.webUrl + 'client/building/index',
  186. header: {
  187. 'Authorization': 'bearer ' + app.globalData.token
  188. },
  189. data: {
  190. order: that.data.orderBuildType,
  191. page: page,
  192. limit: "10",
  193. },
  194. success: function (res) {
  195. wx.hideLoading()
  196. if (res.data.code == 0) {
  197. res.data.data.forEach(v => {
  198. v.areastr = v.area_list.map(v => `${v}㎡`).join('/');
  199. v.update_time = v.update_time ? v.update_time.split(' ')[0] : '';
  200. v.duetime = v.duetime ? v.duetime.split(' ')[0] : '';
  201. })
  202. that.setData({
  203. buildinglist: res.data.data
  204. })
  205. }
  206. }
  207. })
  208. },
  209. /**
  210. * 楼盘详情
  211. * @param {*} e
  212. */
  213. toPageDetail(e) {
  214. let id = e.currentTarget.dataset.id;
  215. wx.navigateTo({
  216. url: '/share/pages/buildprogress/buildprogress?type=3&cid=' + id + '&ctp=' + app.globalData.clientype + '&uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId,
  217. })
  218. },
  219. arrfun: function (str) {
  220. var that = this;
  221. let arr = str.split(',');
  222. return arr;
  223. },
  224. /**
  225. * 生命周期函数--监听页面初次渲染完成
  226. */
  227. onReady: function () {
  228. },
  229. /**
  230. * 生命周期函数--监听页面显示
  231. */
  232. onShow: function () {
  233. page = 1;
  234. timer = setInterval(function () {
  235. time = time * 1 + 1;
  236. }, 1000)
  237. },
  238. /**
  239. * 生命周期函数--监听页面隐藏
  240. */
  241. onHide: function () {
  242. page = 1;
  243. if (timer) {
  244. clearInterval(timer)
  245. }
  246. this.setimetap();
  247. },
  248. setimetap(){
  249. const that = this;
  250. if(!that.data.companyobj.employee_id){
  251. return false;
  252. }
  253. utils.$post({
  254. url: app.globalData.webUrl + 'client/index/visit_due_time',
  255. header: {
  256. 'Authorization': 'bearer ' + app.globalData.token
  257. },
  258. data: {
  259. id: that.data.companyobj.employee_id,
  260. pipe_type: 'toolAll',
  261. time: time,
  262. },
  263. success: function (res) {
  264. }
  265. })
  266. },
  267. /**
  268. * 生命周期函数--监听页面卸载
  269. */
  270. onUnload: function () {
  271. page = 1;
  272. this.setimetap();
  273. },
  274. /**
  275. * 页面相关事件处理函数--监听用户下拉动作
  276. */
  277. onPullDownRefresh: function () {
  278. var that = this;
  279. if (that.data.mattertype == '热装楼盘') {
  280. page = 1;
  281. this.getBuildingProgress();
  282. wx.stopPullDownRefresh();
  283. }
  284. },
  285. /**
  286. * 页面上拉触底事件的处理函数
  287. */
  288. onReachBottom: function () {
  289. var that = this;
  290. if (that.data.mattertype == '热装楼盘') {
  291. var that = this;
  292. page = page * 1 + 1;
  293. utils.$post({
  294. url: app.globalData.webUrl + 'client/building/index',
  295. header: {
  296. 'Authorization': 'bearer ' + app.globalData.token
  297. },
  298. data: {
  299. order: that.data.orderBuildType,
  300. page: page,
  301. limit: "10",
  302. },
  303. success: function (res) {
  304. wx.hideLoading()
  305. if (res.data.code == 0) {
  306. let list = that.data.buildinglist;
  307. res.data.data.forEach(v => {
  308. v.areastr = v.area_list.map(v => `${v}㎡`).join('/');
  309. v.update_time = v.update_time ? v.update_time.split(' ')[0] : '';
  310. v.duetime = v.duetime ? v.duetime.split(' ')[0] : '';
  311. })
  312. list = list.concat(res.data.data);
  313. that.setData({
  314. buildinglist: list
  315. })
  316. }
  317. }
  318. })
  319. }
  320. },
  321. addsharetap: function (type) {
  322. let that = this;
  323. utils.$post({
  324. url: app.globalData.webUrl + 'api/share/addlog',
  325. header: {
  326. 'Authorization': 'bearer ' + app.globalData.token
  327. },
  328. data: {
  329. id: '0',
  330. type: type,
  331. },
  332. success: function (r) {}
  333. })
  334. },
  335. /**
  336. * 用户点击右上角分享
  337. */
  338. onShareAppMessage: function () {
  339. let that = this;
  340. that.addsharetap('toolAll');
  341. return {
  342. title: "热装楼盘-"+that.data.companyobj.company_name,
  343. imageUrl: "https://o.nczyzs.com/xcx/aaa/buildcover.png",
  344. path: '/share/pages/buildinglist/buildinglist?uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&emid=' + app.globalData.currentUserId
  345. }
  346. }
  347. })