collagemsg.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. const app = getApp();
  2. var utils = require("../../../utils/http"),
  3. page = 1;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. countDownTime: 0,
  10. teamOrderNum: 0,
  11. imgUrl: app.globalData.imgUrl,
  12. defaultButtons: [{
  13. text: '知道了',
  14. extClass: 'color28A1FF'
  15. }],
  16. buttons: [{
  17. text: '拨打电话',
  18. extClass: 'color28A1FF'
  19. }],
  20. buttonarr: [{
  21. text: '取消',
  22. extClass: 'colorccc'
  23. },
  24. {
  25. text: '拨打电话',
  26. extClass: 'color28A1FF'
  27. }
  28. ],
  29. canIUseGetUserProfile: false,
  30. empid: '', //分享员工的id
  31. teamid: '',//团队id
  32. myTeamId: '',//我的团队
  33. collagemsg: {},
  34. userCollage: {},
  35. loginFlag: true,
  36. phoneFlag: false,
  37. canIUseGetUserProfile: false,
  38. articlelogin: true,
  39. collageflag: false,
  40. endshow: false,
  41. attendflag: false,
  42. haveFull: false,
  43. nowspellground_id: '',
  44. nowteam_id: '',
  45. clientype: '',
  46. empdata: {},
  47. spellsucesfalg: false,
  48. timeoutflag: false,
  49. companyobj: {},
  50. teamPerson: [],
  51. top: app.globalData.statusBarHeight,
  52. hgt: app.globalData.titleBarHeight,
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad(options) {
  58. var that = this;
  59. // wx.hideHomeButton();
  60. if (wx.getUserProfile) {
  61. this.setData({
  62. canIUseGetUserProfile: true
  63. })
  64. }
  65. wx.showLoading({
  66. title: '加载中...',
  67. })
  68. if (!!options.scene) {
  69. options = unescape(options.scene);
  70. let arr = options.split('&');
  71. let obj = {};
  72. for (let i = 0; i < arr.length; i++) {
  73. let arr1 = arr[i].split('=');
  74. obj[arr1[0]] = arr1[1];
  75. }
  76. if (!!obj.e) {
  77. app.globalData.currentUserId = obj.e;
  78. this.setData({
  79. empid: obj.e, //分享拼团员工的id
  80. })
  81. }
  82. if (!!obj.t) {
  83. this.setData({
  84. teamid: obj.t, //团队id
  85. })
  86. }
  87. if (!!obj.p) {
  88. this.setData({
  89. clientype: obj.p
  90. })
  91. app.globalData.clientype = obj.p;
  92. }
  93. if (!!obj.u) {
  94. app.globalData.shareuserid = obj.u;
  95. }
  96. } else {
  97. if (!!options.uid) {
  98. app.globalData.shareuserid = options.uid;
  99. }
  100. if (!!options.empid) {
  101. app.globalData.currentUserId = options.empid;
  102. this.setData({
  103. empid: options.empid, //分享拼团员工的id
  104. })
  105. }
  106. if (!!options.teamid) {
  107. this.setData({
  108. teamid: options.teamid, //团队id
  109. })
  110. }
  111. if (!!options.clientype) {
  112. this.setData({
  113. clientype: options.clientype
  114. })
  115. app.globalData.clientype = options.clientype;
  116. }
  117. }
  118. this.logindata();
  119. wx.hideShareMenu({
  120. menus: ['shareAppMessage', 'shareTimeline']
  121. })
  122. },
  123. sharecompany: function () {
  124. const that = this;
  125. utils.$post({
  126. url: app.globalData.webUrl + 'client/index/content_belong_company',
  127. header: {
  128. 'Authorization': 'bearer ' + app.globalData.token
  129. },
  130. data: {
  131. client_type: app.globalData.clientype,
  132. uid: app.globalData.shareuserid
  133. },
  134. success: function (res) {
  135. if (res.data.code == '0') {
  136. app.globalData.companyobj=res.data.data;
  137. that.setData({
  138. companyobj: res.data.data
  139. })
  140. }
  141. },
  142. complete(res) {
  143. wx.hideLoading()
  144. }
  145. })
  146. },
  147. lookcovertap() {
  148. wx.previewImage({
  149. current: this.data.collagemsg.cover, // 当前显示图片的http链接
  150. urls: [this.data.collagemsg.cover] // 需要预览的图片http链接列表
  151. })
  152. },
  153. golastap: function () {
  154. let arr = getCurrentPages();
  155. if (arr.length == 1) {
  156. wx.reLaunch({
  157. url: '/pages/index/index?state=1',
  158. })
  159. } else {
  160. wx.reLaunch({
  161. url: '/pages/index/index?state=1',
  162. })
  163. }
  164. },
  165. goindextap: function () {
  166. wx.reLaunch({
  167. url: '/pages/index/index?state=1',
  168. })
  169. },
  170. logindata: function () {
  171. var that = this;
  172. wx.showLoading();
  173. wx.login({
  174. success: function (data) {
  175. if (data.errMsg == 'login:ok') {
  176. utils.$post({
  177. url: app.globalData.webUrl + 'api/users/code2session',
  178. data: {
  179. client_type: that.data.clientype,
  180. code: data.code,
  181. share: app.globalData.shareuserid
  182. },
  183. success: function (r) {
  184. if (r.data.code == '0') {
  185. app.globalData.sharepersonobj = r.data.share;
  186. app.globalData.token = r.data.token;
  187. that.sharecompany();
  188. that.collagefun();
  189. 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 != '游客')) {
  190. app.globalData.use_id = r.data.user.id;
  191. app.globalData.personMsg = r.data.user;
  192. app.globalData.userflag = false; //有个人信息
  193. var nickname = r.data.user.nickname;
  194. var phone = r.data.user.phone;
  195. that.setData({
  196. loginFlag: true,
  197. datashow: true,
  198. })
  199. if (r.data.user.phone != '') {
  200. app.globalData.personMsg = r.data.user;
  201. that.setData({
  202. mobileflag: false
  203. })
  204. } else {
  205. that.setData({
  206. phoneFlag: true
  207. })
  208. }
  209. } else {
  210. wx.hideLoading();
  211. that.setData({
  212. articlelogin: false,
  213. loginFlag: false
  214. })
  215. }
  216. } else {
  217. wx.hideLoading();
  218. that.setData({
  219. articlelogin: false,
  220. loginFlag: true
  221. })
  222. }
  223. }
  224. })
  225. } else {
  226. wx.hideLoading();
  227. that.setData({
  228. articlelogin: false,
  229. loginFlag: true
  230. })
  231. }
  232. }
  233. })
  234. },
  235. /**
  236. * 获取拼团详情
  237. */
  238. collagefun: function () {
  239. let that = this;
  240. console.log(app.globalData.token)
  241. utils.$post({
  242. url: app.globalData.webUrl + 'api/spellgroup/sel_user_group',
  243. header: {
  244. 'Authorization': 'bearer ' + app.globalData.token
  245. },
  246. data: {
  247. empid: that.data.empid,
  248. teamid: that.data.teamid
  249. },
  250. success: function (res) {
  251. wx.stopPullDownRefresh();
  252. if (res.data.code == '0') {
  253. let data = res.data.data;
  254. let nowtime = new Date().getTime();
  255. if (data) {
  256. let countDownTime = data.surplus_time ? (new Date(data.surplus_time.replace(/-/g, "/")).getTime() - nowtime) : 0;
  257. that.setData({
  258. collagemsg: data.act_data,
  259. userCollage: data.user,
  260. countDownTime: countDownTime,
  261. teamid: data.user.teamid,
  262. teamPerson: data.team_mer,
  263. empdata: data.empdata || {},
  264. teamOrderNum: data.team_order_num,
  265. myTeamId: data.my_teamid
  266. })
  267. if (!!that.data.myTeamId && (that.data.userCollage.type == 5 || that.data.userCollage.type == 4)) {
  268. wx.showModal({
  269. title: '提示',
  270. content: '您名下已有正在进行的拼团,不能参加该拼团!',
  271. showCancel: false,
  272. confirmText: '知道了',
  273. success: (res) => {
  274. that.setData({
  275. teamid: that.data.myTeamId
  276. })
  277. that.collagefun();
  278. }
  279. })
  280. return false;
  281. }
  282. if (that.data.userCollage.type == 6) {
  283. that.setData({
  284. haveFull: true
  285. })
  286. }
  287. if (that.data.userCollage.type == 5) {
  288. that.setData({
  289. timeoutflag: true
  290. })
  291. }
  292. if (that.data.userCollage.type == 4) {
  293. that.setData({
  294. spellsucesfalg: true
  295. })
  296. }
  297. }
  298. wx.hideLoading();
  299. } else {
  300. wx.hideLoading();
  301. let msg = res.data.msg;
  302. setTimeout(() => {
  303. wx.showModal({
  304. title: '拼团提示',
  305. content: msg,
  306. showCancel: false,
  307. confirmText: '退出应用',
  308. success: () => {
  309. wx.exitMiniProgram();
  310. }
  311. })
  312. },1000)
  313. }
  314. }
  315. })
  316. },
  317. /**
  318. * 删除参与拼团的队员
  319. */
  320. delTeamItem(e) {
  321. let that = this;
  322. let id = e.currentTarget.dataset.id;
  323. wx.showModal({
  324. title: '提示',
  325. content: '确定删除当前队员吗?',
  326. cancelText: '取消',
  327. confirmText: '确定',
  328. success: (res) => {
  329. if (res.confirm) {
  330. utils.$post({
  331. url: app.globalData.webUrl + 'api/spellgroup/del_team_mer',
  332. header: {
  333. 'Authorization': 'bearer ' + app.globalData.token
  334. },
  335. data: {
  336. id: id,
  337. teamid: that.data.teamid
  338. },
  339. success: function (res) {
  340. if (res.data.code == '0') {
  341. that.collagefun();
  342. wx.showToast({
  343. title: '删除成功',
  344. icon: 'success'
  345. })
  346. }
  347. }
  348. })
  349. }
  350. },
  351. fail: (error) => { }
  352. })
  353. },
  354. tapDialogButton: function () {
  355. let that = this;
  356. if (that.data.empdata.phone) {
  357. that.setData({
  358. spellsucesfalg: false
  359. })
  360. wx.makePhoneCall({
  361. phoneNumber: that.data.empdata.phone,
  362. })
  363. } else {
  364. that.setData({
  365. spellsucesfalg: false
  366. })
  367. wx.showToast({
  368. title: '未返回电话号码',
  369. icon: 'none',
  370. duration:1000
  371. })
  372. }
  373. },
  374. activityendtap: function () {
  375. this.setData({
  376. endshow: true
  377. })
  378. },
  379. timeoutap: function (e) {
  380. let that = this;
  381. if (e.detail.index == 1) {
  382. if (!that.data.empdata.phone) {
  383. that.setData({
  384. timeoutflag: false
  385. })
  386. wx.showToast({
  387. title: '未返回电话号码',
  388. icon: 'none',
  389. duration: 1000
  390. });
  391. return;
  392. }
  393. wx.makePhoneCall({
  394. phoneNumber: that.data.empdata.phone,
  395. success: function (res) {
  396. that.setData({
  397. timeoutflag: false
  398. })
  399. },
  400. fail: function (err) {
  401. that.setData({
  402. timeoutflag: false
  403. })
  404. }
  405. })
  406. } else {
  407. that.setData({
  408. timeoutflag: false
  409. })
  410. }
  411. },
  412. closeDialog: function () {
  413. let that = this;
  414. if (that.data.empdata.phone) {
  415. that.setData({
  416. haveFull: false
  417. })
  418. wx.makePhoneCall({
  419. phoneNumber: that.data.empdata.phone,
  420. })
  421. } else {
  422. that.setData({
  423. haveFull: false
  424. })
  425. wx.showToast({
  426. title: '未返回电话号码',
  427. icon: 'none',
  428. duration:1000
  429. })
  430. }
  431. },
  432. colsendtap: function () {
  433. this.setData({
  434. endshow: false
  435. })
  436. wx.exitMiniProgram();
  437. },
  438. attendtap: function () {
  439. this.setData({
  440. attendflag: false
  441. })
  442. },
  443. attendbtnap: function () {
  444. this.setData({
  445. attendflag: true
  446. })
  447. return false;
  448. },
  449. /**
  450. * 开启拼团-加入拼团
  451. * @param {*} res
  452. */
  453. getPhoneNumberTap: function (res) {
  454. let that = this;
  455. if (!!that.data.myTeamId && (that.data.userCollage.type == 1 || that.data.userCollage.type == 3)) {
  456. wx.showModal({
  457. title: '提示',
  458. content: '您名下已有正在进行的拼团,不能参加该拼团!',
  459. showCancel: false,
  460. confirmText: '知道了',
  461. success: (res) => {
  462. that.setData({
  463. teamid: that.data.myTeamId
  464. })
  465. that.collagefun();
  466. }
  467. })
  468. return false;
  469. }
  470. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  471. utils.$post({
  472. url: app.globalData.webUrl + 'api/users/setUserMobile',
  473. data: {
  474. encryptedData: res.detail.encryptedData,
  475. iv: res.detail.iv
  476. },
  477. header: {
  478. 'Authorization': 'bearer ' + app.globalData.token
  479. },
  480. success: function (r) {
  481. if (r.data.code == '0') {
  482. app.globalData.phone = true;
  483. app.globalData.personMsg.phone = r.data.mobile;
  484. that.setData({
  485. endshow: false
  486. })
  487. if (res.currentTarget.dataset.type == 'join') {
  488. that.jointeam();
  489. }
  490. if (res.currentTarget.dataset.type == 'open') {
  491. that.openteam();
  492. }
  493. } else {
  494. wx.showToast({
  495. title: r.data.msg,
  496. icon: "none",
  497. duration: 2000
  498. });
  499. }
  500. }
  501. })
  502. }
  503. },
  504. /***
  505. * 加入拼团
  506. */
  507. jointeam: function () {
  508. let that = this;
  509. utils.$post({
  510. url: app.globalData.webUrl + 'api/spellgroup/join_team',
  511. header: {
  512. 'Authorization': 'bearer ' + app.globalData.token
  513. },
  514. data: {
  515. empid: that.data.empid,
  516. teamid: that.data.teamid
  517. },
  518. success: function (res) {
  519. console.log(res)
  520. //1->活动下架,2->已参加过,3->拼团人数已满,4->拼团时限结束,0->拼团成功
  521. if (res.data.code == '0') {
  522. wx.showToast({
  523. title: '已成功加入拼团',
  524. icon: 'none',
  525. duration: 1500
  526. })
  527. that.collagefun();
  528. } else if (res.data.code == '2') {
  529. that.setData({
  530. attendflag: true
  531. })
  532. }
  533. }
  534. })
  535. },
  536. /**
  537. * 开启拼团
  538. */
  539. openteam() {
  540. let that = this;
  541. utils.$post({
  542. url: app.globalData.webUrl + 'api/spellgroup/open_team',
  543. header: {
  544. 'Authorization': 'bearer ' + app.globalData.token
  545. },
  546. data: {
  547. empid: that.data.empid,
  548. },
  549. success: function (res) {
  550. console.log(res)
  551. //1->活动下架,2->已参加过,3->拼团人数已满,4->拼团时限结束,0->拼团成功
  552. if (res.data.code == '0') {
  553. wx.showToast({
  554. title: '恭喜您,成功开启拼团',
  555. icon: 'none',
  556. duration: 1500
  557. })
  558. that.collagefun();
  559. } else {
  560. that.setData({
  561. attendflag: true
  562. })
  563. }
  564. }
  565. })
  566. },
  567. /**
  568. * 生命周期函数--监听页面初次渲染完成
  569. */
  570. onReady: function () {
  571. },
  572. /**
  573. * 生命周期函数--监听页面显示
  574. */
  575. onShow: function () {
  576. },
  577. /**
  578. * 生命周期函数--监听页面隐藏
  579. */
  580. onHide: function () {
  581. },
  582. /**
  583. * 生命周期函数--监听页面卸载
  584. */
  585. onUnload: function () {
  586. },
  587. /**
  588. * 页面相关事件处理函数--监听用户下拉动作
  589. */
  590. onPullDownRefresh() {
  591. this.collagefun();
  592. },
  593. /**
  594. * 页面上拉触底事件的处理函数
  595. */
  596. onReachBottom: function () {
  597. },
  598. addsharetap: function (type) {
  599. let that = this;
  600. utils.$post({
  601. url: app.globalData.webUrl + 'api/share/addlog',
  602. header: {
  603. 'Authorization': 'bearer ' + app.globalData.token
  604. },
  605. data: {
  606. id: '0',
  607. type: type,
  608. },
  609. success: function (r) {}
  610. })
  611. },
  612. /**
  613. * 用户点击右上角分享
  614. */
  615. onShareAppMessage: function () {
  616. this.addsharetap('customerJsAll');
  617. return {
  618. title: '装修拼团',
  619. imageUrl: this.data.collagemsg.cover,
  620. path: '/share/pages/collagemsg/collagemsg?empid=' + app.globalData.currentUserId + '&teamid=' + this.data.teamid + '&clientype=' + this.data.clientype + '&uid=' + app.globalData.shareuserid,
  621. };
  622. }
  623. })