<template>
    <basic-container>
        <!-- 累计检查项配置 -->
        <avue-crud :option="option" :table-loading="loading" :data="data" v-model="form" v-model:page="page" ref="crud"
            @row-update="rowUpdate" @row-save="rowSave" @search-change="searchChange" @search-reset="searchReset"
            @selection-change="selectionChange" @current-change="currentChange" @size-change="sizeChange"
            @refresh-change="refreshChange" @on-load="onLoad">

            <template #menu-left>
                <el-button icon="el-icon-plus" type="primary" @click="handleAdd">新增</el-button>
                <el-button icon="el-icon-delete" type="danger" @click="handleDelete">删除</el-button>
                <el-button icon="el-icon-coordinate" type="success" @click="handleMaintain">批量维护</el-button>
            </template>
        </avue-crud>
        <el-dialog title="新增" append-to-body v-model="showDialog" width="80%">
            <div style="margin-bottom: 10px;">
                <el-button type="primary" icon="el-icon-plus" @click="insertEvent()">插入一行</el-button>
                <el-button plain type="danger" @click="remove">删除选择行</el-button>
                <el-button type="primary" @click="handleSave">保存</el-button>
            </div>
            <el-table :data="tableData" @select="selectChange">
                <el-table-column type="selection"></el-table-column>
                <el-table-column align="center" label="作业中心" prop="bsWorkCenter.wcId">
                    <template #default="scope">
                        <el-select v-model="scope.row.bsWorkCenter.wcId">
                            <el-option v-for="item in wcData" :key="item.wcId" :value="item.wcId"
                                :label="item.wcName"></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="作业槽" prop="batchNo">
                    <template #default="scope">
                        <el-select v-model="scope.row.batchNo">
                            <el-option v-for="item in batchNo" :key="item.value" :value="item.value"
                                :label="item.label"></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="规则类型" prop="ruleType">
                    <template #default="scope">
                        <el-select v-model="scope.row.ruleType">
                            <el-option v-for="item in ruleTypeData" :key="item.value" :value="item.value"
                                :label="item.label"></el-option>
                        </el-select>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="维护内容" prop="preserveContent">
                    <template #default="scope">
                        <el-input v-model="scope.row.preserveContent"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="添加量" prop="actualValue">
                    <template #default="scope">
                        <el-input v-model="scope.row.actualValue"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="添加量倍数" prop="actualValueMom">
                    <template #default="scope">
                        <el-input v-model="scope.row.actualValueMom"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="累计触发值" prop="cumulativeTriggerValue">
                    <template #default="scope">
                        <el-input v-model="scope.row.cumulativeTriggerValue"></el-input>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="累计初始值" prop="cumulativeInitialValue">
                    <template #default="scope">
                        <el-input v-if="scope.row.ruleType != 3" v-model="scope.row.cumulativeInitialValue"></el-input>
                        <el-date-picker style="width: 100%;" v-if="scope.row.ruleType == 3"
                            v-model="scope.row.cumulativeInitialValue" type="date" placeholder="选择日期">
                        </el-date-picker>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
        <maintain-dialog :show-maintain="showMaintain" :maintain-data="maintainData" @closeDialog="closeDialog"></maintain-dialog>
        <!-- <el-dialog title="批量维护" append-to-body v-model="showMaintain" width="80%">
            <div style="margin-bottom: 10px;display: flex;align-items: center;">
                <div style="display: flex;align-items: center;margin-right: 10px;">检查结果：
                    <el-radio v-model="isQualified" :label="true">合格</el-radio>
                    <el-radio v-model="isQualified" :label="false">不合格</el-radio>
                </div>
                <el-button type="primary" @click="handleSet">批量设置</el-button>
                <el-button type="primary" @click="maintainValue">保存</el-button>
            </div>
            <el-table :data="maintainData">
                <el-table-column align="center" label="作业中心" prop="bsWorkCenter.wcName"></el-table-column>
                <el-table-column align="center" label="作业槽" prop="batchNo"></el-table-column>
                <el-table-column align="center" label="维护内容" prop="preserveContent"></el-table-column>
                <el-table-column align="center" label="合格/不合格" prop="isQualified">
                    <template #default=scope>
                        <el-radio v-model="scope.row.isQualified" :label="true">合格</el-radio>
                        <el-radio v-model="scope.row.isQualified" :label="false">不合格</el-radio>
                    </template>
                </el-table-column>
                <el-table-column align="center" label="添加量/实测值" prop="actualValue">
                    <template #default="scope">
                        <el-input v-model="scope.row.actualValue"></el-input>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog> -->
    </basic-container>
</template>

<script>
import maintainDialog from './components/maintainDialog.vue';
export default {
    components:{
        maintainDialog
    },
    data() {
        return {
            loading: false,
            data: [],
            selectionList: [],
            form: {},
            isQualified:null,
            showMaintain:false,
            page: {
                pageSize: 10,
                currentPage: 1,
                total: 0,
            },
            batchNo: [
                { label: '作业槽一', value: '1' },
                { label: '作业槽二', value: '2' },
                { label: '作业槽三', value: '3' },
            ],
            ruleTypeData: [
                {
                    label: '电量差类',
                    value: 1
                },
                {
                    label: '累计电量类',
                    value: 2
                },
                {
                    label: '累计生产日期',
                    value: 3
                },
                {
                    label: '主盐添加量类',
                    value: 4
                },
                {
                    label: '累计生产面积',
                    value: 5
                },
                {
                    label: '累计主盐添加量',
                    value: 6
                }
            ],
            wcData: [
                {
                    "area": 13000.0,
                    "batchNo": null,
                    "bigBatch": false,
                    "checkout": false,
                    "craftAbility": "化学镀镍",
                    "createTime": "2023-02-06 12:31:36",
                    "deleted": false,
                    "describe": null,
                    "endPoint": null,
                    "keyValue": 81,
                    "limitType": 0,
                    "processes": "上挂、下挂、交检、化学镀镍、喷砂",
                    "quantity": null,
                    "roundCycle": null,
                    "saturation": 85.0,
                    "sign": "4",
                    "startPoint": null,
                    "team": "化学镀镍一班崔胜伟、化学镀镍一班郭家梁",
                    "updateTime": "2023-03-06 18:42:47",
                    "wcCode": "001",
                    "wcId": 81,
                    "wcName": "化学镀镍作业中心",
                    "whetherPlate": false
                },
                {
                    "area": 0.0,
                    "batchNo": null,
                    "bigBatch": false,
                    "checkout": false,
                    "craftAbility": "镀后接收",
                    "createTime": "2023-02-06 12:48:41",
                    "deleted": false,
                    "describe": null,
                    "endPoint": null,
                    "keyValue": 85,
                    "limitType": 0,
                    "processes": "镀后接收",
                    "quantity": null,
                    "roundCycle": null,
                    "saturation": null,
                    "sign": "4",
                    "startPoint": null,
                    "team": "零件管理班",
                    "updateTime": "2023-03-06 18:23:20",
                    "wcCode": "004",
                    "wcId": 85,
                    "wcName": "镀后库作业中心",
                    "whetherPlate": true
                },
                {
                    "area": 0.0,
                    "batchNo": null,
                    "bigBatch": false,
                    "checkout": true,
                    "craftAbility": "镀后检验",
                    "createTime": "2023-02-06 12:49:33",
                    "deleted": false,
                    "describe": null,
                    "endPoint": null,
                    "keyValue": 86,
                    "limitType": 0,
                    "processes": "镀后检验、性能检测、镀后自检外观检验、镀后自检尺寸检验",
                    "quantity": null,
                    "roundCycle": null,
                    "saturation": null,
                    "sign": "4",
                    "startPoint": null,
                    "team": "检验班",
                    "updateTime": "2023-06-06 15:07:27",
                    "wcCode": "005",
                    "wcId": 86,
                    "wcName": "检验作业中心",
                    "whetherPlate": false
                },
            ],
            showDialog: false,
            tableData: [],
            option: {
                height: 'auto',
                calcHeight: 32,
                rowKey: 'keyValue',
                tip: false,
                size: 'medium',
                simplePage: true,
                searchShow: true,
                searchMenuSpan: 6,
                searchIcon: true,
                searchIndex: 3,
                tree: false,
                border: true,
                index: false,
                selection: true,
                viewBtn: false,
                delBtn: false,
                addBtn: false,
                editBtn: false,
                editBtnText: '修改',
                viewBtnIcon: ' ',
                delBtnIcon: ' ',
                editBtnIcon: ' ',
                viewBtnText: '详情',
                labelWidth: 120,
                searchLabelWidth: 120,
                menu: false,
                menuWidth: 220,
                dialogWidth: 1200,
                dialogClickModal: false,
                searchEnter: true,
                excelBtn: false,
                filterBtn: true,
                searchShowBtn: false,
                columnSort: true,
                excelBtn: true,
                columnSort: true,
                showOverflowTooltip: true,
                column: [
                    {
                        label: '作业中心',
                        prop: 'wcName',
                        type: 'select',
                        bind: 'bsWorkCenter.wcName',
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入作业中心',
                                trigger: 'blur',
                            },
                        ],
                        props: {
                            label: 'wcName',
                            value: 'wcId'
                        },
                        dicData: [
                            {
                                "area": 13000.0,
                                "batchNo": null,
                                "bigBatch": false,
                                "checkout": false,
                                "craftAbility": "化学镀镍",
                                "createTime": "2023-02-06 12:31:36",
                                "deleted": false,
                                "describe": null,
                                "endPoint": null,
                                "keyValue": 81,
                                "limitType": 0,
                                "processes": "上挂、下挂、交检、化学镀镍、喷砂",
                                "quantity": null,
                                "roundCycle": null,
                                "saturation": 85.0,
                                "sign": "4",
                                "startPoint": null,
                                "team": "化学镀镍一班崔胜伟、化学镀镍一班郭家梁",
                                "updateTime": "2023-03-06 18:42:47",
                                "wcCode": "001",
                                "wcId": 81,
                                "wcName": "化学镀镍作业中心",
                                "whetherPlate": false
                            },
                            {
                                "area": 0.0,
                                "batchNo": null,
                                "bigBatch": false,
                                "checkout": false,
                                "craftAbility": "镀后接收",
                                "createTime": "2023-02-06 12:48:41",
                                "deleted": false,
                                "describe": null,
                                "endPoint": null,
                                "keyValue": 85,
                                "limitType": 0,
                                "processes": "镀后接收",
                                "quantity": null,
                                "roundCycle": null,
                                "saturation": null,
                                "sign": "4",
                                "startPoint": null,
                                "team": "零件管理班",
                                "updateTime": "2023-03-06 18:23:20",
                                "wcCode": "004",
                                "wcId": 85,
                                "wcName": "镀后库作业中心",
                                "whetherPlate": true
                            },
                        ]
                    },
                    {
                        label: '作业槽',
                        prop: 'batchNo',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入作业槽',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '规则类型',
                        prop: 'ruleTypeTitle',
                        type: "select",
                        search: true,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入规则类型',
                                trigger: 'blur',
                            },
                        ],
                        dicData: [
                            {
                                label: '电量差类',
                                value: 1
                            },
                            {
                                label: '累计电量类',
                                value: 2
                            },
                            {
                                label: '累计生产日期',
                                value: 3
                            },
                            {
                                label: '主盐添加量类',
                                value: 4
                            },
                            {
                                label: '累计生产面积',
                                value: 5
                            },
                            {
                                label: '累计主盐添加量',
                                value: 6
                            }
                        ]
                    },
                    {
                        label: '维护内容',
                        prop: 'preserveContent',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入维护内容',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '维护内容',
                        prop: 'preserveContent',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入维护内容',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '添加量',
                        prop: 'actualValue',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入添加量',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '添加量倍数',
                        prop: 'actualValueMom',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入添加量倍数',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '累计触发值',
                        prop: 'cumulativeTriggerValue',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入累计触发值',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '当前值(累计)',
                        prop: 'currentValue',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入当前值(累计)',
                                trigger: 'blur',
                            },
                        ],
                    },
                    {
                        label: '累计初始值',
                        prop: 'cumulativeInitialValue',
                        search: false,
                        sortable: true,
                        overHidden: true,
                        rules: [
                            {
                                required: true,
                                message: '请输入累计初始值',
                                trigger: 'blur',
                            },
                        ],
                    },
                ]
            }
        }
    },
    mounted() {

    },
    methods: {
        // 关闭弹窗
        closeDialog() {
            this.showMaintain = false
        },
        selectionChange(val) {
            this.selectionList = val
        },
        handleAdd() {
            this.tableData = []
            this.showDialog = true
        },
        handleDelete() {
            if (this.selectionList.length == 0) {
                this.$message.error('请先选择数据')
                return
            }
            this.$confirm('确定将选择数据删除?', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
            }).then(() => { })
        },
        handleMaintain(){
            if (this.selectionList.length == 0) {
                this.$message.error('请先选择数据')
                return
            }
            this.maintainData = this.selectionList
            this.showMaintain = true
        },
        handleSet(){
            if(this.isQualified == null){
                this.$message.error('请先选择检查结果')
                return
            }
            this.maintainData.map(item =>{
                item.isQualified = this.isQualified
            })
        },
        maintainValue(){
            this.showMaintain = false
        },
        insertEvent() {
            const record = { bsWorkCenter: { wcId: '' }, _select: false }
            this.tableData.push(record)
        },
        selectChange(list, row) {
            row._select = !row._select
        },
        //删除所选行
        remove() {
            let arr = this.tableData.filter(item => item._select)
            if (arr.length != 0) {
                this.$confirm('确定将选择数据删除?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    if (this.rowId) {
                        let deleteData = this.tableData.filter(item => item._select)
                        this.deleteProcessArr = deleteData.filter(item => item.tidId)
                    }
                    let deleteArr = this.tableData.filter(item => !item._select)
                    this.tableData = deleteArr
                })
            } else {
                this.$message.error('请至少选择一条数据进行操作！')
            }
        },
        handleSave() {
            this.showDialog = false
        },
        searchReset() {
            this.query = {};
            this.onLoad(this.page);
        },
        searchChange(params, done) {
            // this.query = params;
            // this.page.currentPage = 1;
            // this.onLoad(this.page, params);
            done();
        },
        currentChange(currentPage) {
            this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
            this.page.pageSize = pageSize;
        },
        refreshChange() {
            this.onLoad(this.page, this.query);
        },
        onLoad() {
            this.data = [
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "6#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 83,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 83,
                    "lastTaskTime": "2024-04-09 11:47:00",
                    "parameterOne": "2",
                    "parameterTwo": null,
                    "preserveContent": "6",
                    "ruleType": 1,
                    "ruleTypeTitle": "电量差类"
                },
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "5#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 84,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 84,
                    "lastTaskTime": "2022-03-26 15:24:50",
                    "parameterOne": "2",
                    "parameterTwo": "100",
                    "preserveContent": "6",
                    "ruleType": 2,
                    "ruleTypeTitle": "累计电量类"
                },
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "4#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 85,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 85,
                    "lastTaskTime": "2022-03-26 15:24:50",
                    "parameterOne": "2",
                    "parameterTwo": "20",
                    "preserveContent": "6",
                    "ruleType": 3,
                    "ruleTypeTitle": "累计生产日期"
                },
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "3#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 86,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 86,
                    "lastTaskTime": "2022-03-26 15:24:50",
                    "parameterOne": "2",
                    "parameterTwo": null,
                    "preserveContent": "6",
                    "ruleType": 4,
                    "ruleTypeTitle": "主盐添加量类"
                },
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "2#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 87,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 87,
                    "lastTaskTime": "2022-03-26 15:24:50",
                    "parameterOne": "2",
                    "parameterTwo": "256",
                    "preserveContent": "6",
                    "ruleType": 5,
                    "ruleTypeTitle": "累计生产面积"
                },
                {
                    "approvalStatus": -1,
                    "arrangeTime": null,
                    "batchNo": "1#",
                    "bbpType": 2,
                    "bbpTypeTitle": "累计类",
                    "bppId": 88,
                    "bsWorkCenter": {
                        "wcId": 81,
                        "wcName": "化学镀镍作业中心"
                    },
                    "businessBeanCreateDate": "2024-03-05 15:14:01",
                    "businessBeanCreateMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "businessBeanCurStatus": -1,
                    "deleted": false,
                    "flowCode": "FLOW_DS_010",
                    "flowRecDescription": "槽位维护计划-维护计划类审核",
                    "frequency": 2,
                    "keepMan": {
                        "userId": 541,
                        "userName": "崔殿龙"
                    },
                    "keepTime": "2024-03-05 15:14:01",
                    "keyValue": 88,
                    "lastTaskTime": "2022-03-26 15:24:50",
                    "parameterOne": "2",
                    "parameterTwo": "366",
                    "preserveContent": "6",
                    "ruleType": 6,
                    "ruleTypeTitle": "累计主盐添加量"
                }
            ]
            this.page.total = this.data.length
        }
    }
}
</script>

<style></style>