<template>
    <div class="execution">
        <basic-container>
            <avue-crud ref="crud"
                       :page.sync="page"
                       :data="tableData"
                       :permission="permissionList"
                       :table-loading="tableLoading"
                       :option="tableOption"
                       @selection-change="onSelectionChange"
                       @on-load="getList"
                       @search-change="searchChange"
                       @refresh-change="refreshChange"
                       @size-change="sizeChange"
                       @current-change="currentChange">
                       <template slot="images" slot-scope="scope" >
                         <div class="layout_h">
                           <el-image
                               v-for="(url, index) in (scope.row.images ? scope.row.images.split(',') : [])"
                               style="width: 50px; height: 50px; margin-right: 5px;"
                               fit="cover"
                               :key="url"
                               :src="url"
                               :preview-src-list="scope.row.images.split(',')">
                           </el-image>
                         </div>
                       </template>
                       <template slot-scope="{row,index}" slot="menu">
                           <el-button
                               v-if="isPermit('feedback_handle') && row.status == 'wait'"
                               type="text"
                               size="small"
                               @click="onAUth(row)">立即处理</el-button>
                            <el-button
                                v-if="isPermit('feedback_delete') && row.status == 'done'"
                                type="text"
                                size="small"
                                @click="onDelete(row)">删除记录</el-button>
                       </template>

                       <template slot="menuLeft">
                           <el-button
                               v-if="permissions.feedback_delete"
                               class="filter-item"
                               plain
                               type="primary"
                               size="small"
                               @click="batchDelete">删除记录
                           </el-button>
                       </template>
            </avue-crud>
        </basic-container>

    </div>
</template>

<script>
    import {fetchList} from '@/api/financial/details.js'
    import {tableOption} from '@/const/crud/financial/details.js'
    import {mapGetters} from 'vuex'
    import {
      ZmMixin
    } from '@/mixins/ZmMixin.js'

    export default {
        name: 'userWIthdraw',
        mixins: [ZmMixin],
        data() {
            return {
                nowId: '',
                searchForm: {},
                tableData: [],
                selectedData: [],
                page: {
                    total: 0, // 总页数
                    currentPage: 1, // 当前页数
                    pageSize: 20 // 每页显示多少条
                },
                showAuth: false,
                tableLoading: false,
                tableOption: tableOption
            }
        },
        computed: {
            ...mapGetters(['permissions']),
            permissionList() {
                return {
                    addBtn: this.vaildData(this.permissions.user_withdraw_export, false),
                    delBtn: this.vaildData(this.permissions.general_basesystemmoney_del, false),
                    editBtn: this.vaildData(this.permissions.general_basesystemmoney_edit, false)
                };
            }
        },
        methods: {
          queryParams(page, params) {
            let p = {
              current: page.currentPage,
              size: page.pageSize
            }
            if(params) {
              let range = this.parseRange(params)
              p = {
                ...p,
                startTime: range[0],
                endTime: range[1],
                way: params.type
              }
            }
            return p
          },
            // 列表查询
            getList(page, params) {
                this.tableLoading = true
                let p = this.queryParams(page, params)
                fetchList(p).then(response => {
                    this.tableData = response.data.data.records
                    this.page.total = response.data.data.total
                    this.tableLoading = false
                }).catch(() => {
                    this.tableLoading=false
                })
            },
            // 每页条数改变事件
            sizeChange(pageSize){
                this.page.pageSize = pageSize
            },
            // 当前页发生改变事件
            currentChange(current){
                this.page.currentPage = current
            },
            // 查询事件
            searchChange(form, done) {
                this.searchForm = form
                this.page.currentPage = 1
                this.getList(this.page, form)
                done()
            },
            // 刷新事件
            refreshChange() {
                this.getList(this.page)
            },
            //选择事件
            onSelectionChange(r) {
              this.selectedData = r
            },
        }
    }
</script>
