1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<template>
<div class="orderCount">
<el-form ref="searchFrom" inline :model="searchFrom" label-width="100px">
<el-form-item label="商品">
<el-select
style="width: 600px"
v-model="searchFrom.priceList"
collapse-tags
multiple
filterable
placeholder="请选择"
@change="searchPage">
<el-option
v-for="item in goodsList"
:key="item.id"
:label="item.name"
:value="item.current_price">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="起止日期">
<el-date-picker
v-model="searchFrom.dateValue"
unlink-panels
type="daterange"
value-format="yyyy-MM-dd"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
@change="searchPage">
</el-date-picker>
</el-form-item>
<el-form-item label="">
<el-button type="primary" @click="searchPage()">
搜索
</el-button>
</el-form-item>
</el-form>
<el-table
:data="tableData"
style="width: 100%">
<el-table-column
v-for="data in headList"
:key="data"
:label="data">
<template slot-scope="scope">
<span v-if="data === '时间'">
{{ scope.row['cur_date'] }}
</span>
<span v-if="data === '注册数'">
{{ scope.row['register_num'] }}
</span>
<span v-if="data === '总金额'">
{{ scope.row['total_money'] }}
</span>
<span v-if="data !== '时间' && data !== '注册数' && data !== '总金额'">
{{ scope.row[data] }}
</span>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import {getGoodsListApi,orderCountApi} from "../../service/api";
export default {
name: "index",
data(){
return {
goodsList:[],
headList:[],
tableData:[],
searchFrom:{
priceList:[],
dateValue:[]
},
}
},
mounted(){
this.defaultTime();
this.initPage()
},
methods:{
Div: function (arg1, arg2) {
var r1 = arg1.toString(), r2 = arg2.toString(), m, resultVal, d = arguments[2];
m = (r2.split(".")[1] ? r2.split(".")[1].length : 0) - (r1.split(".")[1] ? r1.split(".")[1].length : 0);
resultVal = Number(r1.replace(".", "")) / Number(r2.replace(".", "")) * Math.pow(10, m);
return typeof d !== "number" ? Number(resultVal) : Number(resultVal.toFixed(parseInt(d)));
},
initPage(){
getGoodsListApi({limit:99999}).then(res=>{
res.list.forEach(i=>{
i.current_price =(this.Div( i.current_price , 100 ));
this.searchFrom.priceList.push(i.current_price)
});
this.goodsList=res.list
this.searchPage();
})
},
searchPage(){
if(this.searchFrom.dateValue.length<2){
this.$message.error('请先选择起止日期');
}else{
let json = {
start_at:this.searchFrom.dateValue[0],
end_at:this.searchFrom.dateValue[1],
price:this.searchFrom.priceList.toString(),
};
orderCountApi(json).then(res=>{
if(res.length>0){
let f = res[0];
this.tableData = res;
this.headList=[];
for(let s in f){
if(s==='cur_date'){
this.headList.push('时间')
}else if(s==='register_num'){
this.headList.push('注册数')
}else if(s==='total_money'){
this.headList.push('总金额')
}else{
this.headList.push(s)
}
}
}
})
}
},
defaultTime(){
let date = new Date();
let year = date.getFullYear();
let Month = date.getMonth()+1;
if(Month < 10){
Month = `0${Month}`
}
let Day = date.getDate();
if(Day<10)Day = `0${Day}`
let star = `${year}-${Month}-01`;
let end = `${year}-${Month}-${Day}`
this.searchFrom.dateValue = [star,end]
}
}
}
</script>
<style scoped lang="less">
.orderCount{
padding: 10px;
}
</style>