designermsg.js 17 KB

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