constructsite.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. var app = getApp();
  2. var utils = require("../../../utils/http");
  3. let time = 0;
  4. var timer = null;
  5. var designTimer = null;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. top: app.globalData.statusBarHeight,
  12. hgt: app.globalData.titleBarHeight,
  13. siteobj: {},
  14. cid: '',
  15. companyName: '',
  16. scrollTop: 0,
  17. canIUseGetUserProfile: false,
  18. loadflag: false,
  19. shareobj: {},
  20. employeeflag: false,//false是用户,true是员工
  21. companyobj: {},
  22. loginFlag: false,
  23. phoneFlag: false,
  24. showAction: false,
  25. type:'',
  26. designPlan: false
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. var that = this;
  33. time = 0;
  34. if(options.type){
  35. this.setData({
  36. type:options.type
  37. })
  38. }
  39. if (wx.getUserProfile) {
  40. this.setData({
  41. canIUseGetUserProfile: true
  42. })
  43. }
  44. wx.showLoading({
  45. title: '加载中...',
  46. })
  47. that.setData({
  48. top: app.globalData.statusBarHeight,
  49. hgt: app.globalData.titleBarHeight,
  50. })
  51. wx.hideHomeButton()
  52. if (!!options.scene) {
  53. options = unescape(options.scene);
  54. let arr = options.split('&');
  55. let obj = {};
  56. for (let i = 0; i < arr.length; i++) {
  57. let arr1 = arr[i].split('=');
  58. obj[arr1[0]] = arr1[1];
  59. }
  60. this.setData({
  61. cid: obj.cid,
  62. shareuserid: obj.uid,
  63. customerFlag: true
  64. })
  65. app.globalData.clientype = obj.ctp;
  66. app.globalData.shareuserid = obj.uid;
  67. } else {
  68. this.setData({
  69. cid: options.cid,
  70. shareuserid: options.uid,
  71. customerFlag: true
  72. })
  73. app.globalData.clientype = options.ctp;
  74. app.globalData.shareuserid = options.uid;
  75. }
  76. this.login();
  77. },
  78. sharecompany: function () {
  79. const that = this;
  80. utils.$post({
  81. url: app.globalData.webUrl + 'client/index/content_belong_company',
  82. header: {
  83. 'Authorization': 'bearer ' + app.globalData.token
  84. },
  85. data: {
  86. client_type: app.globalData.clientype,
  87. uid: app.globalData.shareuserid
  88. },
  89. success: function (res) {
  90. if (res.data.code == '0') {
  91. app.globalData.companyobj=res.data.data;
  92. app.globalData.currentUserId = res.data.data.employee_id;
  93. that.setData({
  94. companyobj: res.data.data
  95. })
  96. }
  97. },
  98. complete(res) {
  99. wx.hideLoading()
  100. }
  101. })
  102. },
  103. login: function () {
  104. var that = this;
  105. wx.login({
  106. success: function (data) {
  107. if (data.errMsg == 'login:ok') {
  108. utils.$post({
  109. url: app.globalData.webUrl + 'api/users/code2session',
  110. data: {
  111. code: data.code,
  112. share: app.globalData.shareuserid,
  113. client_type:app.globalData.clientype
  114. },
  115. success: function (r) {
  116. if (r.data.code == '0') {
  117. app.globalData.sharepersonobj = r.data.share;
  118. app.globalData.token = r.data.token;
  119. that.setData({
  120. shareobj: app.globalData.sharepersonobj,
  121. companyName: r.data.company
  122. })
  123. that.sharecompany();
  124. 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 != '游客')) {
  125. that.setData({
  126. loginFlag: false,
  127. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  128. })
  129. app.globalData.personMsg = r.data.user;
  130. app.globalData.userflag = false; //有个人信息
  131. var nickname = r.data.user.nickname;
  132. var phone = r.data.user.phone;
  133. app.globalData.phone = false; //没有手机号
  134. if (r.data.user.phone == '') {
  135. that.setData({
  136. phoneFlag: false,
  137. mobileflag: true
  138. })
  139. wx.hideLoading();
  140. app.globalData.phone = false; //没有手机号
  141. } else {
  142. that.setData({
  143. mobileflag: false,
  144. phoneFlag: false
  145. })
  146. app.globalData.phone = true; //有手机号
  147. }
  148. } else {
  149. wx.hideLoading();
  150. that.setData({
  151. loginFlag: true,
  152. phoneFlag: false
  153. })
  154. }
  155. setTimeout(function () {
  156. wx.hideLoading()
  157. }, 500)
  158. that.houseinfofun();
  159. } else {
  160. that.setData({
  161. phoneFlag: false
  162. })
  163. that.houseinfofun();
  164. setTimeout(function () {
  165. wx.hideLoading()
  166. }, 500)
  167. }
  168. }
  169. })
  170. }
  171. }
  172. })
  173. },
  174. cancelGetPhone() {
  175. designTimer = setTimeout(() => {
  176. this.setData({
  177. designPlan: true
  178. })
  179. },4000)
  180. },
  181. houseinfofun() {
  182. const that = this;
  183. utils.$post({
  184. url: app.globalData.webUrl + 'client/construction/view',
  185. header: {
  186. 'Authorization': 'bearer ' + app.globalData.token
  187. },
  188. data: {
  189. id: that.data.cid
  190. },
  191. success: function (res) {
  192. if (res.data.code == '0') {
  193. that.setData({
  194. siteobj: res.data.data
  195. })
  196. }
  197. setTimeout(function () {
  198. wx.hideLoading();
  199. }, 500)
  200. }
  201. })
  202. },
  203. /**
  204. * 生命周期函数--监听页面初次渲染完成
  205. */
  206. onReady: function () {
  207. },
  208. openVRLink(e) {
  209. let type = e.currentTarget.dataset.type;
  210. let vrlink = escape(e.currentTarget.dataset.vr);
  211. wx.navigateTo({
  212. url: '/pages/other/other?type=vr&vrurl=' + vrlink + '&uid=' + (app.globalData.shareuserid?app.globalData.shareuserid:app.globalData.personMsg.id) + '&cty=construction' + '&ctp=' + app.globalData.clientype + '&aid=' + this.data.cid,
  213. })
  214. },
  215. prelooktap() {
  216. if (!app.globalData.sharepersonobj.qrcode) {
  217. wx.showToast({
  218. title: "当前专属客服的二维码为空!",
  219. icon: 'none',
  220. duration: 2000
  221. })
  222. return false;
  223. }
  224. wx.previewImage({
  225. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  226. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  227. })
  228. },
  229. /**
  230. * 前往个人名片
  231. */
  232. toPageNameCard() {
  233. wx.navigateTo({
  234. url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share',
  235. })
  236. },
  237. /**
  238. * 关闭免费设计方案弹窗
  239. */
  240. closeDesigntap(e) {
  241. if (designTimer) {
  242. clearTimeout(designTimer);
  243. }
  244. if (e.detail.type == 'success') {
  245. this.setData({
  246. designPlan: false
  247. })
  248. } else {
  249. this.setData({
  250. designPlan: false
  251. })
  252. }
  253. },
  254. operateBtn() {
  255. this.setData({
  256. showAction: false
  257. })
  258. },
  259. callphonetap: function () {
  260. wx.makePhoneCall({
  261. phoneNumber: app.globalData.sharepersonobj.phone
  262. })
  263. },
  264. golastap: function () {
  265. let arr = getCurrentPages();
  266. wx.navigateBack()
  267. },
  268. goindextap: function () {
  269. wx.reLaunch({
  270. url: '/pages/index/index?state=1',
  271. })
  272. },
  273. getPhoneNumberTap: function (res) {
  274. var that = this;
  275. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  276. that.setData({
  277. phoneFlag: false,
  278. })
  279. utils.$post({
  280. url: app.globalData.webUrl + 'api/users/setUserMobile',
  281. data: {
  282. encryptedData: res.detail.encryptedData,
  283. iv: res.detail.iv
  284. },
  285. header: {
  286. 'Authorization': 'bearer ' + app.globalData.token
  287. },
  288. success: function (r) {
  289. if (r.data.code == '0') {
  290. app.globalData.phone = true;
  291. that.setData({
  292. phoneFlag: false,
  293. })
  294. }
  295. }
  296. })
  297. }
  298. },
  299. looktap(e) {
  300. wx.previewImage({
  301. current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接
  302. urls: this.data.siteobj.step_list[e.currentTarget.dataset.idx].data.img // 需要预览的图片 http 链接列表
  303. })
  304. },
  305. /**
  306. * 生命周期函数--监听页面显示
  307. */
  308. onShow: function () {
  309. timer = setInterval(function () {
  310. time = time * 1 + 1;
  311. }, 1000)
  312. },
  313. /**
  314. * 生命周期函数--监听页面隐藏
  315. */
  316. onHide: function () {
  317. if (designTimer) {
  318. clearTimeout(designTimer);
  319. }
  320. if (timer) {
  321. clearInterval(timer)
  322. }
  323. this.visitimefun();
  324. },
  325. visitimefun() {
  326. const that = this;
  327. utils.$post({
  328. url: app.globalData.webUrl + 'client/index/visit_due_time',
  329. header: {
  330. 'Authorization': 'bearer ' + app.globalData.token
  331. },
  332. data: {
  333. id: that.data.cid,
  334. pipe_type: 'Construction',
  335. time: time,
  336. },
  337. success: function (res) {
  338. }
  339. })
  340. },
  341. /**
  342. * 生命周期函数--监听页面卸载
  343. */
  344. onUnload: function () {
  345. if (designTimer) {
  346. clearTimeout(designTimer);
  347. }
  348. this.visitimefun();
  349. },
  350. /**
  351. * 页面相关事件处理函数--监听用户下拉动作
  352. */
  353. onPullDownRefresh: function () {
  354. },
  355. /**
  356. * 页面上拉触底事件的处理函数
  357. */
  358. onReachBottom: function () {
  359. },
  360. /**
  361. * 用户点击右上角分享
  362. */
  363. onShareAppMessage: function () {
  364. return {
  365. title: that.data.siteobj.name,
  366. imageUrl: that.data.siteobj.cover,
  367. path: '/share/pages/constructsite/constructsite?cid=' + that.data.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  368. }
  369. }
  370. })