collagemsg.js 19 KB

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