designermsg.js 17 KB

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