<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="订单条码" prop="orderNo">
                <el-input v-model="queryParams.orderNo" placeholder="请输入订单条码" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="交易时间">
                <el-date-picker v-model="createTimeRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :clearable="false" :picker-options="pickerOptions"></el-date-picker>
            </el-form-item>
            <el-form-item label="会员手机" prop="phoneNumber">
                <el-input v-model.number="queryParams.phoneNumber" placeholder="请输入会员手机" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="会员条码" prop="userId">
                <el-input v-model="queryParams.userId" placeholder="会员条码" clearable @keyup.enter.native="handleQuery" />
            </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">
            <el-card>
                <span>
                    累计衣服件数： <span style="color: #ff4949">{{ countCloth }}</span> 件
                </span>
                <span style="margin-left: 20px">
                    合计应收金额： <span style="color: #ff4949">{{ countWillMoney }}</span> 元</span
                >
                <span style="margin-left: 20px">
                    合计实收金额： <span style="color: #ff4949">{{ countAlreadyMoney }}</span
                    >元</span
                >
            </el-card>
        </el-row>
        <el-row :gutter="10" class="mb8">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" fit highlight-current-row border stripe :data="clothOrderList" style="margin-top: 10px">
            <el-table-column label="订单编号" align="center" prop="orderNo" width="200" fixed="left" />
            <el-table-column label="客户姓名" align="center" prop="userName" />
            <el-table-column label="客户手机号" align="center" prop="phoneNumber" width="130" />
            <el-table-column label="衣服件数" align="center" prop="orderClothCount" />
            <el-table-column label="金额（元）" align="center" prop="payAmount" />
            <el-table-column label="实收金额（元）" align="center" prop="alreadyPayAmount" />
            <el-table-column label="收款类型" align="center" prop="payType">
                <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" prop="employeeName" />
            <el-table-column label="交易时间" align="center" prop="createTime" width="160" />
            <el-table-column label="是否付款" align="center" prop="hasPay">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.hasPay" />
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { listCountConsumeByClothOrder } from '../../../api/order/cloth'

export default {
    name: 'CountConsume',
    dicts: ['sys_yes_no', 'recharge_pay_type'],
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 洗衣订单衣服明细表格数据
            clothOrderList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                phoneNumber: null,
                userId: null,
                beginCreateTime: '',
                endCreateTime: ''
            },
            createTimeRange: [],
            countCloth: 0,
            countWillMoney: 0,
            countAlreadyMoney: 0,

            pickerOptions: {
                onPick: this.getPickDate,
                disabledDate: this.disabledDate
            },
            pickDate: '' // 存放getPickDate获取的数据
        }
    },
    created() {
        this.setDefaultRange()
        // this.userInfoVO = this.getUserInfo();
        this.getList()
    },
    methods: {
        setDefaultRange() {
            const end = this.formatDates(new Date(), 2)
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            this.createTimeRange = [this.formatDates(start, 2), end]
        },
        getPickDate(pick) {
            this.pickDate = pick
        },
        disabledDate(date) {
            const { minDate, maxDate } = this.pickDate
            if (minDate && !maxDate) {
                const diff = Math.abs(minDate.valueOf() - date.valueOf())
                if (diff > 1000 * 3600 * 24 * 90) {
                    return true
                }
            }
        },
        /** 查询洗衣订单衣服明细列表 */
        getList() {
            this.loading = true
            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
            }
            listCountConsumeByClothOrder(this.queryParams).then((response) => {
                this.clothOrderList = response.data.orderClothCountConsumeVOList
                this.total = response.data.total
                this.countCloth = response.data.totalOrderClothCount
                this.countWillMoney = response.data.totalWillMoney
                this.countAlreadyMoney = response.data.totalAlreadyMoney
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            // this.createTimeRange = null;
            this.queryParams.beginCreateTime = null
            this.queryParams.endCreateTime = null
            this.resetForm('queryForm')
            this.setDefaultRange()
            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>
