buildShare.js 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // share/pages/buildShare/buildShare.js
  2. const app = getApp();
  3. var utils = require("../../../utils/http");
  4. var designTimer = null;
  5. var time = 0;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. canIUseGetUserProfile: false,
  12. cid: '',
  13. loginFlag: false,
  14. designPlan: false,
  15. employeeflag: false,
  16. sharepersonMsg: {},
  17. companyobj: {},
  18. detail: {}
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. if (wx.getUserProfile) {
  25. this.setData({
  26. canIUseGetUserProfile: true
  27. })
  28. }
  29. if (!!options.cid) {
  30. this.setData({
  31. cid: options.cid
  32. })
  33. }
  34. if (!!options.ctp) {
  35. app.globalData.clientype = options.ctp;
  36. }
  37. if (!!options.uid) {
  38. app.globalData.shareuserid = options.uid;
  39. }
  40. this.login();
  41. wx.hideHomeButton()
  42. },
  43. login: function () {
  44. var that = this;
  45. wx.login({
  46. success: function (data) {
  47. if (data.errMsg == 'login:ok') {
  48. utils.$post({
  49. url: app.globalData.webUrl + 'api/users/code2session',
  50. data: {
  51. code: data.code,
  52. share: app.globalData.shareuserid,
  53. client_type: app.globalData.clientype
  54. },
  55. success: function (r) {
  56. if (r.data.code == '0') {
  57. app.globalData.sharepersonobj = r.data.share;
  58. app.globalData.token = r.data.token;
  59. that.sharecompany();
  60. that.setData({
  61. sharepersonMsg: app.globalData.sharepersonobj,
  62. })
  63. 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 != '游客')) {
  64. that.setData({
  65. loginFlag: false,
  66. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  67. })
  68. app.globalData.personMsg = r.data.user;
  69. app.globalData.use_id = r.data.user.id;
  70. app.globalData.userflag = false;//有个人信息
  71. var nickname = r.data.user.nickname;
  72. var phone = r.data.user.phone;
  73. app.globalData.phone = false;//没有手机号
  74. if (r.data.user.phone == '') {
  75. wx.hideLoading();
  76. app.globalData.phone = false;//没有手机号
  77. that.setData({
  78. phoneFlag: true,
  79. })
  80. designTimer = setTimeout(() => {
  81. that.setData({
  82. designPlan: true
  83. })
  84. }, 3000)
  85. that.buildProgress();
  86. } else {
  87. app.globalData.phone = true;//有手机号
  88. that.setData({
  89. phoneFlag: false,
  90. })
  91. var obj = {
  92. detail: 1
  93. }
  94. that.buildProgress(obj);
  95. }
  96. } else {
  97. wx.hideLoading();
  98. that.setData({
  99. loginFlag: true,
  100. phoneFlag: true
  101. })
  102. }
  103. } else {
  104. setTimeout(function () {
  105. wx.hideLoading()
  106. }, 500)
  107. }
  108. }
  109. })
  110. }
  111. }
  112. })
  113. },
  114. sharecompany: function () {
  115. const that = this;
  116. utils.$post({
  117. url: app.globalData.webUrl + 'client/index/content_belong_company',
  118. header: {
  119. 'Authorization': 'bearer ' + app.globalData.token
  120. },
  121. data: {
  122. client_type: app.globalData.clientype,
  123. uid: app.globalData.shareuserid
  124. },
  125. success: function (res) {
  126. if (res.data.code == '0') {
  127. app.globalData.companyobj=res.data.data;
  128. app.globalData.currentUserId = res.data.data.employee_id;
  129. that.setData({
  130. companyobj: res.data.data
  131. })
  132. }
  133. },
  134. complete(res) {
  135. wx.hideLoading()
  136. }
  137. })
  138. },
  139. buildProgress() {
  140. var that = this;
  141. utils.$get({
  142. url: app.globalData.webUrl + 'client/building/progress_detail',
  143. header: {
  144. 'Authorization': 'bearer ' + app.globalData.token
  145. },
  146. data: {
  147. id: that.data.cid,
  148. },
  149. success: function (res) {
  150. if (res.data.code == '0') {
  151. wx.setNavigationBarTitle({
  152. title: res.data.data.building_name,
  153. })
  154. that.setData({
  155. detail: res.data.data
  156. })
  157. } else {
  158. wx.showToast({
  159. title: res.data.msg,
  160. icon: 'none',
  161. duration: 1500
  162. })
  163. }
  164. }
  165. })
  166. },
  167. previewImage(e) {
  168. wx.previewImage({
  169. current: e.currentTarget.dataset.img,
  170. urls: this.data.detail.img,
  171. })
  172. },
  173. openVRLink(e) {
  174. let vrlink = e.currentTarget.dataset.vr;
  175. wx.navigateTo({
  176. url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&uid=' + app.globalData.shareuserid + '&cty=building' + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.detail.id,
  177. })
  178. },
  179. visitimefun() {
  180. const that = this;
  181. utils.$post({
  182. url: app.globalData.webUrl + 'client/index/visit_due_time',
  183. header: {
  184. 'Authorization': 'bearer ' + app.globalData.token
  185. },
  186. data: {
  187. id: that.data.cid,
  188. pipe_type: 'progressDetail',
  189. time: time,
  190. },
  191. success: function (res) {
  192. console.log(res, time, '<<<')
  193. }
  194. })
  195. },
  196. closeDesigntap(e) {
  197. if (designTimer) {
  198. clearTimeout(designTimer);
  199. }
  200. if (e.detail.type == 'success') {
  201. this.setData({
  202. designPlan: false
  203. })
  204. } else {
  205. this.setData({
  206. designPlan: false
  207. })
  208. }
  209. },
  210. /**
  211. * 生命周期函数--监听页面初次渲染完成
  212. */
  213. onReady() {
  214. },
  215. /**
  216. * 生命周期函数--监听页面显示
  217. */
  218. onShow() {
  219. time = 0;
  220. setInterval(() => {
  221. time++;
  222. }, 1000)
  223. },
  224. /**
  225. * 生命周期函数--监听页面隐藏
  226. */
  227. onHide() {
  228. this.visitimefun();
  229. },
  230. /**
  231. * 生命周期函数--监听页面卸载
  232. */
  233. onUnload() {
  234. this.visitimefun();
  235. },
  236. /**
  237. * 页面相关事件处理函数--监听用户下拉动作
  238. */
  239. onPullDownRefresh() {
  240. },
  241. /**
  242. * 页面上拉触底事件的处理函数
  243. */
  244. onReachBottom() {
  245. },
  246. /**
  247. * 用户点击右上角分享
  248. */
  249. // onShareAppMessage() {
  250. // }
  251. })