Commit ca74ea39 authored by 李硕's avatar 李硕

无筛选信息展示中奖名单和筛选信息展示中奖名单

parent 89c9e65d
......@@ -15,7 +15,7 @@
key="{{item.key}}"
> -->
<!-- 添加筛选条件导出中奖名单 start -->
<form class="edit-content-form" data-name="form" inline="true" labelTextAlign="right" size="large">
<form a:if="{{isSearch}}" class="edit-content-form" data-name="form" inline="true" labelTextAlign="right" size="large">
<form-item class="edit-content-formItem" label="奖品编号" labelTextAlign="right" asterisk="{{false}}">
<input data-type="prize" value="{{searchInfo.prizeId}}" onChange="onInputChange" hasLimitHint="true" name="奖品编号" />
</form-item>
......@@ -40,17 +40,15 @@
</form-item>
</form>
<view style="textAlign:right">
<view a:if="{{isSearch}}" style="textAlign:right">
<button onTap="onChangeSearch" style="height:32px;" type="primary" size="medium">搜索</button>
<button style="margin-left:20px;height:32px" type="primary" data-type="search" onTap="exportWinnerListBySearch" size="medium">导出</button>
<button style="margin-left:20px;height:32px" type="primary" onTap="onChangeUpLoad" size="medium">导入发货</button>
</view>
<!-- end -->
<view class="now-winner-list">
<view a:if="{{!isSearch}}" class="now-winner-list">
<button type="primary" data-type="export" onTap="exportWinnerList">导出中奖名单</button>
</view>
<table dataSource="{{list}}">
<table-column a:for="{{columns}}" a:key="*this" title="{{item.title}}" dataIndex="{{item.prop}}" width="{{item.width}}"/>
</table>
......
......@@ -2,16 +2,21 @@
import {
findWinnerInfoList,
uploadDataCreateFile,
//通过搜索条件筛选中奖名单
// 通过搜索条件筛选中奖名单
exportAwardsInfoBySearch,
findWinnerInfoListBySearch
} from "/api";
import { appId } from "/config";
import { setClipboard } from "/utils";
//每页的展示数量
const PageInfo = {
PAGE_SIZE: 30,
PAGE_NO: 1
}
Component({
mixins: [],
data: {
PageInfo,
tabs: [{
tab: '0608-0712',
key: 111
......@@ -43,7 +48,7 @@ Component({
dataSource: [],
columns: [
{ title: '排名', prop: 'rank' },
{ title: '奖品编号', prop: 'prizeId' },//prizeId为awards_info中的_id
{ title: '奖品编号', prop: 'prizeId' },// prizeId为awards_info中的_id
{ title: '发奖时间', prop: 'createTime' },
{ title: '填地址时间', prop: 'receiveTime' },
{ title: '用户昵称', prop: 'userNick' },
......@@ -52,13 +57,18 @@ Component({
{ title: '奖品名', prop: 'name' },
{ title: '收货人', prop: 'receiveName' },
{ title: '联系方式', prop: 'phone' },
/*注:需要在接口里将 省+市+区+详细 拼写起来*/
{ title: '收货地址', prop: 'address' },//{ title: '收货地址', prop: 'address', width: 240 }
/* 注:需要在接口里将 省+市+区+详细 拼写起来*/
{ title: '收货地址', prop: 'address' },// { title: '收货地址', prop: 'address', width: 240 }
{ title: '物流状态', prop: 'shipStatus' },
{ title: '物流公司', prop: 'shipCompany' },
{ title: '物流单号', prop: 'shipNum' }
],
//《条件搜索》start显示中奖名单搜索条件
// pageInfo: {
// pageNo: 1,
// pageSize: 100,
// total: 0
// },
// 《条件搜索》start显示中奖名单搜索条件
list: [],
prizeId: "",
userId: "",
......@@ -69,21 +79,27 @@ Component({
prizeType: "",
showShip: false,
winactivityId: "",
pageNo: 1,
pageSize: 1,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
//end
// end
//需要筛选查询时改为true
isSearch: false
},
props: {
onClose: () => { },
selectedItem: {},
},
didMount() { },
didMount() {
if (!this.data.isSearch) {
this.loadWinnerList();
}
},
didUpdate() { },
didUnmount() { },
methods: {
//start《条件搜索》初始化数据更新
// start《条件搜索》初始化数据更新
initData() {
this.setData({
list: [],
......@@ -94,12 +110,26 @@ Component({
timeRange: [],
shipStatus: "",
prizeType: "",
pageNo: 1,
pageSize: 1,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
})
});
},
//end
//加载中奖名单
async loadWinnerList() {
let { pageNo, pageSize } = this.data;
let { activityId } = this.props.selectedItem;
const { data, success } = await findWinnerInfoList({ activityId, pageNo, pageSize });
console.log('data>>>>>', data);
if (success) {
this.setData({
list: data.list,
total: data.total
});
}
},
// end
onCloseDialog() {
this.initData();
this.props.onClose && this.props.onClose();
......@@ -147,7 +177,7 @@ Component({
}
},
//《条件搜索》 导出中奖名单
// 《条件搜索》 导出中奖名单
timeExchange(time) {
console.log("time==", time);
......@@ -179,7 +209,7 @@ Component({
my.showToast({
type: 'fail',
content: '没有符合条件的订单!'
})
});
}
else {
console.log("导出中奖名单");
......@@ -189,7 +219,7 @@ Component({
my.showToast({
type: 'success',
content: '下载链接复制成功,请在浏览器中打开下载'
})
});
}
});
}
......@@ -197,7 +227,7 @@ Component({
my.showToast({
type: 'fail',
content: message
})
});
}
} catch (error) {
my.hideLoading();
......@@ -208,26 +238,25 @@ Component({
my.showToast({
type: "fail",
content: "请填写至少一个筛选信息"
})
});
}
},
//《条件搜索》导入发货信息
// 《条件搜索》导入发货信息
onChangeUpLoad() {
const { activityId, title } = this.props.selectedItem;
this.setData({
showShip: true,
winactivityId: activityId
})
});
},
//《条件搜索》关闭导入发货窗口
// 《条件搜索》关闭导入发货窗口
onCloseShip() {
this.setData({
showShip: false,
})
});
},
//《条件搜索》搜索
// 《条件搜索》搜索
async onChangeSearch() {
const { activityId, title } = this.props.selectedItem;
let { prizeId, userId, startT, endT, pageNo, pageSize, shipStatus, prizeType } = this.data;
......@@ -240,20 +269,13 @@ Component({
this.setData({
list: [],
total: 0
}); 0
}); 0;
my.showToast({
type: "fail",
content: "没有符合条件的订单!"
})
});
} else {
console.log("rewardList==", rewardList);
//时间戳的转换都去到服务端做
/*
rewardList.data.list.forEach((item) => {
item.createTime = moment(+item.createTime).format("YYYY-MM-DD HH:mm:ss");
item.receiveTime = !!item.receiveTime ? moment(+item.receiveTime).format("YYYY-MM-DD HH:mm:ss") : '/';
});
*/
this.setData({
list: rewardList.data.list,
total: rewardList.data.total
......@@ -264,10 +286,10 @@ Component({
my.showToast({
type: "fail",
content: "请填写至少一个筛选信息"
})
});
}
},
//《条件搜索》按照时间搜索
// 《条件搜索》按照时间搜索
onChangeTime(e) {
console.log("时间搜索e", e);
const [startTime, endTime] = e.detail.value;
......@@ -275,52 +297,55 @@ Component({
startT: startTime || "",
endT: endTime || "",
timeRange: [startTime, endTime],
pageNo: 1,
pageSize: 10,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
console.log("this.data.timeRange==", this.data.timeRange, this.data.startT, this.data.endT);
},
//《条件搜索》输入框查找信息
// 《条件搜索》输入框查找信息
onInputChange(e) {
let { type } = e.currentTarget.dataset;
let { value } = e.detail;
this.setData({
[type + "Id"]: value,
pageNo: 1,
pageSize: 10,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
})
});
console.log("this.data.prizeId===", this.data.prizeId, "this.data.userId===", this.data.userId);
},
//《条件搜索》发货状态筛选
// 《条件搜索》发货状态筛选
onSelectShipStatus(e) {
console.log('筛选发货状态e>>>', e);
this.setData({
shipStatus: e.detail.value,
pageNo: 1,
pageSize: 10,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
})
});
},
//《条件搜索》奖品类型筛选
// 《条件搜索》奖品类型筛选
onSelectPrizeType(e) {
console.log('筛选奖品类型e>>>', e);
this.setData({
prizeType: e.detail.value,
pageNo: 1,
pageSize: 10,
pageNo: PageInfo.PAGE_NO,
pageSize: PageInfo.PAGE_SIZE,
total: 0,
});
console.log("type", this.data.prizeType);
},
//《条件搜索》更换页码时调用接口
// 《条件搜索》更换页码时调用接口
onChangePageNo(e) {
this.setData({
pageNo: e.detail.value
})
this.onChangeSearch();
});
if (this.data.isSearch) {
this.onChangeSearch();
} else {
this.loadWinnerList();
}
}
},
});
......@@ -39,4 +39,4 @@
/>
<rank-dialog visible="{{winnerListDialogVisible}}" onClose="onCloseWinnerListDialog" list="{{winnerList}}" selectedItem="{{selectedItem}}"/>
\ No newline at end of file
<rank-dialog a:if="{{winnerListDialogVisible}}" visible="{{winnerListDialogVisible}}" onClose="onCloseWinnerListDialog" selectedItem="{{selectedItem}}"/>
\ No newline at end of file
......@@ -10,7 +10,6 @@ import {
import { appId } from "/config";
import { setClipboard } from "/utils";
Component({
data: {
isLoadingList: false,
......@@ -28,7 +27,6 @@ Component({
},
deleteId: "",
winnerListDialogVisible: false,
winnerList: [],
selectedItem: {}
},
props: {
......@@ -38,7 +36,7 @@ Component({
this.getList();
},
methods: {
/**
/**
*获取活动列表
*
* @param {number} [currentPage=1] 页数
......@@ -90,33 +88,22 @@ Component({
}
},
// 获取中奖名单
async handleOpenWinnerList(evt) {
const { activityId } = evt.target.dataset.x.record;
const { data,success } = await findWinnerInfoList({ activityId });
if (success) {
this.setData({
winnerListDialogVisible: true,
winnerList: data.map(v => {
return {
...v,
typeName: v.type == 1 ? '优惠券': '实物'
}
}),
selectedItem: evt.target.dataset.x.record
})
}
handleOpenWinnerList(evt) {
this.setData({
winnerListDialogVisible: true,
selectedItem: evt.target.dataset.x.record
});
},
onCloseWinnerListDialog() {
this.setData({
winnerListDialogVisible: false
})
});
},
// 复制链接
async onCopyLink(evt) {
const { activityId } = evt.target.dataset.x.record;
let text = `https://m.duanqu.com/?_ariver_appid=${appId}?query=activityId%3D${activityId}`
let text = `https://m.duanqu.com/?_ariver_appid=${appId}?query=activityId%3D${activityId}`;
try {
await setClipboard({
text
......@@ -132,9 +119,9 @@ Component({
onCloseExportDialog() {
this.setData({
exportDialogVisible: false
})
});
},
//复制新活动
// 复制新活动
async onCreateNewActivity(evt) {
const { activityId } = evt.target.dataset.x.record;
let res = await createCopyActivity({ activityId });
......@@ -151,10 +138,10 @@ Component({
const { activityId } = evt.target.dataset.x.record;
this.$page.$router.push(`/activity/data/${activityId}`);
},
// 点击列表删除
// 点击列表删除
handleTapDelete(evt) {
const { activityId } = evt.target.dataset.x.record;
console.log(1)
console.log(1);
this.setData({
confirmDialog: Object.assign({}, this.data.confirmDialog, {
visible: true,
......@@ -216,7 +203,7 @@ Component({
this.setData({
exportDialogVisible: true,
exportUrl: data.url.replace(/amp;/g, "")
})
});
} else {
my.showToast({
type: "fail",
......
......@@ -35,35 +35,51 @@ let resultsModel = new ResultsModel();
// 活动中奖名单
const findWinnerInfoList = async (context) => {
let {
activityId
activityId,
pageNo, pageSize
} = context.data;
if (!activityId) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少activityId`);
}
if (!activityId) {
return resultsModel.error(CODE_TYPES.PARAMS_ERROR, `缺少activityId`);
}
let rankopenprizeService = new RankopenprizeService(context);
// 获取活动中奖列表
let awardslist = await rankopenprizeService.getAwardslistByActivityId(activityId);
console.log(`awardslist: ${JSON.stringify(awardslist)}`);
let winnersObj = {};
awardslist.forEach((v, index, arr) => {
if (!winnersObj[v.rank]) {
winnersObj[v.rank] = [];
}
winnersObj[v.rank].push({
userNick: v.userNick,
id: v.openId
});
});
console.log(`winnersObj: ${JSON.stringify(winnersObj)}`);
let results = [];
new Map(Object.entries(winnersObj)).forEach((v, index, arr) => {
results.push({
rank: index,
winnerDetailList: v
});
});
return resultsModel.success(results);
let total = await rankopenprizeService.getAwardslistCount(activityId);
console.log("totle=========", total);
let awardslist = [];
let awardMore = await rankopenprizeService.getAwardslistByActivityId(
activityId,
pageSize,
pageNo
);
awardslist = awardslist.concat(awardMore);
// console.log('awardslist>>>>', awardslist)
// awardslist = await rankopenprizeService.getAwardslistByActivityId(
// activityId,
// );
// console.log(`awardslist:》》》 ${JSON.stringify(awardslist)}《《《`);
awardslist.map((item) => {
let ad = item.province + item.city + item.area + item.addressdetail, type0 = item.type;
item.createTime = formatTime(new Date(item.createTime)) || "";
item.receiveTime = item.receiveTime ? formatTime(new Date(item.receiveTime)) : '未填';
item.awardsType = prizePoolType[item.awardsType];
item.type = prizeKind[item.type];
item.receiveName = type0 == 3 ? (item.receiveName || "未填") : '/';
item.phone = type0 == 3 ? (item.phone || "未填") : '/';
item.address = type0 == 3 ? (item.province ? ad : "未填") : '/';
item.shipStatus = type0 == 3 ? (shipMsg[item.shipStatus]) : '/';
item.shipCompany = type0 == 3 ? (item.shipCompany || '/') : '/';
item.shipNum = type0 == 3 ? (item.shipNum || '/') : '/';
})
// console.log(`xlsxData: ${JSON.stringify(xlsxData)}`);
try {
return resultsModel.success({ list: awardslist, total });
} catch (e) {
console.log("上传文件出错", e);
// 打印日志
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `查看结果错误`);
}
};
// 导出活动中奖名单
const exportAwardsList = async (context) => {
......@@ -84,35 +100,68 @@ const exportAwardsList = async (context) => {
// 获取活动中奖列表
let awardslist = await rankopenprizeService.getAwardslistByActivityId(activityId);
console.log(`awardslist: ${JSON.stringify(awardslist)}`);
let xlsxData = [
['序列', '名次', '昵称', '中奖名称']
];
awardslist.forEach((v, index, arr) => {
xlsxData.push([index + 1, v.rank, v.userNick, v.prizeName]);
});
let buffer = xlsx.build([{
name: title + new Date().getTime(),
data: xlsxData
}]);
console.log(`xlsxData: ${JSON.stringify(xlsxData)}`);
try {
let result = await cloud.file.uploadFile({
fileContent: buffer,
fileName: title + new Date().getTime() + '.xlsx'
if (awardslist.length > 0) {
let xlsxData = [
[
"序列",
"奖品编号",
"中奖时间",
"地址填写时间",
"用户昵称",
"奖品种类",
"奖品类型",
"中奖名称",
"收货人",
"手机号",
"收获地址",
"发货状态",
"物流公司",
"物流单号"
],
];
awardslist.forEach((v, index, arr) => {
xlsxData.push([
index + 1,
v._id,
// 中奖时间-填写地址时间
v.createTime ? formatTime(new Date(v.createTime + EIGHT_HOURS)) : "",
v.type == 1 ? "/" : v.receiveTime ? formatTime(new Date(v.receiveTime + EIGHT_HOURS)) : "未填",
v.userNick || "/",
prizePoolType[v.awardsType],
prizeKind[v.type],
v.name || "",
v.type == 1 ? "/" : v.receiveName || "",
v.type == 1 ? "/" : v.phone || "未填",
v.type == 1 ? "/" : (v.province ? v.province + v.city + v.area + v.addressdetail : "未填"),
v.type == 1 ? "/" : shipMsg[v.shipStatus],
v.type == 1 ? "/" : v.shipCompany || "/",
v.type == 1 ? "/" : v.shipNum || "/",
]);
});
// result.url 需进行处理
if (result.url) {
result.url = result.url.replace('http', 'https').replace('-internal', '');
let buffer = xlsx.build([{
name: title + new Date().getTime(),
data: xlsxData
}]);
console.log(`xlsxData: ${JSON.stringify(xlsxData)}`);
try {
let result = await cloud.file.uploadFile({
fileContent: buffer,
fileName: title + new Date().getTime() + '.xlsx'
});
// result.url 需进行处理
if (result.url) {
result.url = result.url.replace('http', 'https').replace('-internal', '');
}
return resultsModel.success(result);
} catch (e) {
console.log('上传文件出错', e);
// 打印日志
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `上传文件错误`);
}
return resultsModel.success(result);
} catch (e) {
console.log('上传文件出错', e);
// 打印日志
return resultsModel.error(CODE_TYPES.SYSTEM_ERROR, `上传文件错误`);
} else {
return resultsModel.success(false);
}
};
//-------------------start--------------------------------------------------
//《条件搜索》 导出活动中奖名单
const exportAwardsInfoBySearch = async (context) => {
......@@ -189,9 +238,6 @@ const exportAwardsInfoBySearch = async (context) => {
v.name || "",
v.type == 1 ? "/" : v.receiveName || "",
v.type == 1 ? "/" : v.phone || "未填",
// v.type == 1 ? "/" : v.province || "未填",
// v.type == 1 ? "/" : v.city || "未填",
// v.type == 1 ? "/" : v.city || "未填",
v.type == 1 ? "/" : (v.province ? v.province + v.city + v.area + v.addressdetail : "未填"),
v.type == 1 ? "/" : shipMsg[v.shipStatus],
v.type == 1 ? "/" : v.shipCompany || "/",
......@@ -204,7 +250,6 @@ const exportAwardsInfoBySearch = async (context) => {
data: xlsxData,
},
]);
// console.log(`xlsxData: ${JSON.stringify(xlsxData)}`);
try {
let result = await cloud.file.uploadFile({
fileContent: buffer,
......
......@@ -25,9 +25,19 @@ class RankopenprizeService {
return false;
}
}
// 根据活动id查找中奖名单
async getAwardslistByActivityId(activityId) {
//获取中奖名单长度
async getAwardslistCount(activityId, pageSize, pageNo) {
if (!activityId) {
return false;
}
return await this.rankopenprizeDao.count(
{
activityId: activityId,
}
);
}
// 根据活动id分页查找中奖名单
async getAwardslistByActivityId(activityId, pageSize, pageNo) {
if (!activityId) {
return false;
}
......@@ -37,9 +47,10 @@ class RankopenprizeService {
},
{
sort: {
score: -1,
rankTime: -1,
rank: 1
},
limit: pageSize,
skip: (pageNo - 1) * pageSize,
}
);
}
......
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