collagemsg.js 19 KB

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