Commit 534b10d9 authored by Edwise's avatar Edwise 🍷

1234

parent 1d0dce52
'use strict';
import API from "/api";
import { SHARE_CONFIG } from '/tbcc-sdk/lib/constants';
import {
SHARE_CONFIG
} from '/tbcc-sdk/lib/constants';
const app = getApp();
const { tbcc } = app;
const { commonToast, navigateToOutside, getUserAddress, setClipboard } = tbcc.tb;
const { PRIZE_TYPE_MAP, PRIZE_DRAW_STATUS_MAP } = tbcc.constants;
const {
tbcc
} = app;
const {
commonToast,
navigateToOutside,
getUserAddress,
setClipboard
} = tbcc.tb;
const {
PRIZE_TYPE_MAP,
PRIZE_DRAW_STATUS_MAP
} = tbcc.constants;
let flag = false;
Page({
data: {
PRIZE_TYPE_MAP,
PRIZE_DRAW_STATUS_MAP,
myPrizeList: null, //我的奖品
endTime: null,//到期时间
task: {
image: {
bg: '//yun.duiba.com.cn/aurora/assets/8fa7cea57cc7071bcc1cbada32f5bfaeb2203981.jpg', //背景图
copyIcon: '//yun.duiba.com.cn/aurora/assets/721e5319d26a4edbb0282558fb87d9bda1de4887.png', //复制
addressBth: '//yun.duiba.com.cn/aurora/assets/7ff6342492c2ce1a94ccfce39c88983b296b35fb.png', //填写地址(实物奖品)
getBth: '//yun.duiba.com.cn/aurora/assets/0725f0f5569ad12d37853ad5c40d163fbe247abf.png', //立即领取(除实物奖品外)
logisticsBth: '//yun.duiba.com.cn/aurora/assets/661f86ff3392cb3b56922b048acf74bebc07bb23.png', //查看物流
useBtn: '//yun.duiba.com.cn/aurora/assets/0829f92f771c5e9fdb05a258a46b2d038d3a9997.png', //去使用(除实物奖品外)
gotBtn: '//yun.duiba.com.cn/aurora/assets/30fa200ba1dcd345247f957c16a03a9706895112.png', //已领取(优惠券)
getAgainBtn: '//yun.duiba.com.cn/aurora/assets/f2bc6220c3b210a4b315ab1bfcc4ebeffcf854ba.png', //重新领取
invalidBtn: '//yun.duiba.com.cn/aurora/assets/2790bbc504bd94bd7914771e5ba1202e9f011a1a.png', //已失效
failBth: '//yun.duiba.com.cn/aurora/assets/7bdd43b0b86094c3cf121abb204824985a13035b.png', //领取失败
},
logisticsImage: {
shipped: '//yun.duiba.com.cn/aurora/assets/3a7b68ec171ee339ce619d19f6ae3f9c1e6d801a.png', // 已发货物理弹窗
notShipped: '//yun.duiba.com.cn/aurora/assets/ee0300d7b472c555ecf0b7b8d582fcf9189c2d19.png', // 待发货物流弹窗
copyIcon: '//yun.dui88.com/duiba-components-c-myprizemyprize_copy_code.png', //复制
},
btnStyle: { // 按钮自定义样式
width: '154rpx',
height: '49rpx',
}
}
},
onShow() {
flag = false
this.getMyPrize();
},
onShareAppMessage() {
return SHARE_CONFIG;
},
// 到期时间
getEndTime(prizeList = []) {
if (!prizeList || !prizeList.length) return null
const endTime = prizeList[0].expiredTime
if (!endTime) return null;
const yy = new Date(endTime).getFullYear();
const mm = new Date(endTime).getMonth() + 1;
const dd = new Date(endTime).getDate();
const t1 = `${yy}${mm}${dd}日`;
// console.log(new Date(endTime).toLocaleDateString())
// const t1 = new Date(endTime).toLocaleDateString() + '';//获取年月日
const t2 = new Date(endTime).getHours() + '';//获取时
const t3 = new Date(endTime).getMinutes() + '';//获取分
const t4 = new Date(endTime).getMilliseconds() + '';//获取秒
console.log(endTime, new Date(endTime + 48 * 60 * 60 * 1000).toLocaleString(), 'endTime');
this.setData({
endTime: t1 + "" + t2.padStart(2, '0') + ":" + t3.padStart(2, '0') + ":" + t4.padStart(2, '0')
})
},
data: {
PRIZE_TYPE_MAP,
PRIZE_DRAW_STATUS_MAP,
myPrizeList: null, //我的奖品
endTime: null, //到期时间
task: {
image: {
bg: '//yun.duiba.com.cn/aurora/assets/8fa7cea57cc7071bcc1cbada32f5bfaeb2203981.jpg', //背景图
copyIcon: '//yun.duiba.com.cn/aurora/assets/721e5319d26a4edbb0282558fb87d9bda1de4887.png', //复制
addressBth: '//yun.duiba.com.cn/aurora/assets/7ff6342492c2ce1a94ccfce39c88983b296b35fb.png', //填写地址(实物奖品)
getBth: '//yun.duiba.com.cn/aurora/assets/0725f0f5569ad12d37853ad5c40d163fbe247abf.png', //立即领取(除实物奖品外)
logisticsBth: '//yun.duiba.com.cn/aurora/assets/661f86ff3392cb3b56922b048acf74bebc07bb23.png', //查看物流
useBtn: '//yun.duiba.com.cn/aurora/assets/0829f92f771c5e9fdb05a258a46b2d038d3a9997.png', //去使用(除实物奖品外)
gotBtn: '//yun.duiba.com.cn/aurora/assets/30fa200ba1dcd345247f957c16a03a9706895112.png', //已领取(优惠券)
getAgainBtn: '//yun.duiba.com.cn/aurora/assets/f2bc6220c3b210a4b315ab1bfcc4ebeffcf854ba.png', //重新领取
invalidBtn: '//yun.duiba.com.cn/aurora/assets/2790bbc504bd94bd7914771e5ba1202e9f011a1a.png', //已失效
failBth: '//yun.duiba.com.cn/aurora/assets/7bdd43b0b86094c3cf121abb204824985a13035b.png', //领取失败
},
logisticsImage: {
shipped: '//yun.duiba.com.cn/aurora/assets/3a7b68ec171ee339ce619d19f6ae3f9c1e6d801a.png', // 已发货物理弹窗
notShipped: '//yun.duiba.com.cn/aurora/assets/ee0300d7b472c555ecf0b7b8d582fcf9189c2d19.png', // 待发货物流弹窗
copyIcon: '//yun.dui88.com/duiba-components-c-myprizemyprize_copy_code.png', //复制
},
btnStyle: { // 按钮自定义样式
width: '154rpx',
height: '49rpx',
}
}
},
onShow() {
flag = false
this.getMyPrize();
},
onShareAppMessage() {
return SHARE_CONFIG;
},
// 到期时间
getEndTime(prizeList = []) {
if (!prizeList || !prizeList.length) return null
const endTime = prizeList[0].expiredTime
if (!endTime) return null;
const yy = new Date(endTime).getFullYear();
const mm = new Date(endTime).getMonth() + 1;
const dd = new Date(endTime).getDate();
const t1 = `${yy}${mm}${dd}日`;
// console.log(new Date(endTime).toLocaleDateString())
// const t1 = new Date(endTime).toLocaleDateString() + '';//获取年月日
const t2 = new Date(endTime).getHours() + ''; //获取时
const t3 = new Date(endTime).getMinutes() + ''; //获取分
const t4 = new Date(endTime).getMilliseconds() + ''; //获取秒
console.log(endTime, new Date(endTime + 48 * 60 * 60 * 1000).toLocaleString(), 'endTime');
this.setData({
endTime: t1 + "" + t2.padStart(2, '0') + ":" + t3.padStart(2, '0') + ":" + t4.padStart(2, '0')
})
},
/**
* 获取奖品列表
* @param {string} type 是否展示loading
*/
async getMyPrize(type) {
const { activityId } = app;
if (type != 'noLoading') {
my.showLoading();
}
const { success, data, message } = await API.getMyPrizeList({ activityId }).catch(res => {
this.setData({
myPrizeList: []
})
}) || {};
data.list.forEach(i => {
// console.log('data list item', i);
i.image = i.image || '//yun.duiba.com.cn/aurora/assets/00b4b751939da230055889445f00f22990ff5f88.png';
});
if (success && data && data.list) {
this.setData({
myPrizeList: data.list
})
this.getEndTime(data.list)
}
if (type != 'noLoading') {
my.hideLoading();
}
},
/**
* 获取奖品列表
* @param {string} type 是否展示loading
*/
async getMyPrize(type) {
const {
activityId
} = app;
if (type != 'noLoading') {
my.showLoading();
}
const {
success,
data,
message
} = await API.getMyPrizeList({
activityId
}).catch(res => {
this.setData({
myPrizeList: []
})
}) || {};
data.list.forEach(i => {
// console.log('data list item', i);
i.image = i.image || '//yun.duiba.com.cn/aurora/assets/00b4b751939da230055889445f00f22990ff5f88.png';
});
if (success && data && data.list) {
this.setData({
myPrizeList: data.list
})
this.getEndTime(data.list)
}
if (type != 'noLoading') {
my.hideLoading();
}
},
//领取奖品
async handleClick(e) {
const { item } = e.target.dataset;
// 领取权益
if (item.type === PRIZE_TYPE_MAP.EQUITY) return this.handleGetEquity(e)
// 领取实物
if (item.type === PRIZE_TYPE_MAP.ENTITY) return this.handleGetEntity(e)
// 领取积分
if (item.type === PRIZE_TYPE_MAP.INTEGRATION) return this.handleGetIntergation(e)
},
//领取奖品
async handleClick(e) {
const {
item
} = e.target.dataset;
// 领取权益
if (item.type === PRIZE_TYPE_MAP.EQUITY) return this.handleGetEquity(e)
// 领取实物
if (item.type === PRIZE_TYPE_MAP.ENTITY) return this.handleGetEntity(e)
// 领取积分
if (item.type === PRIZE_TYPE_MAP.INTEGRATION) return this.handleGetIntergation(e)
},
/**
* 发奖
*/
async cloudTBIssue(params) {
const { cloud } = app;
return new Promise((resolve, reject) => {
my.authorize({
scopes: "scope.latourBenefit",
success: async () => {
const result = await cloud.topApi
.invoke({
api: "alibaba.latour.strategy.issue",
data: {
channel: params.channel || "",
strategy_code: params.strategyCode || "",
selected_benefit_code: params.code || "",
},
})
.catch((err) => {
commonToast('领取失败~')
console.log("alibaba.latour.strategy.issue------catch", err);
/**
* 发奖
*/
async cloudTBIssue(params) {
const {
cloud
} = app;
return new Promise((resolve, reject) => {
my.authorize({
scopes: "scope.latourBenefit",
success: async () => {
const result = await cloud.topApi
.invoke({
api: "alibaba.latour.strategy.issue",
data: {
channel: params.channel || "",
strategy_code: params.strategyCode || "",
selected_benefit_code: params.code || "",
},
})
.catch((err) => {
commonToast('领取失败~')
console.log("alibaba.latour.strategy.issue------catch", err);
});
console.log(result, "result");
resolve(result);
},
fail: (err) => {
console.log("scope.latourBenefit----fail", err);
commonToast('领取失败~')
reject(err);
},
});
console.log(result, "result");
resolve(result);
},
fail: (err) => {
console.log("scope.latourBenefit----fail", err);
commonToast('领取失败~')
reject(err);
},
});
})
},
})
},
// 优惠券
async handleGetEquity(e) {
if (flag) {
return
}
flag = true;
// 优惠券
async handleGetEquity(e) {
if (flag) {
return
}
flag = true;
const {
item: {
strategyCode,
code,
channel
}
} = e.target.dataset;
this.cloudTBIssue({
strategyCode,
code,
channel
})
// const { activityId } = app;
// console.log(item, '领取权益')
// const { success, data, message } = await API.receiveEnamePrize({ activityId, _id: item._id }).catch(res => {
// this.getMyPrize('noLoading')
// commonToast(res && res.message)
// }) || {};
// if (success && data) {
// commonToast('领取成功')
// this.getMyPrize()
// }
const { item: { strategyCode, code, channel } } = e.target.dataset;
this.cloudTBIssue({ strategyCode, code, channel })
// const { activityId } = app;
// console.log(item, '领取权益')
// const { success, data, message } = await API.receiveEnamePrize({ activityId, _id: item._id }).catch(res => {
// this.getMyPrize('noLoading')
// commonToast(res && res.message)
// }) || {};
// if (success && data) {
// commonToast('领取成功')
// this.getMyPrize()
// }
setTimeout(() => {
flag = false
}, 500)
},
// 领取实物前询问
async handleGetEntity(e) {
my.confirm({
title: '领取奖品',
content: '是否允许访问您的粘贴板',
confirmButtonText: '确认',
cancelButtonText: '取消',
success: (result) => {
if (result.confirm) {
const text = 'zzzxxx'
commonToast('请前去钉钉领取,钉钉号为:' + text + '。钉钉号已经复制成功。', 3000);
setClipboard({
text: `${text}`
})
}
setTimeout(() => {
flag = false
}, 500)
},
// 领取实物前询问
async handleGetEntity(e) {
const text = 'zzzxxx'
commonToast('请前去钉钉领取,钉钉号为:'+text+'。钉钉号已经复制成功。',3000);
setClipboard({ text:`${text}` })
},
});
// if (flag) {
// return
// }
// // my.showLoading();
// flag = true;
// const { activityId } = app;
// const { item } = e.target.dataset;
// const userAddress = await getUserAddress({ joinTag: " " }).catch((data) => {
// flag = false
// console.log('getUserAddress出错了,错误信息是', data);
// })
// // my.hideLoading();
// if (!userAddress) return
// // commonToast(' getUserAddress =>'+JSON.stringify( userAddress))
// const { name, telNumber, provinceName, cityName, cityCode, countyName, detailInfo, streetName } = userAddress || {};
// const params = {
// activityId,
// area: countyName,
// addressdetail: detailInfo,
// name,
// phone: telNumber,
// detailInfo,
// cityCode,
// cityName,
// city: cityName,
// province: provinceName,
// provinceName,
// countyName,
// streetName,
// _id: item._id
// }
// my.confirm({
// title: '提示',
// content: '确认使用该收货地址:' + name + telNumber + userAddress.duibaAddress.address,
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// success: (result) => {
// console.log(result)
// const { confirm } = result;
// if (flag) {
// return
// }
// // my.showLoading();
// flag = true;
// const { activityId } = app;
// const { item } = e.target.dataset;
// const userAddress = await getUserAddress({ joinTag: " " }).catch((data) => {
// flag = false
// console.log('getUserAddress出错了,错误信息是', data);
// })
// // my.hideLoading();
// if (!userAddress) return
// // commonToast(' getUserAddress =>'+JSON.stringify( userAddress))
// const { name, telNumber, provinceName, cityName, cityCode, countyName, detailInfo, streetName } = userAddress || {};
// const params = {
// activityId,
// area: countyName,
// addressdetail: detailInfo,
// name,
// phone: telNumber,
// detailInfo,
// cityCode,
// cityName,
// city: cityName,
// province: provinceName,
// provinceName,
// countyName,
// streetName,
// _id: item._id
// }
// if (confirm) {
// this.receiveObjectPrize(params);
// }
// },
// });
// flag = false
},
// 领取实物
async receiveObjectPrize(params) {
// commonToast('正在调用receiveObjectPrize'+JSON.stringify(params))
API.receiveObjectPrize(params).then((res) => {
// setTimeout(() => {
// commonToast(JSON.stringify(res))
// }, 5000);
// my.confirm({
// title: '提示',
// content: '确认使用该收货地址:' + name + telNumber + userAddress.duibaAddress.address,
// confirmButtonText: '确定',
// cancelButtonText: '取消',
// success: (result) => {
// console.log(result)
// const { confirm } = result;
// if (confirm) {
// this.receiveObjectPrize(params);
// }
// },
// });
// flag = false
},
// 领取实物
async receiveObjectPrize(params) {
// commonToast('正在调用receiveObjectPrize'+JSON.stringify(params))
API.receiveObjectPrize(params).then((res) => {
// setTimeout(() => {
// commonToast(JSON.stringify(res))
// }, 5000);
const { success, data, message } = res;
if (success && data) {
commonToast('领取成功')
} else {
commonToast(message)
}
this.getMyPrize()
}, (rej) => {
commonToast(rej.message)
});
},
// 积分
async handleGetIntergation(e) {
if (flag) {
return
}
flag = true;
// 判断是否为会员
await this.getUserInfo()
const { isVip, vipLink } = app;
if (!isVip) {
commonToast('立即加入会员,即可领取奖品', 2000);
setTimeout(() => {
navigateToOutside(vipLink)
}, 1000)
flag = false
return
}
const { activityId } = app;
const { item } = e.target.dataset;
console.log(item, '领取积分')
const { success, data, message } = await API.receiveEnamePrize({ activityId, _id: item._id }) || {};
if (success && data) {
commonToast('领取成功')
} else {
commonToast(message)
}
flag = false
this.getMyPrize()
},
const {
success,
data,
message
} = res;
if (success && data) {
commonToast('领取成功')
} else {
commonToast(message)
}
this.getMyPrize()
}, (rej) => {
commonToast(rej.message)
});
},
// 积分
async handleGetIntergation(e) {
if (flag) {
return
}
flag = true;
// 判断是否为会员
await this.getUserInfo()
const {
isVip,
vipLink
} = app;
if (!isVip) {
commonToast('立即加入会员,即可领取奖品', 2000);
setTimeout(() => {
navigateToOutside(vipLink)
}, 1000)
flag = false
return
}
const {
activityId
} = app;
const {
item
} = e.target.dataset;
console.log(item, '领取积分')
const {
success,
data,
message
} = await API.receiveEnamePrize({
activityId,
_id: item._id
}) || {};
if (success && data) {
commonToast('领取成功')
} else {
commonToast(message)
}
flag = false
this.getMyPrize()
},
//获取用户vip信息
async getUserInfo() {
const { activityId } = app;
const { success, data, message } = await API.getVipInfo({ activityId }) || {};
console.log(data, '用户vip信息');
if (success && data) {
app.isVip = (data && data.isVip) || false;
app.vipLink = (data && data.url) || '';
} else {
commonToast(message)
}
},
//获取用户vip信息
async getUserInfo() {
const {
activityId
} = app;
const {
success,
data,
message
} = await API.getVipInfo({
activityId
}) || {};
console.log(data, '用户vip信息');
if (success && data) {
app.isVip = (data && data.isVip) || false;
app.vipLink = (data && data.url) || '';
} else {
commonToast(message)
}
},
});
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment