| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- // package-basic-data/pages/share/share.js
- const Constants = require('@/utils/Constants.js');
- const mixins = require('@/mixins/index.js');
- const config = require('@/config/config.js');
- const util = require('@/utils/util.js')
- const app = getApp()
- Page({
- mixins: [mixins],
- /**
- * 页面的初始数据
- */
- data: {
- routeObjName: 'share',
- staffName: '',
- staffPhone: '',
- companyName: '',
- versionName: '',
- gradeCode: null,
- integral: 0,
- couponNumber: 0,
- cilckViewId: 'toShare',
- integralTacticItem: {},
- avatarUrl: config.image_url + '/static/img/' + '/order_billing_detail_01.png',
- couponItem: undefined,
- time: 129600000,
- timeData: {},
- couponSendItem: undefined,
- integralShareItem: undefined,
- settingFlg: false,
- },
- /**
- * @desc : 头像
- * @date : 2024/7/1 15:49
- * @author : 姜永辉
- */
- getUser() {
- let service = app.globalData['oauthService']
- return this.excute(service, service.getUser + '/' + app.globalData.user.userId, {}).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- let avatarUrl = res.data.data.userImage || this.data.defaultAvatarUrl
- this.setData({
- avatarUrl: avatarUrl
- })
- }
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 从我的进入 和 首页进入 不同
- if (options.settingFlg) {
- this.setData({
- settingFlg: options.settingFlg
- })
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- // 积分
- this.getIntegral()
- },
- /**
- * @desc : onLoad生命周期回调
- * @date : 2024/7/30 09:11
- * @author : 刘尧
- */
- loadInit() {
- wx.hideShareMenu({})
- // 版本
- this.setData({
- staffName: app.globalData.user.staffName,
- staffPhone: app.globalData.user.staffPhone,
- companyName: app.globalData.company.cpName,
- versionName: this.data.freeVersionFlag ? mixins.$t('standardVersion') : mixins.$t('professionalVersion')
- })
- // 策略
- this.getIntegralTactic()
- // 获取优惠劵助力信息
- this.getCouponTactic()
- // 获取用户头像
- this.getUser()
- // 优惠劵
- this.getCouponNumber()
- },
- /**
- * @desc : 显示活动卡片明细
- * @author : 刘尧
- * @date : 2024/7/29 15:23
- */
- showCardItem(e) {
- this.setData({
- cilckViewId: e.currentTarget.dataset.name
- })
- if (e.currentTarget.dataset.name != 'toShare') {
- switch (e.currentTarget.dataset.name) {
- case 'toPower':
- this.getPowerItem().then(res => {
- const data = res.data.data
- if (data) {
- const that = this
- const endDate = data.endDate
- const nowTime = data.nowTime
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- couponSendItem: data
- })
- }
- that.setData({
- couponSendItem: data
- })
- })
- break;
- case 'toRegister':
- const that = this
- this.getRegisterItem().then(res => {
- const item = res.data.data
- if(item){
- const endDate = item.endDate
- const nowTime = item.nowDate
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- integralShareItem: item
- })
- }
- that.setData({
- integralShareItem: item
- })
- })
- break;
- }
- }
- },
- /**
- * @desc : 获取助力明细
- * @author : 刘尧
- * @date : 2024/7/30
- */
- getPowerItem() {
- let params = {
- cpId: app.globalData.company.cpId,
- couponId: this.data.couponItem.couponId,
- sendUser: app.globalData.user.userId,
- }
- let service = app.globalData['couponSendService']
- return this.excute(service, 'get_item', params)
- },
- formatDate(isoDateString) {
- // 首先,尝试将ISO 8601格式的日期字符串转换为Date对象
- const date = new Date(isoDateString);
- // 然后,使用Date对象的方法获取年、月、日、时、分、秒
- // 注意月份是从0开始的,所以要+1
- const year = date.getUTCFullYear();
- const month = String(date.getUTCMonth() + 1).padStart(2, '0');
- const day = String(date.getUTCDate()).padStart(2, '0');
- const hours = String(date.getUTCHours()).padStart(2, '0');
- const minutes = String(date.getUTCMinutes()).padStart(2, '0');
- const seconds = String(date.getUTCSeconds()).padStart(2, '0');
- // 最后,按照yyyy-MM-ddTHH:mm:ss的格式拼接字符串
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
- },
- /**
- * @desc : 获取助力明细
- * @author : 刘尧
- * @date : 2024/7/30
- */
- getRegisterItem() {
- let service = app.globalData['integralShareService']
- const params = {
- cpId: app.globalData.company.cpId,
- tacticId: this.data.integralTacticItem.tacticId,
- flgValid: true,
- integralType: Constants.integralType.invite,
- userId: app.globalData.user.userId,
- staffName: app.globalData.user.staffName,
- }
- return this.excute(service, 'select_share_item', params)
- },
- /**
- * @desc : 倒计时事件
- * @author : 刘尧
- * @date : 2024/7/30
- */
- onCountDownChange(e) {
- this.setData({
- timeData: e.detail,
- });
- },
- /**
- * @desc : 服务器的日期
- * @author : 姜永辉
- * @date : 2024/4/1
- */
- getCurrentDate() {
- let _this = this
- let service = app.globalData['commonService']
- return _this.excute(service, service.getCurrentDate, { 'DateFormat': 'yyyy-MM-dd hh:mm:ss' });
- },
- /**
- * @desc : 积分策略
- * @author : 刘尧
- * @date : 2024/7/25 14:32
- */
- getIntegralTactic() {
- let params = {}
- let service = app.globalData['integralTacticService']
- this.excute(service, service.selectByCond, params).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- if (res.data && res.data.data.list && res.data.data.list.length > 0) {
- this.setData({
- integralTacticItem: res.data.data.list[0],
- })
- this.getShareNumber()
- }
- }
- });
- },
- /**
- * @desc : 获取优惠劵策略
- * @author : 刘尧
- * @date : 2024/7/30 09:42
- */
- getCouponTactic() {
- let params = {
- flgValid: true
- }
- let service = app.globalData['couponService']
- this.excute(service, service.selectByCond, params).then(res => {
- const list = res.data.data.list
- if (list.length > 0) {
- this.setData({
- couponItem: list[0]
- })
- }
- });
- },
- /**
- * @desc : 公司积分
- * @author : 刘尧
- * @date : 2024/7/25 14:32
- */
- getIntegral() {
- let params = {}
- let service = app.globalData['integralService']
- this.excute(service, app.globalData.company.cpId, params).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- if (res.data && res.data.data) {
- this.setData({
- integral: res.data.data.integral,
- })
- }
- }
- });
- },
- /**
- * @desc : 优惠劵数量获取
- * @author : 刘尧
- * @date : 2024/7/29 15:54
- */
- getCouponNumber() {
- let params = {
- couponStatus: Constants.couponStatus.unused,
- flgValid: true
- }
- let service = app.globalData['couponUseService']
- this.excute(service, service.countByCond, params).then(res => {
- this.setData({
- couponNumber: res.data.data
- })
- });
- },
- /**
- * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
- * @author : 刘尧
- * @date : 2024/7/25 14:32
- */
- insertNewPowerItem() {
- let params = {
- cpId: app.globalData.company.cpId,
- couponId: this.data.couponItem.couponId,
- userNum: this.data.couponItem.userNum,
- sendStaff: app.globalData.user.staffName,
- sendUser: app.globalData.user.userId,
- flgValid: true
- }
- let service = app.globalData['couponSendService']
- return this.excute(service, service.insert, params)
- },
- /**
- * @desc : 点击立即邀请按钮调后台服务插入优惠劵发出数据
- * @author : 刘尧
- * @date : 2024/8/1 11:32
- */
- insertNewRegisterItem() {
- const params = {
- cpId: app.globalData.company.cpId,
- tacticId: this.data.integralTacticItem.tacticId,
- flgValid: true,
- integralType: Constants.integralType.invite,
- userId: app.globalData.user.userId,
- staffName: app.globalData.user.staffName,
- }
- let service = app.globalData['integralShareService']
- return this.excute(service, service.insert, params)
- },
- /**
- * @desc : 将两个时间进行作差计算
- * @author : 刘尧
- * @date : 2024/7/30 15:40
- */
- calculateTimeDifference(date1, date2) {
- // 将日期转换为时间戳
- const timestamp1 = date1.getTime();
- const timestamp2 = date2.getTime();
- // 计算时间戳之差
- const diff = Math.abs(timestamp2 - timestamp1);
- // 返回结果
- return diff;
- },
- /**
- * @desc : 分享调用
- * @author : 刘尧
- * @date : 2024/7/30 15:40
- */
- shareIntegral() {
- let service = app.globalData['integralShareService']
- const params = {
- cpId: app.globalData.company.cpId,
- tacticId: this.data.integralTacticItem.tacticId,
- flgValid: true,
- integralType: Constants.integralType.share,
- userId: app.globalData.user.userId,
- staffName: app.globalData.user.staffName,
- }
- return this.excute(service, service.insert, params)
- },
- /**
- * @desc : 获取用户剩余分享次数
- * @author : 刘尧
- * @date : 2024/7/30 15:40
- */
- getShareNumber() {
- let service = app.globalData['integralShareService']
- const params = {
- cpId: app.globalData.company.cpId,
- tacticId: this.data.integralTacticItem.tacticId,
- flgValid: true,
- integralType: Constants.integralType.share,
- userId: app.globalData.user.userId,
- staffName: app.globalData.user.staffName,
- }
- this.excute(service, 'select_share_number', params).then(res => {
- const integralTacticItem = this.data.integralTacticItem
- integralTacticItem.shareRemainderNum = integralTacticItem.shareDayNum - res.data.data
- this.setData({
- integralTacticItem: integralTacticItem
- })
- })
- },
-
- /**
- * @desc : 跳转云币规则
- * @author : 刘尧
- * @date : 2024/8/2 14:54
- */
- toIntegralRules() {
- let url = config.knowledge_url + '/agreement-index?agId=10002024-0802-0000-0000-000009ff303e'
- let toUrl = '/pages/product/product'
- if (url) {
- wx.navigateTo({
- url: toUrl,
- success: function (res) {
- res.eventChannel.emit('url', url);
- }
- })
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: async function (e) {
- const url = this.data.imageUrl + 'share-background.png'
- this.setData({
- cilckViewId: e.target.dataset.detail
- })
- if (e.target.dataset.detail === "toShare") {
- const integralTacticItem = this.data.integralTacticItem
- if (integralTacticItem.shareDayNum > 0) {
- const res = await this.shareIntegral()
- if (res.data.code == Constants.SUCESS_CODE) {
- this.getShareNumber()
- this.getIntegral()
- return {
- title: '分享好友获取云币',
- desc: '分享不停歇',
- path: '/pages/welcome/welcome',
- imageUrl: url
- }
- }
- } else {
- util.showToast('今日分享已达上限!')
- }
- }
- if (e.target.dataset.detail === "toRegister") {
- let item = await this.getRegisterItem()
- item = item.data.data
- if (item) {
- const that = this
- const endDate = item.endDate
- const nowTime = item.nowDate
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- integralShareItem: item
- })
- }
- if (!this.data.integralShareItem) {
- const res = await this.insertNewRegisterItem()
- if (res.data.code == Constants.SUCESS_CODE) {
- const that = this
- const data = res.data.data
- const endDate = data.endDate
- const nowTime = data.nowTime
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- integralShareItem: data
- })
- }
- }
- const that = this
- let path = '/pages/welcome/welcome?cpIdFrom=' + app.globalData.company.cpId + '&shareType=1&shareEndDate=' + that.data.integralShareItem.endDate + '&staffNameFrom=' + app.globalData.user.staffName + '&userIdFrom=' + app.globalData.user.userId
- console.log("path",path);
- return {
- title: '邀请好友,互利共赢',
- desc: '邀请注册拿云币',
- path: path,
- imageUrl: url
- }
- }
- if (e.target.dataset.detail === "toPower") {
- const couponDesc = this.data.couponItem.couponDesc
- let item = await this.getPowerItem()
- item = item.data.data
- if (item) {
- const that = this
- const endDate = item.endDate
- const nowTime = item.nowTime
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- couponSendItem: item
- })
- }
- this.setData({
- couponSendItem: item
- })
- if (!this.data.couponSendItem) {
- const that = this
- const res = await this.insertNewPowerItem()
- if (res.data.code == Constants.SUCESS_CODE) {
- const data = res.data.data
- const endDate = data.endDate
- const nowTime = data.nowTime
- const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
- that.setData({
- time: time,
- couponSendItem: data
- })
- }
- }
- const that = this
- return {
- title: couponDesc,
- desc: '助力拿福利',
- path: '/package-basic-data/pages/share-power/share-power?cpId=' + app.globalData.company.cpId + '&couponId=' + that.data.couponItem.couponId + '&sendId=' + that.data.couponSendItem.sendId + '&discount=' + that.data.couponItem.discount + '&userIdForm=' + app.globalData.user.userId + '&userNum=' + this.data.couponItem.userNum,
- imageUrl: url
- }
- }
- }
- })
|