<template>
    <div class="app-container">
        <el-card>
            <el-descriptions :column="2" direction="vertical" :label-style="{ 'text-align': 'center' }" :content-style="{ 'text-align': 'center', color: '#ff4949', 'font-size': '20px', 'font-weight': 'bold' }">
                <el-descriptions-item label="今日发券数量（张）">{{ sendCount }}</el-descriptions-item>
                <el-descriptions-item label="今日核销券数量（张）">{{ hxCount }}</el-descriptions-item>
            </el-descriptions>
        </el-card>
        <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="80px" style="margin-top: 10px">-->

        <!--      <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" style="margin-top: 10px">
            <span style="margin-left: 20px"> 统计时间： {{ countTime }}</span>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" fit highlight-current-row border stripe :data="couponItemList">
            <!--      <el-table-column type="selection" width="55" align="center" fixed="left"/>-->
            <el-table-column label="编号" align="center" prop="id" fixed="left" />
            <!--      <el-table-column label="订单编码" align="center" prop="orderNo" />-->
            <el-table-column label="优惠券名称" align="center" prop="couponTypeTitle" width="120" :show-overflow-tooltip="true" />
            <el-table-column label="优惠券类型" align="center" prop="discountWay" width="120" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.coupon_type" :value="scope.row.discountWay" />
                </template>
            </el-table-column>
            <el-table-column label="券值" align="center" prop="deductAmount" width="150">
                <template slot-scope="scope">
                    <span v-if="scope.row.discountWay == 0">满{{ scope.row.minAmount }}元减{{ scope.row.deductAmount }}元</span>
                    <span v-if="scope.row.discountWay == 1">满{{ scope.row.minAmount }}件减{{ scope.row.deductAmount }}件</span>
                    <span v-if="scope.row.discountWay == 2">折扣比例：{{ scope.row.discountRate }}%</span>
                </template>
            </el-table-column>
            <!--      <el-table-column label="活动ID" align="center" prop="activityInfoId" />-->
            <el-table-column label="所属门店" align="center" prop="orgName" width="120" :show-overflow-tooltip="true" />
            <el-table-column label="客户姓名" align="center" prop="appUserName" width="100" />
            <el-table-column label="客户手机号" align="center" prop="appUserPhone" width="120" />

            <el-table-column label="有效期开始时间" align="center" prop="startDate" width="180"> </el-table-column>
            <el-table-column label="有效期结束时间" align="center" prop="endDate" width="180"> </el-table-column>
            <el-table-column label="活动名称" align="center" prop="activityTitle" width="120" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    <sapn>{{ scope.row.activityTitle ? scope.row.activityTitle : '--' }}</sapn>
                </template>
            </el-table-column>
            <!--            <el-table-column label="是否单件抵扣券" align="center" prop="isUnique" width="180">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isUnique" />-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--      <el-table-column label="是否手动发券" align="center" prop="canManual" width="180">-->
            <!--        <template slot-scope="scope">-->
            <!--          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.canManual"/>-->
            <!--        </template>-->
            <!--      </el-table-column>-->
            <el-table-column label="是否核销" align="center" prop="isUsed" width="80">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isUsed" />
                </template>
            </el-table-column>
            <!--            <el-table-column label="抵用金额（元）" align="center" prop="deductAmount" width="120" />-->
            <el-table-column label="发券时间" align="center" prop="createTime" width="160" />
            <el-table-column label="核销时间" align="center" prop="usedTime" width="180"> </el-table-column>
            <!--      <el-table-column label="核销订单编码" align="center" prop="deductOrderNo" width="150"/>-->
        </el-table>

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

<script>
import { countFinancialStatisticsByFactoryWithToday, listFinancialStatisticsByFactoryWithToday } from '@/api/order/cloth'
import { getStoreByFactoryId } from '@/api/system/store'
import { listCouponSendCount, todayCouponSendCountByStore } from '@/api/activity/couponInfo'

export default {
    name: 'couponDay',
    dicts: ['coupon_type', 'sys_yes_no'],
    data() {
        return {
            tabs: '0',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 洗衣订单衣服明细表格数据
            clothOrderList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                beginCreateTimeToInFactory: '',
                endCreateTimeToInFactory: ''
            },
            createTimeRange: [],
            countTime: '', // 统计时间
            sendCount: 0, // 发券数
            hxCount: 0, // 核销数
            totalStatementMoney: 0, // 今日结算金额
            storeList: [],
            pickerOptions: {
                onPick: this.getPickDate,
                disabledDate: this.disabledDate
            },
            pickDate: '' // 存放getPickDate获取的数据
        }
    },
    created() {
        // this.setDefaultRange();
        // this.getStoreList();
        this.getCount()
        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
                }
            }
        },
        getStoreList() {
            getStoreByFactoryId().then((response) => {
                this.storeList = response.data
            })
        },
        getCount() {
            todayCouponSendCountByStore().then((response) => {
                this.sendCount = response.data.sendTotal
                this.hxCount = response.data.hxtotal
            })
        },
        getList() {
            this.getNowTime()
            this.loading = true
            listCouponSendCount(this.queryParams).then((response) => {
                this.couponItemList = response.data.records
                this.total = response.data.total
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            // this.createTimeRange = null;
            this.queryParams.beginCreateTimeToInFactory = null
            this.queryParams.endCreateTimeToInFactory = null
            this.queryParams.orgId = 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(() => {})
        },
        getNowTime() {
            var day = new Date()
            let seconds = day.getSeconds()
            if (seconds < 10) {
                // 如果月份值小于10，则在前面加上0
                seconds = '0' + seconds
            } else {
                seconds = seconds
            }
            let minutes = day.getMinutes()
            if (minutes < 10) {
                minutes = '0' + minutes
            } else {
                minutes = minutes
            }
            let month = day.getMonth()
            if (month < 10) {
                month = '0' + month
            }
            this.countTime = day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate() + ' ' + day.getHours() + ':' + minutes + ':' + seconds
        }
    }
}
</script>
