MrShi
2025-03-19 5965c857d575f5b4ebc6e73345c992f4f5def4a3
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<template>
    <TableLayout :permissions="['business:wxbill:query']">
        <!-- 搜索表单 -->
        <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
            <el-form-item label="对账日期" prop="name">
                <el-date-picker
                    v-model="value1"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    :picker-options="pickerOptions"
                    format="yyyy-MM-dd" value-format="yyyy-MM-dd HH:mm:ss"
                    @change="selectDate"
                ></el-date-picker>
            </el-form-item>
            <section>
                <el-button type="primary" @click="search">搜索</el-button>
                <el-button @click="reset">重置</el-button>
                <el-button type="primary" @click="daochu">导出</el-button>
            </section>
        </el-form>
        <!-- 表格和分页 -->
        <template v-slot:table-wrap>
            <el-table
                v-loading="isWorking.search"
                :data="list"
                stripe
                border
            >
                <el-table-column :prop="item" :label="item" align="center" v-for="(item, index) in column" :key="index"></el-table-column>
            </el-table>
        </template>
    </TableLayout>
</template>
 
<script>
  import BaseTable from '@/components/base/BaseTable'
  import TableLayout from '@/layouts/TableLayout'
  import Pagination from '@/components/common/Pagination'
  import { getBikeIncomeReportVOList, bikeIncomeExportExcel } from '@/api/business/goodsorder'
  export default {
    name: 'analysis',
    extends: BaseTable,
    components: { TableLayout, Pagination },
    data () {
      return {
        value1: [],
        list: [],
        column: [],
        // 搜索
        searchForm: {
          endDate: '',
          startDate: ''
        },
        sumData: {
        },
        pickerOptions: {}
      }
    },
    created () {
      this.config({
        module: '',
        api: '/business/wxBill',
        'field.id': 'id',
        'field.main': 'id'
      })
      this.pickerOptions.disabledDate = (time) => {
        // 一天
        const tempTime = 3600 * 1000 * 24
        return time.getTime() > new Date() - tempTime
      }
      const yesterday = new Date();
      yesterday.setDate(yesterday.getDate() - 1);
      const startDate = new Date(yesterday);
      startDate.setDate(startDate.getDate() - 30);
      this.searchForm.startDate = startDate.toISOString().split('T')[0] + ' 00:00:00'
      this.searchForm.endDate = yesterday.toISOString().split('T')[0] + ' 00:00:00'
      this.value1 = [this.searchForm.startDate, this.searchForm.endDate]
      this.search()
    },
    methods: {
      search() {
        getBikeIncomeReportVOList({
          startDate: this.searchForm.startDate,
          endDate: this.searchForm.endDate
        }).then(res => {
          this.column = res.map(item => item[0])
 
          const keys = res.map(row => row[0]); // 获取键名
          const values = res.map(row => row.slice(1, row.length)); // 获取值
 
          this.list = values[0].map((_, index) => {
            return keys.reduce((obj, key, i) => {
              obj[key] = values[i][index];
              return obj;
            }, {});
          });
        })
      },
      daochu() {
        bikeIncomeExportExcel({
          startDate: this.searchForm.startDate,
          endDate: this.searchForm.endDate
        }).then(res => {
          this.download(res)
          console.log(res.data)
        })
      },
      reset () {
        const yesterday = new Date();
        yesterday.setDate(yesterday.getDate() - 1);
        const startDate = new Date(yesterday);
        startDate.setDate(startDate.getDate() - 30);
        this.searchForm.startDate = startDate.toISOString().split('T')[0] + ' 00:00:00'
        this.searchForm.endDate = yesterday.toISOString().split('T')[0] + ' 00:00:00'
        this.value1 = [this.searchForm.startDate, this.searchForm.endDate]
        this.search()
      },
      getDays(startDate, endDate) {
        const date1 = new Date(startDate); // 第一个日期
        const date2 = new Date(endDate); // 第二个日期
 
        const timeDifference = date2 - date1;
 
        return timeDifference / (1000 * 3600 * 24);
      },
      selectDate (v) {
        // this.searchForm.startDate = ''
        // this.searchForm.endDate = ''
        if (v) {
          if (this.getDays(v[0], v[1]) > 30) {
            this.$message.warning('最多只能选择30天')
            const yesterday = new Date();
            yesterday.setDate(yesterday.getDate() - 1);
            const startDate = new Date(yesterday);
            startDate.setDate(startDate.getDate() - 30);
            this.searchForm.startDate = startDate.toISOString().split('T')[0] + ' 00:00:00'
            this.searchForm.endDate = yesterday.toISOString().split('T')[0] + ' 00:00:00'
            this.value1 = [this.searchForm.startDate, this.searchForm.endDate]
          } else {
            this.searchForm.startDate = v[0]
            this.searchForm.endDate = v[1]
          }
        }
        this.search()
      },
      // 页码变更处理
      handlePageChange (pageIndex) {
        this.__checkApi()
        this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
        this.isWorking.search = true
        this.api.fetchList({
          page: this.tableData.pagination.pageIndex,
          capacity: this.tableData.pagination.pageSize,
          model: this.searchForm,
          sorts: this.tableData.sorts
        })
          .then(data => {
            this.tableData.list = data.records
            this.tableData.pagination.total = data.total
            this.sumData = data.extData
          })
          .catch(e => {
            this.$tip.apiFailed(e)
          })
          .finally(() => {
            this.isWorking.search = false
          })
      }
    }
  }
</script>
<style lang="scss" scoped>
    ::v-deep .el-table tbody tr:last-child {
        font-size: 16px;
        font-weight: bold;
        background-color: #f3f3fb;
    }
    .sum {
        display: flex;
        font-size: 16px;
        margin-bottom: 10px;
        background-color: rgb(243, 243, 251);
        .sum-title {
            flex-shrink: 0;
            background-color: rgb(111, 129, 198);
            color: #fff;
            font-weight: 500;
            text-align: center;
            padding: 15px;
        }
        .sum-value {
            padding: 15px 30px;
            :first-child {
                font-size: 14px;
            }
            :last-child {
                font-weight: 600;
            }
        }
    }
</style>