designermsg.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. const app = getApp();
  2. var utils = require("../../../utils/http"),
  3. page = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. imgUrl: app.globalData.imgUrl,
  10. top: app.globalData.statusBarHeight,
  11. hgt: app.globalData.titleBarHeight,
  12. isShow: false,
  13. designerId: '',
  14. designId: '',
  15. designerobj: {},
  16. caselist: [],
  17. loginFlag: true, //false是没有个人信息
  18. phoneflag: false, //true有手机号
  19. caseallshow: false,
  20. companyobj: {},
  21. shareobj: {},
  22. employeeflag: false, //false是用户,true是员工
  23. type: ''
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. wx.hideHomeButton();
  30. this.setData({
  31. imgUrl: app.globalData.imgUrl,
  32. top: app.globalData.statusBarHeight,
  33. hgt: app.globalData.titleBarHeight,
  34. designerId: options.did,
  35. designId: options.did,
  36. })
  37. if (!!options.type) {
  38. this.setData({
  39. phoneflag: app.globalData.phone,
  40. type: options.type
  41. })
  42. } else {
  43. if (wx.getUserProfile) {
  44. this.setData({
  45. canIUseGetUserProfile: true
  46. })
  47. }
  48. app.globalData.clientype = options.ctp;
  49. app.globalData.shareuserid = options.uid;
  50. }
  51. },
  52. //用户同意隐私协议
  53. agreePrivacy() {
  54. wx.showLoading({
  55. title: '加载中...',
  56. })
  57. this.login();
  58. },
  59. sharecompany: function () {
  60. const that = this;
  61. utils.$post({
  62. url: app.globalData.webUrl + 'client/index/content_belong_company',
  63. header: {
  64. 'Authorization': 'bearer ' + app.globalData.token
  65. },
  66. data: {
  67. client_type: app.globalData.clientype,
  68. uid: app.globalData.shareuserid
  69. },
  70. success: function (res) {
  71. if (res.data.code == '0') {
  72. app.globalData.companyobj=res.data.data;
  73. that.setData({
  74. companyobj: res.data.data
  75. })
  76. }
  77. },
  78. complete(res) {
  79. wx.hideLoading()
  80. }
  81. })
  82. },
  83. login: function () {
  84. var that = this;
  85. wx.login({
  86. success: function (data) {
  87. if (data.errMsg == 'login:ok') {
  88. utils.$post({
  89. url: app.globalData.webUrl + 'api/users/code2session',
  90. data: {
  91. code: data.code,
  92. share: app.globalData.shareuserid,
  93. client_type:app.globalData.clientype
  94. },
  95. success: function (r) {
  96. if (r.data.code == '0') {
  97. app.globalData.sharepersonobj = r.data.share;
  98. app.globalData.token = r.data.token;
  99. that.setData({
  100. shareobj: app.globalData.sharepersonobj,
  101. })
  102. that.sharecompany();
  103. if (r.data.share) {
  104. app.globalData.vrString = r.data.share.str;
  105. }
  106. app.globalData.companyname=r.data.company;
  107. app.globalData.official_openid = r.data.official_openid;
  108. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  109. app.globalData.personMsg = r.data.user;
  110. if (!!r.data.user.phone) {
  111. that.setData({
  112. loginFlag: true,
  113. phoneflag: true,
  114. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  115. })
  116. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  117. app.globalData.currentUserId = r.data.user.binded.id;
  118. }
  119. that.designermsg();
  120. } else {
  121. that.designermsg();
  122. that.setData({
  123. loginFlag: true,
  124. phoneflag: false
  125. })
  126. }
  127. setTimeout(function () {
  128. wx.hideLoading()
  129. }, 500)
  130. } else {
  131. wx.hideLoading()
  132. }
  133. }
  134. })
  135. }
  136. }
  137. })
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. otherlistfun() {
  145. this.setData({
  146. caseallshow: true
  147. })
  148. },
  149. designermsg() {
  150. const that = this;
  151. utils.$post({
  152. url: app.globalData.webUrl + 'client/designer/designer_read',
  153. header: {
  154. 'Authorization': 'bearer ' + app.globalData.token
  155. },
  156. data: {
  157. id: that.data.designerId
  158. },
  159. success: function (res) {
  160. that.setData({
  161. loginFlag:true
  162. })
  163. if (res.data.code == "0") {
  164. that.setData({
  165. designerobj: res.data.data
  166. })
  167. }
  168. wx.hideLoading()
  169. }
  170. })
  171. this.casefun();
  172. },
  173. casefun() {
  174. const that = this;
  175. page = 1;
  176. utils.$post({
  177. url: app.globalData.webUrl + 'client/designer/designer_case_list',
  178. header: {
  179. 'Authorization': 'bearer ' + app.globalData.token
  180. },
  181. data: {
  182. id: that.data.designId,
  183. page: 1,
  184. limit: 10,
  185. },
  186. success: function (res) {
  187. if (res.data.code == "0") {
  188. that.setData({
  189. caselist: res.data.data
  190. })
  191. }
  192. wx.hideLoading()
  193. }
  194. })
  195. },
  196. golastap: function () {
  197. wx.navigateBack({
  198. delta: 1,
  199. success:function(r){
  200. },
  201. fail:function(r){
  202. wx.reLaunch({
  203. url: '/pages/index/index?state=1',
  204. })
  205. },
  206. })
  207. },
  208. goindextap: function () {
  209. if(!this.data.employeeflag){
  210. wx.reLaunch({
  211. url: '/pages/index/index?state=1',
  212. })
  213. }else{
  214. wx.reLaunch({
  215. url: '/pages/consoledesk/consoledesk',
  216. })
  217. }
  218. },
  219. openVRLink(e) {
  220. let vrlink = e.currentTarget.dataset.vrlink;
  221. let id = e.currentTarget.dataset.id;
  222. wx.navigateTo({
  223. url: '/pages/other/other?type=vr&vrurl=' + escape(vrlink) + '&cty=materialCase' + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype + '&aid=' + id,
  224. })
  225. },
  226. apointap: function (e) {
  227. if (this.data.designerobj.make == 1) {
  228. wx.showToast({
  229. title: '不能重复预约!',
  230. icon: 'none',
  231. duration: 2000
  232. })
  233. return false;
  234. }
  235. const that = this;
  236. utils.$post({
  237. url: app.globalData.webUrl + 'client/designer/designer_make',
  238. header: {
  239. 'Authorization': 'bearer ' + app.globalData.token
  240. },
  241. data: {
  242. designer_id: that.data.designerobj.designer_id,
  243. designer_name: that.data.designerobj.name,
  244. share_uid: app.globalData.shareuserid
  245. },
  246. success: function (res) {
  247. if (res.data.code == "0") {
  248. let designerobj = that.data.designerobj;
  249. designerobj.make = 1;
  250. that.setData({
  251. designerobj: designerobj
  252. })
  253. wx.showToast({
  254. title: res.data.msg,
  255. icon: 'none',
  256. duration: 2000
  257. })
  258. }
  259. }
  260. })
  261. },
  262. loginfun() {
  263. var that = this;
  264. wx.login({
  265. success: function (data) {
  266. if (data.errMsg == 'login:ok') {
  267. utils.$post({
  268. url: app.globalData.webUrl + 'api/users/code2session',
  269. data: {
  270. code: data.code,
  271. share: app.globalData.shareuserid,
  272. client_type:app.globalData.clientype
  273. },
  274. success: function (r) {
  275. if (r.data.code == '0') {
  276. app.globalData.sharepersonobj = r.data.share;
  277. app.globalData.token = r.data.token;
  278. if (!!r.data.user.phone) {
  279. that.setData({
  280. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false
  281. })
  282. app.globalData.personMsg = r.data.user;
  283. app.globalData.use_id = r.data.user.id;
  284. app.globalData.userflag = false;//有个人信息
  285. }
  286. }
  287. }
  288. })
  289. }
  290. }
  291. })
  292. },
  293. getUserInfoTap: function (res) {
  294. var that = this;
  295. wx.showLoading();
  296. if (res.detail.errMsg == 'getUserInfo:ok') {
  297. utils.$post({
  298. method: "POST", //TESTAPIURL APIURL/users/auth
  299. url: app.globalData.webUrl + 'api/users/setUserInfo',
  300. data: {
  301. encryptedData: res.detail.encryptedData,
  302. iv: res.detail.iv,
  303. rawData: res.detail.rawData,
  304. signature: res.detail.signature,
  305. },
  306. header: {
  307. 'Authorization': 'bearer ' + app.globalData.token
  308. },
  309. success: function (r) {
  310. if (r.data.code == '0') {
  311. that.loginfun();
  312. that.setData({
  313. loginFlag: true,
  314. phoneflag: false
  315. })
  316. app.globalData.userflag = true; //有个人信息
  317. } else {
  318. if (r.data.code == '403') {
  319. that.login();
  320. return false
  321. }
  322. wx.showToast({
  323. title: r.data.msg,
  324. icon: "none",
  325. duration: 2000
  326. });
  327. }
  328. }
  329. })
  330. }
  331. },
  332. getUserProfile: function () {
  333. var that = this;
  334. wx.getUserProfile({
  335. lang: 'zh_CN',
  336. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  337. success: (res) => {
  338. if (res.errMsg == "getUserProfile:ok") {
  339. wx.showLoading();
  340. utils.$post({
  341. method: "POST", //TESTAPIURL APIURL/users/auth
  342. url: app.globalData.webUrl + 'api/users/setUserInfo',
  343. data: {
  344. encryptedData: res.encryptedData,
  345. iv: res.iv,
  346. rawData: res.rawData,
  347. signature: res.signature,
  348. },
  349. header: {
  350. 'Authorization': 'bearer ' + app.globalData.token
  351. },
  352. success: function (r) {
  353. setTimeout(res => {
  354. wx.hideLoading()
  355. }, 500)
  356. if (r.data.code == '0') {
  357. that.loginfun();
  358. that.setData({
  359. loginFlag: true,
  360. phoneflag: false
  361. })
  362. app.globalData.userflag = true; //有个人信息
  363. } else {
  364. if (r.data.code == '403') {
  365. that.login();
  366. return false
  367. }
  368. wx.showToast({
  369. title: r.data.msg,
  370. icon: "none",
  371. duration: 2000
  372. });
  373. }
  374. }
  375. })
  376. }
  377. }
  378. })
  379. },
  380. getPhoneNumberTap: function (res) {
  381. var that = this;
  382. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  383. utils.$post({
  384. url: app.globalData.webUrl + 'api/users/setUserMobile',
  385. data: {
  386. encryptedData: res.detail.encryptedData,
  387. iv: res.detail.iv
  388. },
  389. header: {
  390. 'Authorization': 'bearer ' + app.globalData.token
  391. },
  392. success: function (r) {
  393. if (r.data.code == '0') {
  394. // wx.showLoading({
  395. // title: '加载中',
  396. // })
  397. app.globalData.phone = true;
  398. that.setData({
  399. phoneflag: true
  400. })
  401. that.apointap(res);
  402. } else {
  403. that.setData({
  404. errorText: r.data.msg,
  405. errorflag: true
  406. })
  407. }
  408. }
  409. })
  410. }
  411. },
  412. casemsgtap: function (e) {
  413. wx.navigateTo({
  414. url: '/share/pages/materialcase/materialcase?type=3&cid=' + e.currentTarget.dataset.sid + '&uid=' + app.globalData.shareuserid + '&ctp=' + app.globalData.clientype
  415. })
  416. },
  417. showdesctap() {
  418. this.setData({
  419. isShow: this.data.isShow ? false : true
  420. })
  421. },
  422. /**
  423. * 生命周期函数--监听页面显示
  424. */
  425. onShow: function () {
  426. page = 1;
  427. this.setData({
  428. top: app.globalData.statusBarHeight,
  429. hgt: app.globalData.titleBarHeight,
  430. phoneflag: app.globalData.phone
  431. })
  432. },
  433. /**
  434. * 生命周期函数--监听页面隐藏
  435. */
  436. onHide: function () {
  437. },
  438. /**
  439. * 生命周期函数--监听页面卸载
  440. */
  441. onUnload: function () {
  442. },
  443. /**
  444. * 页面相关事件处理函数--监听用户下拉动作
  445. */
  446. onPullDownRefresh: function () {
  447. },
  448. /**
  449. * 页面上拉触底事件的处理函数
  450. */
  451. onReachBottom: function () {
  452. const that = this;
  453. page = page * 1 + 1;
  454. utils.$post({
  455. url: app.globalData.webUrl + 'client/designer/designer_case_list',
  456. header: {
  457. 'Authorization': 'bearer ' + app.globalData.token
  458. },
  459. data: {
  460. id: that.data.designId,
  461. page: page,
  462. limit: 10,
  463. },
  464. success: function (res) {
  465. let caselist = that.data.caselist;
  466. if (res.data.code == "0") {
  467. caselist = caselist.concat(res.data.data);
  468. that.setData({
  469. caselist: caselist
  470. })
  471. }
  472. wx.hideLoading()
  473. }
  474. })
  475. },
  476. /**
  477. * 用户点击右上角分享
  478. */
  479. onShareAppMessage: function () {
  480. return {
  481. title: app.globalData.companyobj.company_name + '设计师:' + this.data.designerobj.name,
  482. imageUrl: app.globalData.imgUrl + "xcx/designerlisticon.jpg",
  483. path: '/share/pages/designermsg/designermsg?uid=' + app.globalData.shareuserid + '&did=' + this.data.designId + '&ctp=' + app.globalData.clientype
  484. }
  485. }
  486. })