You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

358 lines
9.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

const app = getApp();
Page({
data: {
brandDataList: [],
//form
iTimeType: 0,
sTimeType: 34,
sStartTime: '',
sEndTime: '',
iPageIndex: 1,
iPageSize: 10,
//api
affList: [],
qgList: [{
key: 1,
value: "正面",
isSelect: false
},
{
key: 2,
value: "负面",
isSelect: false
},
{
key: 3,
value: "中性",
isSelect: false
}
],
wjList: [{
key: 1,
value: '低级危机',
isSelect: false
}, {
key: 2,
value: '中级危机',
isSelect: false
}, {
key: 3,
value: '高级危机',
isSelect: false
}],
copyShow: false,
copyData: {},
total: 0,
isSelectAll: false,
result: [],
fileName: '',
reportShow: false,
reportOption: []
},
onShow() {
this.setData({
sTimeType: wx.getStorageSync('sTimeType') || 34,
sStartTime: wx.getStorageSync('sStartTime') || '',
sEndTime: wx.getStorageSync('sEndTime') || '',
})
this.getApi();
this.getData();
},
onReachBottom() {
let qdList = [];
this.data.affList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qdList.push(ele.key)
}
});
let qgList = [];
this.data.qgList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qgList.push(ele.key)
}
});
let wjList = [];
this.data.wjList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
wjList.push(ele.key)
}
});
let pageIndex = this.data.iPageIndex + 1;
this.setData({
iPageIndex: pageIndex
});
app.globalData.request({
action: 'getList', //数据列表
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
sTimeType: this.data.sTimeType,
sStartTime: this.data.sStartTime,
sEndTime: this.data.sEndTime,
sQuDao: qdList.join(',') || '',
sQingGan: qgList.join(',') || '',
iPageIndex: this.data.iPageIndex,
iPageSize: this.data.iPageSize,
sType: 'BrandData',
isSourcetype: 0, //1返回渠道 0不返回
iTimeType: this.data.iTimeType, //0发布时间 1入库时间
sCrisis: wjList.join(',') || '',
sBrand: wx.getStorageSync('sBrand') || '',
sSeries: wx.getStorageSync('sSeriesName') || '',
}).then(res => {
let arr = [...this.data.brandDataList, ...res]
this.setData({
brandDataList: arr
})
});
},
getData() {
let qdList = [];
this.data.affList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qdList.push(ele.key)
}
});
let qgList = [];
this.data.qgList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qgList.push(ele.key)
}
});
let wjList = [];
this.data.wjList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
wjList.push(ele.key)
}
});
app.globalData.request({
action: 'getList', //数据列表
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
sTimeType: this.data.sTimeType,
sStartTime: this.data.sStartTime,
sEndTime: this.data.sEndTime,
sQuDao: qdList.join(',') || '',
sQingGan: qgList.join(',') || '',
iPageIndex: this.data.iPageIndex,
iPageSize: this.data.iPageSize,
sType: 'BrandData',
isSourcetype: 0, //1返回渠道 0不返回
iTimeType: this.data.iTimeType, //0发布时间 1入库时间
sCrisis: wjList.join(',') || '',
sBrand: wx.getStorageSync('sBrand') || '',
sSeries: wx.getStorageSync('sSeriesName') || '',
}, (res) => {
this.setData({
total: res.totalNum
})
}).then(res => {
this.setData({
brandDataList: res
})
});
},
getApi() {
app.globalData.request({
action: 'getQuDao', //获取所有渠道
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
}).then(res => {
res.forEach(ele => {
ele.isSelect = false;
})
this.setData({
affList: res
})
});
app.globalData.request({
action: 'getToExcelField', //获取导出字段
sType: 'BrandData',
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
}).then(res => {
this.setData({
reportOption: res
})
});
},
changeSource(event) {
let that = this;
let val = event.currentTarget.dataset.value;
if (val.key == -1 && val.isSelect == false) {
that.data.affList.forEach(ele => {
ele.isSelect = true;
})
} else if (val.key == -1 && val.isSelect == true) {
that.data.affList.forEach(ele => {
ele.isSelect = false;
})
} else {
that.data.affList[0].isSelect = false;
}
if (val.key == -1) {
this.setData({
affList: that.data.affList
});
} else {
that.data.affList[val.key].isSelect = !that.data.affList[val.key].isSelect;
this.setData({
affList: that.data.affList
});
};
this.getData();
},
changeQingGan(event) {
let that = this;
let val = event.currentTarget.dataset.value;
that.data.qgList[val.key - 1].isSelect = !that.data.qgList[val.key - 1].isSelect;
this.setData({
qgList: that.data.qgList
});
this.getData();
},
changeWeiJi(event) {
let that = this;
let val = event.currentTarget.dataset.value;
that.data.wjList[val.key - 1].isSelect = !that.data.wjList[val.key - 1].isSelect;
this.setData({
wjList: that.data.wjList
});
this.getData();
},
iTimeTypeChange(event) {
this.setData({
iTimeType: this.data.iTimeType == 1 ? 0 : 1,
});
this.getData()
},
changeTime(result) {
this.setData({
sTimeType: result.detail.sTimeType,
sStartTime: result.detail.sStartTime,
sEndTime: result.detail.sEndTime,
});
this.getData();
},
toEventDetail(e) {
let id = e.currentTarget.dataset.id._id;
wx.navigateTo({
url: '/subPackages/pages/detail/index?id=' + id
})
},
//单选
onChange(event) {
this.setData({
result: event.detail,
})
},
changeSelectAll(event) {
let listId = [];
let isSelectAllList = [];
if (event.detail.length != 0) {
this.data.brandDataList.forEach((e) => {
listId.push(e._id);
})
isSelectAllList.push(event.detail)
} else {
listId.splice();
}
this.setData({
result: listId,
isSelectAll: event.detail,
});
},
openReport() {
let that = this;
let d = new Date();
let date = d.toISOString().replace(/\D/g, '');
let result = this.data.result.length
let total = this.data.total
if (result == 0 && total*1 > 50000) {
wx.showModal({
title: '提示',
content: '全部数据超过50000条是否要全部导出',
success: function (r) {
if (r.confirm) {
that.setData({
fileName: "事件数据" + date,
reportShow: true
})
} else {
}
}
})
} else {
that.setData({
fileName: "事件数据" + date,
reportShow: true
})
}
},
fieldChange(event) {
let index = event.currentTarget.dataset.index;
var that = this;
that.data.reportOption[index].checked = that.data.reportOption[index].checked == 0 ? 1 : 0
this.setData({
reportOption: that.data.reportOption
})
},
report() {
let d = new Date();
let date = d.toISOString().replace(/\D/g, '');
let qdList = [];
this.data.affList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qdList.push(ele.key)
}
});
let qgList = [];
this.data.qgList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
qgList.push(ele.key)
}
});
let wjList = [];
this.data.wjList.forEach(ele => {
if (ele.isSelect && ele.key != -1) {
wjList.push(ele.key)
}
});
let sField = {};
this.data.reportOption.forEach(ele => {
if (ele.checked == 1 || ele.checked == "1") {
sField[ele.field] = 1;
}
})
let obj = {
action: 'toExcel', //导出
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
sTimeType: this.data.sTimeType,
sStartTime: this.data.sStartTime,
sEndTime: this.data.sEndTime,
sBrand: wx.getStorageSync('sBrand') || '',
sSeries: wx.getStorageSync('sSeriesName') || '',
sQuDao: qdList.join(',') || '',
sQingGan: qgList.join(',') || '',
sCrisis: wjList.join(',') || '',
sType: 'BrandData',
sField: JSON.stringify(sField), //导出字段
sFileName: this.data.fileName, //文件名称
sCheckedIds: this.data.result.join(',') || '', //数据id
iNum: this.data.result.length == 0 ? this.data.total : this.data.result.length, //导出条数
iTimeType: this.data.iTimeType, //0发布时间 1入库时间
}
app.globalData.request(obj).then((res) => {
if (res.Code == 1) {
this.setData({
reportShow: false
})
wx.showModal({
title: '数据生成中,请前往”我的“查看生成进度',
showCancel: false
})
}
}).catch(err => {
wx.showModal({
title: '提示',
content: err.Msg,
})
});
}
})