<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" @submit.native.prevent :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item>
                <el-date-picker v-model="createTimeRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <Page uri="/mapi/recharge/card/getBillMstrInfoList" :request-params="queryParams" ref="pagination">
            <el-table-column label="订单编号" align="center" prop="orderNo" width="200" fixed="left" />
            <el-table-column label="订单类型" align="center" prop="orderType" width="100">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.order_type" :value="scope.row.orderType" />
                </template>
            </el-table-column>
            <el-table-column label="总金额（元）" align="center" prop="payTotalAmount" width="110">
                <template slot-scope="scope">
                    {{ scope.row.isRefund == 'Y' && scope.row.payTotalAmount.toString() != '0' ? '退款：' + scope.row.payTotalAmount.toString().replace('-', '') : scope.row.payTotalAmount.toString().replace('-', '') }}
                </template>
            </el-table-column>
            <el-table-column label="客户姓名" align="center" prop="userName" width="90" />
            <el-table-column label="客户手机号" align="center" prop="phoneNumber" width="130" />
            <el-table-column label="支付方式" align="center" prop="payType" width="80">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.recharge_pay_type" :value="scope.row.payType" />
                </template>
            </el-table-column>
            <el-table-column label="收银门店" align="center" width="120">
                <template slot-scope="scope">
                    <span v-if="scope.row.sourceType == '02'">{{ scope.row.orgName }}</span>
                    <span v-if="scope.row.sourceType == '00'">总部</span>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="createTime" width="160" />
            <el-table-column label="现金支付金额（元）" align="center" width="140">
                <template slot-scope="scope">
                    {{ scope.row.isRefund == 'Y' && scope.row.cashPayAmount.toString() != '0' ? '退款：' + scope.row.cashPayAmount.toString().replace('-', '') : scope.row.cashPayAmount.toString().replace('-', '') }}
                </template>
            </el-table-column>
            <el-table-column label="充值余额支付金额（元）" align="center" width="170">
                <template slot-scope="scope">
                    {{ scope.row.isRefund == 'Y' && scope.row.rechargePayAmount.toString() != '0' ? '退款：' + scope.row.rechargePayAmount.toString().replace('-', '') : scope.row.rechargePayAmount.toString().replace('-', '') }}
                </template>
            </el-table-column>
            <el-table-column label="赠送余额支付金额（元）" align="center" width="170">
                <template slot-scope="scope">
                    {{ scope.row.isRefund == 'Y' && scope.row.givePayAmount.toString() != '0' ? '退款：' + scope.row.givePayAmount.toString().replace('-', '') : scope.row.givePayAmount.toString().replace('-', '') }}
                </template>
            </el-table-column>
            <el-table-column label="福利金余额支付金额（元）" align="center" width="180">
                <template slot-scope="scope">
                    {{ scope.row.isRefund == 'Y' && scope.row.welfarePayAmount.toString() != '0' ? '退款：' + scope.row.welfarePayAmount.toString().replace('-', '') : scope.row.welfarePayAmount.toString().replace('-', '') }}
                </template>
            </el-table-column>
        </Page>
    </div>
</template>

<script>
import { getBillMstrInfoList } from '@/api/recharge/card'

export default {
    name: 'CashStatement',
    dicts: ['sys_yes_no', 'recharge_pay_type', 'order_type'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 洗衣订单衣服明细表格数据
            clothOrderList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                phoneNumber: null,
                userId: null,
                beginCreateTime: '',
                endCreateTime: ''
            },
            createTimeRange: [],
            countCloth: 0,
            countWillMoney: 0,
            countAlreadyMoney: 0,
            pickerOptions: {
                onPick: this.getPickDate,
                disabledDate: this.disabledDate
            },
            pickDate: '' // 存放getPickDate获取的数据
        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            if (null != this.createTimeRange && '' != this.createTimeRange) {
                this.queryParams['beginCreateTime'] = this.createTimeRange[0]
                this.queryParams['endCreateTime'] = this.createTimeRange[1]
            } else {
                delete this.queryParams.beginCreateTime
                delete this.queryParams.endCreateTime
            }
            this.$nextTick(() => {
                this.$refs.pagination.handleSearch(true)
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.createTimeRange = null
            this.queryParams.beginCreateTime = null
            this.queryParams.endCreateTime = null
            this.resetForm('queryForm')
            this.handleQuery()
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        checkClose(done) {
            this.$confirm('是否关闭表单，关闭后数据将丢失？')
                .then(function () {
                    done()
                })
                .then(() => {})
                .catch(() => {})
        }
    }
}
</script>
