<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item :label="tLang('quality', '产品名称')" prop="productName">
                <el-input v-model="queryParams.productName"
                    :placeholder="tLang('common', '请输入') + tLang('quality', '产品名称')" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item :label="tLang('quality', '产品编码')" prop="productCode">
                <el-input v-model="queryParams.productCode"
                    :placeholder="tLang('common', '请输入') + tLang('quality', '产品编码')" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item :label="tLang('quality', '产品序列号')" prop="serialNumber">
                <el-input v-model="queryParams.serialNumber"
                    :placeholder="tLang('common', '请输入') + tLang('quality', '产品序列号')" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item :label="tLang('quality', '员工姓名')" prop="operator">
                <el-input v-model="queryParams.operator"
                    :placeholder="tLang('common', '请输入') + tLang('quality', '员工姓名')" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item :label="tLang('quality', '设备名称')" prop="deviceName">
                <el-input v-model="queryParams.deviceName"
                    :placeholder="tLang('common', '请输入') + tLang('quality', '设备名称')" clearable
                    @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item :label="tLang('quality', '开始时间')" prop="starttime">
                <el-date-picker clearable v-model="queryParams.starttime" type="datetime" format="YYYY-MM-DD hh:mm:ss"
                    value-format="YYYY-MM-DD hh:mm:ss" :placeholder="tLang('common', '请选择') + tLang('quality', '开始时间')">
                </el-date-picker>
            </el-form-item>
            <el-form-item :label="tLang('quality', '完成时间')" prop="endtime">
                <el-date-picker clearable v-model="queryParams.endtime" type="datetime" format="YYYY-MM-DD hh:mm:ss"
                    value-format="YYYY-MM-DD hh:mm:ss" :placeholder="tLang('common', '请选择') + tLang('quality', '完成时间')">
                </el-date-picker>
            </el-form-item>
            <el-form-item :label="tLang('quality', '状态')" prop="state">
                <el-input v-model="queryParams.state" :placeholder="tLang('common', '请输入') + tLang('quality', '状态')"
                    clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="search" size="mini" @click="handleQuery">{{ tLang('common', '搜索')
                    }}</el-button>
                <el-button icon="refresh" size="mini" @click="resetQuery">{{ tLang('common', '重置') }}</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="20" class="mb8">
            <el-col :span="2">
                <el-statistic :title="tLang('quality', '产品合格率')" :value="qualifiedRate" :precision="1"
                    :value-style="{ color: 'green' }"
                    :formatter="(val) => { return ((val / total) * 100).toFixed(1) + '%' }" />
            </el-col>
            <el-col :span="2">
                <el-statistic :title="tLang('quality', '产品不合格率')" :value="unqualifiedRate" :precision="1"
                    :value-style="{ color: 'red' }"
                    :formatter="(val) => { return ((val / total) * 100).toFixed(1) + '%' }" />
            </el-col>
            <el-col :span="2">
                <el-statistic :title="tLang('quality', '产品完成量')" :value="total" />
            </el-col>
            <!-- <el-col :span="1.5">
          <el-button type="warning" plain icon="download" size="mini" @click="handleExport"
            v-hasPermi="['product:product:export']">导出</el-button>
        </el-col> -->
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="qualityList" @selection-change="handleSelectionChange">
            <!-- <el-table-column type="selection" width="55" align="center" /> -->
            <el-table-column type="index" :label="tLang('common', '序号')" width="60" align="center" />
            <el-table-column :label="tLang('quality', '产品名称')" v-if="columns[0].visible" align="center"
                prop="productName" />
            <el-table-column :label="tLang('quality', '产品编码')" v-if="columns[1].visible" align="center"
                prop="productCode" />
            <el-table-column :label="tLang('quality', '产品序列号')" v-if="columns[2].visible" align="center"
                prop="serialNumber" />
            <el-table-column :label="tLang('quality', '员工姓名')" v-if="columns[3].visible" align="center"
                prop="operator" />
            <el-table-column :label="tLang('quality', '设备名称')" v-if="columns[4].visible" align="center"
                prop="deviceName" />
            <el-table-column :label="tLang('quality', '开始时间')" v-if="columns[5].visible" align="center" prop="startTime"
                width="180">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.starttime, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :label="tLang('quality', '完成时间')" v-if="columns[6].visible" align="center" prop="endTime"
                width="180">
                <template #default="scope">
                    <span>{{ parseTime(scope.row.endtime, '{y}-{m}-{d} {hh}:{mm}:{ss}') }}</span>
                </template>
            </el-table-column>
            <el-table-column :label="tLang('quality', '状态')" v-if="columns[7].visible" align="center" prop="state">
                <template #default="scope">
                    <div>
                        <el-tag type="success" size="mini" v-if="scope.row.state === '0'">{{tLang('common','合格')}}</el-tag>
                        <el-tag type="danger" size="mini" v-else-if="scope.row.state === '1'">{{tLang('common','不合格')}}</el-tag>
                        <el-tag type="error" size="mini" v-else>{{tLang('common','未完成')}}</el-tag>
                    </div>
                </template>
            </el-table-column>
            <!-- <el-table-column :label="tLang('quality','')操作" align="center" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-tooltip content="详情" placement="top" v-if="scope.row.userId !== 1">
                        <el-button link type="primary" icon="Tickets" @click="handleInfo(scope.row)"
                            v-hasPermi="['casm:produce:info']"></el-button>
                    </el-tooltip>
                    <el-tooltip content="修改" placement="top" v-if="scope.row.userId !== 1">
                        <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                            v-hasPermi="['casm:produce:edit']"></el-button>
                    </el-tooltip>
                    <el-tooltip content="删除" placement="top" v-if="scope.row.userId !== 1">
                        <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                            v-hasPermi="['casm:produce:remove']"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column> -->
        </el-table>

        <div class="pagination">
            <el-pagination :hide-on-single-page="true" v-model:current-page="queryParams.pageNum"
                v-model:page-size="queryParams.pageSize" :page-sizes="[25, 50, 100, 150]"
                layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="getList"
                @current-change="getList" />
        </div>


    </div>
</template>

<script setup>
import { ref, reactive, watch, onMounted } from 'vue'
import { listQuality, qualitystandardRate } from "@/api/casm/quality";
const { proxy } = getCurrentInstance();

// 遮罩层
let loading = ref(true)
// 选中数组
let ids = ref([])
// 非单个禁用
let single = ref(true)
// 非多个禁用
let multiple = ref(true)
// 显示搜索条件
let showSearch = ref(false)
// 查询参数
let queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    productionCode: null,
    deviceCode: null,
    persionCode: null,
    planOutput: null,
    output: null,
    starttime: null,
    endtime: null,
    batch: null,
})

let total = ref(0)
// 设备信息表格数据
let qualityList = ref([
    { name: '设备1', code: 'code1', id: 1 },
])
// 列显隐信息
const columns = ref([
    { key: 0, label: proxy.tLang('quality', '产品名称'), visible: true },
    { key: 1, label: proxy.tLang('quality', '产品编码'), visible: true },
    { key: 2, label: proxy.tLang('quality', '产品序列号'), visible: true },
    { key: 3, label: proxy.tLang('quality', '员工姓名'), visible: true },
    { key: 4, label: proxy.tLang('quality', '设备名称'), visible: true },
    { key: 5, label: proxy.tLang('quality', '开始时间'), visible: true },
    { key: 6, label: proxy.tLang('quality', '完成时间'), visible: true },
    { key: 7, label: proxy.tLang('quality', '状态'), visible: true },
]);

let qualifiedRate = ref(1)
let unqualifiedRate = ref(1)
/** 查询设备信息列表 */
function getList() {
    loading.value = true;
    qualitystandardRate().then(response => {
        if (response.code === 200) {
            qualifiedRate.value = response.data.on
            unqualifiedRate.value = response.data.off
        }
    })
    listQuality(queryParams).then(response => {
        qualityList.value = response.rows;
        total.value = response.total;
        loading.value = false;
    });
}
// 多选框选中数据
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.id)
    single.value = selection.length !== 1
    multiple.value = !selection.length
}

//** 搜索按钮操作 */
function handleQuery() {
    queryParams.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    queryParams.pageNum = 1
    queryParams.pageSize = 10
    queryParams.name = null
    queryParams.code = null

    handleQuery();
}




onMounted(() => {
    getList();
})
</script>

<style lang="scss" scoped>
.pagination {
    width: 100%;
    margin: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}
</style>