constructsite.js 12 KB

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