constructsite.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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/code2sessionmini',
  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.share) {
  125. app.globalData.vrString = r.data.share.str;
  126. }
  127. app.globalData.personMsg = r.data.user;
  128. app.globalData.companyname=r.data.company;
  129. app.globalData.official_openid = r.data.official_openid;
  130. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  131. if (!!r.data.user.phone) {
  132. that.setData({
  133. loginFlag: false,
  134. phoneFlag: false,
  135. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  136. })
  137. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  138. app.globalData.currentUserId = r.data.user.binded.id;
  139. }
  140. app.globalData.personMsg = r.data.user;
  141. app.globalData.userflag = false; //有个人信息
  142. var nickname = r.data.user.nickname;
  143. var phone = r.data.user.phone;
  144. app.globalData.phone = false; //没有手机号
  145. that.houseinfofun();
  146. } else {
  147. that.houseinfofun();
  148. that.setData({
  149. loginFlag: false,
  150. phoneFlag: true
  151. })
  152. }
  153. setTimeout(function () {
  154. wx.hideLoading()
  155. }, 500)
  156. }
  157. }
  158. })
  159. }
  160. }
  161. })
  162. },
  163. cancelGetPhone() {
  164. designTimer = setTimeout(() => {
  165. this.setData({
  166. designPlan: true
  167. })
  168. },4000)
  169. },
  170. houseinfofun() {
  171. const that = this;
  172. utils.$post({
  173. url: app.globalData.webUrl + 'client/construction/view',
  174. header: {
  175. 'Authorization': 'bearer ' + app.globalData.token
  176. },
  177. data: {
  178. id: that.data.cid
  179. },
  180. success: function (res) {
  181. if (res.data.code == '0') {
  182. that.setData({
  183. siteobj: res.data.data
  184. })
  185. }
  186. setTimeout(function () {
  187. wx.hideLoading();
  188. }, 500)
  189. }
  190. })
  191. },
  192. /**
  193. * 生命周期函数--监听页面初次渲染完成
  194. */
  195. onReady: function () {
  196. },
  197. openVRLink(e) {
  198. let type = e.currentTarget.dataset.type;
  199. let vrlink = escape(e.currentTarget.dataset.vr);
  200. wx.navigateTo({
  201. 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,
  202. })
  203. },
  204. prelooktap() {
  205. if (!app.globalData.sharepersonobj.qrcode) {
  206. wx.showToast({
  207. title: "当前专属客服的二维码为空!",
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. return false;
  212. }
  213. wx.previewImage({
  214. current: app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode, // 当前显示图片的http链接
  215. urls: [app.globalData.imgUrl + app.globalData.sharepersonobj.qrcode]// 需要预览的图片http链接列表
  216. })
  217. },
  218. /**
  219. * 前往个人名片
  220. */
  221. toPageNameCard() {
  222. wx.navigateTo({
  223. url: '/share/pages/shareCard/shareCard?uid=' + app.globalData.shareuserid + '&empid=' + app.globalData.currentUserId + '&ctp=' + app.globalData.clientype + '&ftype=share',
  224. })
  225. },
  226. /**
  227. * 关闭免费设计方案弹窗
  228. */
  229. closeDesigntap(e) {
  230. if (designTimer) {
  231. clearTimeout(designTimer);
  232. }
  233. if (e.detail.type == 'success') {
  234. this.setData({
  235. designPlan: false
  236. })
  237. } else {
  238. this.setData({
  239. designPlan: false
  240. })
  241. }
  242. },
  243. operateBtn() {
  244. this.setData({
  245. showAction: false
  246. })
  247. },
  248. callphonetap: function () {
  249. wx.makePhoneCall({
  250. phoneNumber: app.globalData.sharepersonobj.phone
  251. })
  252. },
  253. golastap: function () {
  254. wx.navigateBack({
  255. delta: 1,
  256. success:function(r){
  257. },
  258. fail:function(r){
  259. wx.reLaunch({
  260. url: '/pages/index/index?state=1',
  261. })
  262. },
  263. })
  264. },
  265. goindextap: function () {
  266. if(!this.data.employeeflag){
  267. wx.reLaunch({
  268. url: '/pages/index/index?state=1',
  269. })
  270. }else{
  271. wx.reLaunch({
  272. url: '/pages/consoledesk/consoledesk',
  273. })
  274. }
  275. },
  276. getPhoneNumberTap: function (res) {
  277. var that = this;
  278. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  279. that.setData({
  280. phoneFlag: false,
  281. })
  282. utils.$post({
  283. url: app.globalData.webUrl + 'api/users/setUserMobile',
  284. data: {
  285. encryptedData: res.detail.encryptedData,
  286. iv: res.detail.iv
  287. },
  288. header: {
  289. 'Authorization': 'bearer ' + app.globalData.token
  290. },
  291. success: function (r) {
  292. if (r.data.code == '0') {
  293. app.globalData.phone = true;
  294. that.setData({
  295. phoneFlag: false,
  296. })
  297. }
  298. }
  299. })
  300. }
  301. },
  302. looktap(e) {
  303. wx.previewImage({
  304. current: e.currentTarget.dataset.img, // 当前显示图片的 http 链接
  305. urls: this.data.siteobj.step_list[e.currentTarget.dataset.idx].data.img // 需要预览的图片 http 链接列表
  306. })
  307. },
  308. /**
  309. * 生命周期函数--监听页面显示
  310. */
  311. onShow: function () {
  312. timer = setInterval(function () {
  313. time = time * 1 + 1;
  314. }, 1000)
  315. },
  316. /**
  317. * 生命周期函数--监听页面隐藏
  318. */
  319. onHide: function () {
  320. if (designTimer) {
  321. clearTimeout(designTimer);
  322. }
  323. if (timer) {
  324. clearInterval(timer)
  325. }
  326. this.visitimefun();
  327. },
  328. visitimefun() {
  329. const that = this;
  330. utils.$post({
  331. url: app.globalData.webUrl + 'client/index/visit_due_time',
  332. header: {
  333. 'Authorization': 'bearer ' + app.globalData.token
  334. },
  335. data: {
  336. id: that.data.cid,
  337. pipe_type: 'Construction',
  338. time: time,
  339. },
  340. success: function (res) {
  341. }
  342. })
  343. },
  344. /**
  345. * 生命周期函数--监听页面卸载
  346. */
  347. onUnload: function () {
  348. if (designTimer) {
  349. clearTimeout(designTimer);
  350. }
  351. this.visitimefun();
  352. },
  353. /**
  354. * 页面相关事件处理函数--监听用户下拉动作
  355. */
  356. onPullDownRefresh: function () {
  357. },
  358. /**
  359. * 页面上拉触底事件的处理函数
  360. */
  361. onReachBottom: function () {
  362. },
  363. /**
  364. * 用户点击右上角分享
  365. */
  366. onShareAppMessage: function () {
  367. return {
  368. title: that.data.siteobj.name,
  369. imageUrl: that.data.siteobj.cover_share_img?that.data.siteobj.cover_share_img:that.data.siteobj.cover,
  370. path: '/share/pages/constructsite/constructsite?cid=' + that.data.cid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  371. }
  372. }
  373. })