<template>
    <transition appear enter-active-class="animated fadeIn">
        <q-card class="shadow-24">
            <!-- 搜索条件 -->
            <q-card-section>
                <div class="row q-col-gutter-md">
                    <!-- 刷新 查询 -->
                    <div class="col-xl-2 col-lg-2 col-sm-12">
                        <q-btn-group push glossy>
                            <q-btn push label="新增" icon="add" @click="addOrEditForm()">
                                <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
                                    content-style="font-size: 12px">{{
                                        '新增一条数据' }}</q-tooltip>
                            </q-btn>
                            <q-btn push label="刷新" icon="refresh" @click="reFresh()">
                                <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
                                    content-style="font-size: 12px">清空所有条件并，刷新数据</q-tooltip>
                            </q-btn>
                            <q-btn push label="查询" icon="search" @click="getPage()">
                                <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
                                    content-style="font-size: 12px">按条件查询数据</q-tooltip>
                            </q-btn>
                        </q-btn-group>
                    </div>
                    <!-- 搜索条件 -->
                    <div class="col-xl-2 col-lg-2 col-sm-12">
                        <q-input dense label="设备编码" outlined v-model="pagination.data.equipmentCode" />
                    </div>
                    <div class="col-xl-2 col-lg-2 col-sm-12">
                        <q-input dense label="设备名称" outlined v-model="pagination.data.equipmentName" />
                    </div>
                    <div class="col-xl-2 col-lg-2 col-sm-12">
                        <q-select dense outlined v-model="pagination.data.equipmentType" :options="equipmentTypeList"
                            emit-value map-options label="设备类型" />
                    </div>
                    <div class="col-xl-2 col-lg-2 col-sm-12">
                        <q-select dense outlined v-model="pagination.data.activated" :options="activatedList" emit-value
                            map-options label="设备启停用" />
                    </div>
                </div>
            </q-card-section>
            <q-card-section style="padding:0 10px 15px 10px;">
                <div class="row q-col-gutter-md">
                    <div class="col-xl-12 col-lg-12 col-sm-12">
                        <q-table class="my-sticky-header-column-table" :rows="list" row-key="id" separator="cell"
                            :loading="loading" :columns="columns" @request="onRequest" v-model:pagination="pagination"
                            :table-style="{ height: Screen.height - 190 + 'px' }" flat bordered
                            :rows-per-page-options="[20, 30, 40, 50, 100]">
                            <template v-slot:body="props">
                                <q-tr :props="props" class="tr_hover">
                                    <q-td style="font-size: 16px;" key="index" :props="props">{{ props.rowIndex + 1
                                    }}</q-td>
                                    <q-td style="font-size: 16px;" key="equipmentCode" :props="props">{{
                                        props.row.equipmentCode
                                    }}</q-td>
                                    <q-td style="font-size: 16px;" key="equipmentName" :props="props">{{
                                        props.row.equipmentName
                                    }}</q-td>
                                    <q-td style="font-size: 16px;" key="equipmentType" :props="props">{{
                                        props.row.equipmentType
                                    }}</q-td>
                                    <q-td style="font-size: 16px;" key="state" :props="props"><q-badge
                                            style="font-size: 18px;height:30px;"
                                            :color="helper.getEquipmentState(props.row.state).color"
                                            :label="helper.getEquipmentState(props.row.state).text" />
                                    </q-td>
                                    <q-td style="font-size: 16px;" key="model" :props="props"><q-badge
                                            style="font-size: 18px;height:30px;"
                                            :color="helper.getModel(props.row.model).color"
                                            :label="helper.getModel(props.row.model).text" />
                                    </q-td>
                                    <q-td style="font-size: 16px;" key="isAlarm" :props="props"><q-badge
                                            style="font-size: 18px;height:30px;"
                                            :color="helper.getIsAlarm(props.row.isAlarm).color"
                                            :label="helper.getIsAlarm(props.row.isAlarm).text" />
                                    </q-td>
                                    <q-td style="font-size: 16px;" key="ordrNo" :props="props">{{
                                        props.row.ordrNo
                                    }}</q-td>
                                    <q-td style="font-size: 16px;" key="activated" :props="props">
                                        <q-badge size="" style="font-size: 18px;height:30px;"
                                            :color="props.row.activated == true ? 'green' : 'red'"
                                            :label="props.row.activated == true ? '启用' : '停用'" />
                                    </q-td>
                                    <q-td style="font-size: 16px;" key="remark" :props="props">{{ props.row.remark }}</q-td>
                                    <q-td key="action" :props="props" style="width: 100px">
                                        <q-btn round flat push color="info" icon="edit" @click="addOrEditForm(props.row)">
                                            <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
                                                content-style="font-size: 12px">编辑这条数据</q-tooltip>
                                        </q-btn>
                                        <q-btn round flat push color="negative" icon="delete"
                                            @click="openDelDialog(props.row)">
                                            <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
                                                content-style="font-size: 12px">删除这条数据</q-tooltip>
                                        </q-btn>
                                    </q-td>
                                </q-tr>
                            </template>
                        </q-table>
                    </div>
                </div>
            </q-card-section>
        </q-card>
    </transition>

    <!-- 系统参数设置 -->
    <addOrEditDialog ref="addOrEdit" @refresh="getPage" />
    <!-- 删除弹窗 -->
    <customDialog ref="deleteDialogRef" @func="delFunc" />
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { Notify, Screen } from 'quasar';
import { equipmentApi } from '../../api/equipment/equipmentApi';
import { EquipmentSearchEntity } from '../../api/equipment/model/equipment';
import { Pagination, cconvert } from 'src/api/class';
import customDialog from 'src/components/customDialog.vue';
import addOrEditDialog from 'src/pages/equipment/components/addOrEditDialog.vue'
import helper from 'src/Utils/helper';

//公共
const equipmentTypeList = ref([
    { label: 'Ionbond', value: 'Ionbond' },
    { label: 'Balzers', value: 'Balzers' },
    { label: 'CemeCon', value: 'CemeCon' },
])
const activatedList = ref([
    { label: '启用', value: true },
    { label: '停用', value: false }
])
const pagination = ref(new Pagination(new EquipmentSearchEntity()));
const loading = ref(false);

const columns = ref([
    {
        name: 'index',
        label: '序号',
        field: 'index',
        align: 'center',
        headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;',
    },
    {
        name: 'equipmentCode',
        align: 'center',
        label: '设备编码',
        field: 'equipmentCode',
        headerClasses: 'text-h4 text-weight-bold',
        headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;',
    },
    { name: 'equipmentName', align: 'center', label: '设备名称', field: 'equipmentName', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'equipmentType', align: 'center', label: '设备类型', field: 'equipmentType', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'state', align: 'center', label: '设备状态', field: 'state', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'model', align: 'center', label: '模式', field: 'model', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'isAlarm', align: 'center', label: '是否报警', field: 'isAlarm', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'ordrNo', align: 'center', label: '排序', field: 'ordrNo', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'activated', align: 'center', label: '设备启停用', field: 'activated', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'remark', align: 'center', label: '所属涂层室', field: 'remark', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' },
    { name: 'action', align: 'center', label: '操作', field: 'action', headerStyle: 'background-color: #5186ec;color: white;font-weight: bold;font-size:20px;' }
])

const list = ref([]);

onMounted(() => {
    getPage();
})

const reFresh = () => {
    pagination.value.data = new EquipmentSearchEntity();
    getPage();
};

const onRequest = (props: any) => {
    const { page, rowsPerPage, rowsNumber } = props.pagination;
    pagination.value.page = page;
    pagination.value.rowsPerPage = rowsPerPage != 0 ? rowsPerPage : rowsNumber;
    getPage();
};

const getPage = () => {
    equipmentApi.getEquipmentPageList(pagination.value).then((res: any) => {
        list.value = res.data;
        cconvert(pagination.value, res);
    });
}

const addOrEdit = ref();
const addOrEditForm = (row?: any) => {
    addOrEdit.value.clickForm(row);
};

const deleteDialogRef = ref();
const openDelDialog = (row: any) => {
    deleteDialogRef.value.open(row);
}
const delFunc = (e: any) => {
    equipmentApi.delete(e.id).then(() => {
        getPage();
    });
};

</script>
<style scoped>
/* .tr_hover {
    background: #aaaaaa;
  } */

.tr_hover:hover {
    background: #e8e8e8;
}

.click-hover {
    cursor: pointer;
    color: #1976d2;
}

.click-hover:hover {
    color: #2196f3;
    /* background-color: yellow; */
}
</style>