<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="衣物数量（件）">{{ totalCloth }}</el-descriptions-item>
                <el-descriptions-item label="结算金额（元）">{{ totalStatementPrice }}</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 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="门店名称">
                <el-select v-model="queryParams.orgId" placeholder="请选择门店名称" clearable>
                    <el-option v-for="org in storeList" :key="org.id" :label="org.name" :value="org.id" />
                </el-select>
            </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">
            <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="clothOrderList" style="margin-top: 10px">
            <el-table-column label="门店名称" align="center" prop="storeName" width="200" />

            <el-table-column label="衣物总件数" align="center" prop="countTotalCloth"> </el-table-column>
            <el-table-column label="已完成衣物" align="center" prop="countFinishCloth"> </el-table-column>
            <el-table-column label="清洗中衣物" align="center" prop="countWashCloth"> </el-table-column>
            <el-table-column label="已检查衣物" align="center" prop="countCheckCloth"> </el-table-column>
            <el-table-column label="总金额（元）" align="center" prop="totalPrice"> </el-table-column>
            <el-table-column label="结算费率" align="center" prop="statementRate"> </el-table-column>
            <el-table-column label="结算金额（元）" align="center" prop="totalStatementPrice" />
        </el-table>

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

<script>
import { countFinancialStatisticsByFactoryOperate } from '@/api/order/cloth'
import { getStoreByFactoryId } from '@/api/system/store'

export default {
    name: 'factoryManageCount',
    dicts: [],
    data() {
        return {
            tabs: '0',
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 洗衣订单衣服明细表格数据
            clothOrderList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                beginCreateTime: '',
                endCreateTime: ''
            },
            createTimeRange: [],
            totalCloth: 0, // 衣服总数量
            totalStatementPrice: 0, // 结算总金额
            countTime: '', // 统计时间
            storeList: [],
            pickerOptions: {
                onPick: this.getPickDate,
                disabledDate: this.disabledDate
            },
            pickDate: '' // 存放getPickDate获取的数据
        }
    },
    created() {
        this.setDefaultRange()
        this.getStoreList()
        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
            })
        },
        getList() {
            this.getNowTime()
            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
            }
            countFinancialStatisticsByFactoryOperate(this.queryParams).then((response) => {
                this.clothOrderList = response.data.factoryStatisticsListQueryVOList
                this.totalCloth = response.data.totalCloth
                this.totalStatementPrice = response.data.totalStatementPrice
                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.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>
