123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- const app = getApp();
- var utils = require("../../../utils/http"),
- page = 1;
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- countDownTime: 0,
- teamOrderNum: 0,
- imgUrl: app.globalData.imgUrl,
- defaultButtons: [{
- text: '知道了',
- extClass: 'color28A1FF'
- }],
- buttons: [{
- text: '拨打电话',
- extClass: 'color28A1FF'
- }],
- buttonarr: [{
- text: '取消',
- extClass: 'colorccc'
- },
- {
- text: '拨打电话',
- extClass: 'color28A1FF'
- }
- ],
- canIUseGetUserProfile: false,
- empid: '', //分享员工的id
- teamid: '',//团队id
- myTeamId: '',//我的团队
- collagemsg: {},
- userCollage: {},
- loginFlag: true,
- phoneFlag: false,
- canIUseGetUserProfile: false,
- articlelogin: true,
- collageflag: false,
- endshow: false,
- attendflag: false,
- haveFull: false,
- nowspellground_id: '',
- nowteam_id: '',
- clientype: '',
- empdata: {},
- spellsucesfalg: false,
- timeoutflag: false,
- companyobj: {},
- teamPerson: [],
- top: app.globalData.statusBarHeight,
- hgt: app.globalData.titleBarHeight,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- var that = this;
- // wx.hideHomeButton();
- if (wx.getUserProfile) {
- this.setData({
- canIUseGetUserProfile: true
- })
- }
- wx.showLoading({
- title: '加载中...',
- })
- if (!!options.scene) {
- options = unescape(options.scene);
- let arr = options.split('&');
- let obj = {};
- for (let i = 0; i < arr.length; i++) {
- let arr1 = arr[i].split('=');
- obj[arr1[0]] = arr1[1];
- }
- if (!!obj.e) {
- app.globalData.currentUserId = obj.e;
- this.setData({
- empid: obj.e, //分享拼团员工的id
- })
- }
- if (!!obj.t) {
- this.setData({
- teamid: obj.t, //团队id
- })
- }
- if (!!obj.p) {
- this.setData({
- clientype: obj.p
- })
- app.globalData.clientype = obj.p;
- }
- if (!!obj.u) {
- app.globalData.shareuserid = obj.u;
- }
- } else {
- if (!!options.uid) {
- app.globalData.shareuserid = options.uid;
- }
- if (!!options.empid) {
- app.globalData.currentUserId = options.empid;
- this.setData({
- empid: options.empid, //分享拼团员工的id
- })
- }
- if (!!options.teamid) {
- this.setData({
- teamid: options.teamid, //团队id
- })
- }
- if (!!options.clientype) {
- this.setData({
- clientype: options.clientype
- })
- app.globalData.clientype = options.clientype;
- }
- }
- this.logindata();
- wx.hideShareMenu({
- menus: ['shareAppMessage', 'shareTimeline']
- })
- },
- sharecompany: function () {
- const that = this;
- utils.$post({
- url: app.globalData.webUrl + 'client/index/content_belong_company',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- client_type: app.globalData.clientype,
- uid: app.globalData.shareuserid
- },
- success: function (res) {
- if (res.data.code == '0') {
- app.globalData.companyobj=res.data.data;
- that.setData({
- companyobj: res.data.data
- })
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- },
- lookcovertap() {
- wx.previewImage({
- current: this.data.collagemsg.cover, // 当前显示图片的http链接
- urls: [this.data.collagemsg.cover] // 需要预览的图片http链接列表
- })
- },
- golastap: function () {
- let arr = getCurrentPages();
- if (arr.length == 1) {
- wx.reLaunch({
- url: '/pages/index/index?state=1',
- })
- } else {
- wx.reLaunch({
- url: '/pages/index/index?state=1',
- })
- }
- },
- goindextap: function () {
- wx.reLaunch({
- url: '/pages/index/index?state=1',
- })
- },
- logindata: function () {
- var that = this;
- wx.showLoading();
- wx.login({
- success: function (data) {
- if (data.errMsg == 'login:ok') {
- utils.$post({
- url: app.globalData.webUrl + 'api/users/code2session',
- data: {
- client_type: that.data.clientype,
- code: data.code,
- share: app.globalData.shareuserid
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.sharepersonobj = r.data.share;
- app.globalData.token = r.data.token;
- that.sharecompany();
- that.collagefun();
- 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 != '游客')) {
- app.globalData.use_id = r.data.user.id;
- app.globalData.personMsg = r.data.user;
- app.globalData.userflag = false; //有个人信息
- var nickname = r.data.user.nickname;
- var phone = r.data.user.phone;
- that.setData({
- loginFlag: true,
- datashow: true,
- })
- if (r.data.user.phone != '') {
- app.globalData.personMsg = r.data.user;
- that.setData({
- mobileflag: false
- })
- } else {
- that.setData({
- phoneFlag: true
- })
- }
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: false
- })
- }
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: true
- })
- }
- }
- })
- } else {
- wx.hideLoading();
- that.setData({
- articlelogin: false,
- loginFlag: true
- })
- }
- }
- })
- },
- /**
- * 获取拼团详情
- */
- collagefun: function () {
- let that = this;
- console.log(app.globalData.token)
- utils.$post({
- url: app.globalData.webUrl + 'api/spellgroup/sel_user_group',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- empid: that.data.empid,
- teamid: that.data.teamid
- },
- success: function (res) {
- wx.stopPullDownRefresh();
- if (res.data.code == '0') {
- let data = res.data.data;
- let nowtime = new Date().getTime();
- if (data) {
- let countDownTime = data.surplus_time ? (new Date(data.surplus_time.replace(/-/g, "/")).getTime() - nowtime) : 0;
- that.setData({
- collagemsg: data.act_data,
- userCollage: data.user,
- countDownTime: countDownTime,
- teamid: data.user.teamid,
- teamPerson: data.team_mer,
- empdata: data.empdata || {},
- teamOrderNum: data.team_order_num,
- myTeamId: data.my_teamid
- })
- if (!!that.data.myTeamId && (that.data.userCollage.type == 5 || that.data.userCollage.type == 4)) {
- wx.showModal({
- title: '提示',
- content: '您名下已有正在进行的拼团,不能参加该拼团!',
- showCancel: false,
- confirmText: '知道了',
- success: (res) => {
- that.setData({
- teamid: that.data.myTeamId
- })
- that.collagefun();
- }
- })
- return false;
- }
- if (that.data.userCollage.type == 6) {
- that.setData({
- haveFull: true
- })
- }
- if (that.data.userCollage.type == 5) {
- that.setData({
- timeoutflag: true
- })
- }
- if (that.data.userCollage.type == 4) {
- that.setData({
- spellsucesfalg: true
- })
- }
- }
- wx.hideLoading();
- } else {
- wx.hideLoading();
- let msg = res.data.msg;
- setTimeout(() => {
- wx.showModal({
- title: '拼团提示',
- content: msg,
- showCancel: false,
- confirmText: '退出应用',
- success: () => {
- wx.exitMiniProgram();
- }
- })
- },1000)
- }
- }
- })
- },
- /**
- * 删除参与拼团的队员
- */
- delTeamItem(e) {
- let that = this;
- let id = e.currentTarget.dataset.id;
- wx.showModal({
- title: '提示',
- content: '确定删除当前队员吗?',
- cancelText: '取消',
- confirmText: '确定',
- success: (res) => {
- if (res.confirm) {
- utils.$post({
- url: app.globalData.webUrl + 'api/spellgroup/del_team_mer',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: id,
- teamid: that.data.teamid
- },
- success: function (res) {
- if (res.data.code == '0') {
- that.collagefun();
- wx.showToast({
- title: '删除成功',
- icon: 'success'
- })
- }
- }
- })
- }
- },
- fail: (error) => { }
- })
- },
- tapDialogButton: function () {
- let that = this;
- if (that.data.empdata.phone) {
- that.setData({
- spellsucesfalg: false
- })
- wx.makePhoneCall({
- phoneNumber: that.data.empdata.phone,
- })
- } else {
- that.setData({
- spellsucesfalg: false
- })
- wx.showToast({
- title: '未返回电话号码',
- icon: 'none',
- duration:1000
- })
- }
- },
- activityendtap: function () {
- this.setData({
- endshow: true
- })
- },
- timeoutap: function (e) {
- let that = this;
- if (e.detail.index == 1) {
- if (!that.data.empdata.phone) {
- that.setData({
- timeoutflag: false
- })
- wx.showToast({
- title: '未返回电话号码',
- icon: 'none',
- duration: 1000
- });
- return;
- }
- wx.makePhoneCall({
- phoneNumber: that.data.empdata.phone,
- success: function (res) {
- that.setData({
- timeoutflag: false
- })
- },
- fail: function (err) {
- that.setData({
- timeoutflag: false
- })
- }
- })
- } else {
- that.setData({
- timeoutflag: false
- })
- }
- },
- closeDialog: function () {
- let that = this;
- if (that.data.empdata.phone) {
- that.setData({
- haveFull: false
- })
- wx.makePhoneCall({
- phoneNumber: that.data.empdata.phone,
- })
- } else {
- that.setData({
- haveFull: false
- })
- wx.showToast({
- title: '未返回电话号码',
- icon: 'none',
- duration:1000
- })
- }
- },
- colsendtap: function () {
- this.setData({
- endshow: false
- })
- wx.exitMiniProgram();
- },
- attendtap: function () {
- this.setData({
- attendflag: false
- })
- },
- attendbtnap: function () {
- this.setData({
- attendflag: true
- })
- return false;
- },
- /**
- * 开启拼团-加入拼团
- * @param {*} res
- */
- getPhoneNumberTap: function (res) {
- let that = this;
- if (!!that.data.myTeamId && (that.data.userCollage.type == 1 || that.data.userCollage.type == 3)) {
- wx.showModal({
- title: '提示',
- content: '您名下已有正在进行的拼团,不能参加该拼团!',
- showCancel: false,
- confirmText: '知道了',
- success: (res) => {
- that.setData({
- teamid: that.data.myTeamId
- })
- that.collagefun();
- }
- })
- return false;
- }
- if (res.detail.errMsg == 'getPhoneNumber:ok') {
- utils.$post({
- url: app.globalData.webUrl + 'api/users/setUserMobile',
- data: {
- encryptedData: res.detail.encryptedData,
- iv: res.detail.iv
- },
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- success: function (r) {
- if (r.data.code == '0') {
- app.globalData.phone = true;
- app.globalData.personMsg.phone = r.data.mobile;
- that.setData({
- endshow: false
- })
- if (res.currentTarget.dataset.type == 'join') {
- that.jointeam();
- }
- if (res.currentTarget.dataset.type == 'open') {
- that.openteam();
- }
- } else {
- wx.showToast({
- title: r.data.msg,
- icon: "none",
- duration: 2000
- });
- }
- }
- })
- }
- },
- /***
- * 加入拼团
- */
- jointeam: function () {
- let that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/spellgroup/join_team',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- empid: that.data.empid,
- teamid: that.data.teamid
- },
- success: function (res) {
- console.log(res)
- //1->活动下架,2->已参加过,3->拼团人数已满,4->拼团时限结束,0->拼团成功
- if (res.data.code == '0') {
- wx.showToast({
- title: '已成功加入拼团',
- icon: 'none',
- duration: 1500
- })
- that.collagefun();
- } else if (res.data.code == '2') {
- that.setData({
- attendflag: true
- })
- }
- }
- })
- },
- /**
- * 开启拼团
- */
- openteam() {
- let that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/spellgroup/open_team',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- empid: that.data.empid,
- },
- success: function (res) {
- console.log(res)
- //1->活动下架,2->已参加过,3->拼团人数已满,4->拼团时限结束,0->拼团成功
- if (res.data.code == '0') {
- wx.showToast({
- title: '恭喜您,成功开启拼团',
- icon: 'none',
- duration: 1500
- })
- that.collagefun();
- } else {
- that.setData({
- attendflag: true
- })
- }
- }
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- this.collagefun();
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- addsharetap: function (type) {
- let that = this;
- utils.$post({
- url: app.globalData.webUrl + 'api/share/addlog',
- header: {
- 'Authorization': 'bearer ' + app.globalData.token
- },
- data: {
- id: '0',
- type: type,
- },
- success: function (r) {}
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- this.addsharetap('customerJsAll');
- return {
- title: '装修拼团',
- imageUrl: this.data.collagemsg.cover,
- path: '/share/pages/collagemsg/collagemsg?empid=' + app.globalData.currentUserId + '&teamid=' + this.data.teamid + '&clientype=' + this.data.clientype + '&uid=' + app.globalData.shareuserid,
- };
- }
- })
|