<template>
    <TableHeader area datePicker ref="TableHeaderRef">
        <template #select>
            <el-form-item label=" 计划状态">
                <el-select v-model="tableStore.table.params.searchState" placeholder="请选择 计划状态">
                    <el-option
                        v-for="item in planstatus"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                    ></el-option>
                </el-select>
            </el-form-item>
        </template>
        <template #operation>
            <el-button icon="el-icon-Plus" type="primary" @click="add">新增计划</el-button>
            <el-button icon="el-icon-Stamp" type="primary">提交审核</el-button>
            <el-button icon="el-icon-Download" type="primary">导出</el-button>
        </template>
    </TableHeader>
    <Table ref="tableRef" />
    <!-- 新增弹窗 -->
    <el-dialog :title="title" v-model="planAddition" width="950px" :before-close="cancelFn">
        <el-row :gutter="20">
            <el-col :span="10">
                <el-divider content-position="left">基本信息</el-divider>
                <el-form :inline="true" :model="formdata" :disabled="viewDetails" label-width="120px">
                    <el-form-item label="普测负责单位:">
                        <el-input v-model="formdata.orgName" class="formW" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="计划开始时间:">
                        <el-date-picker
                            v-model.trim="formdata.planStartTime"
                            type="date"
                            style="width: 240px"
                            placeholder="选择计划开始时间"
                            value-format="yyyy-MM-dd"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="计划结束时间:">
                        <el-date-picker
                            v-model.trim="formdata.planEndTime"
                            type="date"
                            style="width: 240px"
                            placeholder="选择计划结束时间"
                            value-format="yyyy-MM-dd"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="普测计划编号:">
                        <el-input
                            :disabled="title == '普测计划修改'"
                            v-model="formdata.planNo"
                            class="formW"
                            placeholder="请输入普测计划编号"
                        ></el-input>
                    </el-form-item>
                    <el-form-item label="计划名称:">
                        <el-input v-model="formdata.planName" placeholder="请输入计划名称" class="formW"></el-input>
                    </el-form-item>
                    <el-form-item label="测试负责人:">
                        <el-input v-model="formdata.leader" placeholder="请输入测试负责人" class="formW"></el-input>
                    </el-form-item>
                </el-form>
            </el-col>
            <el-col :span="14">
                <el-divider content-position="left" style="font-size: 18px; font-weight: bolder">添加电站</el-divider>
                <!-- <div class="mb10" style="display: flex" v-if="!viewDetails">
                        <el-input
                            v-model="input"
                            placeholder="请输入电站数"
                            class="formW"
                            @input="handleEdit"
                            class="mr10"
                        ></el-input>
                        <el-button
                            type="primary"
                            :disabled="!input.length > 0"
                            icon="el-icon-circle-check"
                            size="small"
                            @click="Tick"
                        >
                            按配置勾选
                        </el-button>
                    </div>
                    <el-tree
                        :data="treeData"
                        show-checkbox
                        node-key="id"
                        style="overflow-y: auto; height: 490px"
                        default-expand-all
                        :props="defaultProps"
                        :check-strictly="true"
                        ref="tree"
                    ></el-tree> -->
            </el-col>
        </el-row>
        <!-- <el-divider
            v-if="title == '计划详情' && formdata.status == 2 && formdata.status == 3"
            content-position="left"
            style="font-size: 18px; font-weight: bolder"
        >
            审核意见
        </el-divider>
        <el-input
            v-if="title == '计划详情' && formdata.status == 2 && formdata.status == 3"
            disabled
            type="textarea"
            :rows="2"
            v-model="textarea"
        ></el-input> -->
        <div slot="footer" style="display: flex; justify-content: center" v-if="!viewDetails">
            <el-button type="primary" size="small" class="ml20" @click="submitFn">提交</el-button>
            <el-button type="primary" size="small" class="ml20" @click="cancelFn">取消</el-button>
        </div>
    </el-dialog>
</template>
<script setup lang="ts">
import { ref, onMounted, provide, nextTick } from 'vue'
import TableStore from '@/utils/tableStore'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { mainHeight } from '@/utils/layout'
import { useDictData } from '@/stores/dictData'
import { addUse, updateUse, removeUse } from '@/api/advance-boot/bearingCapacity'

const dictData = useDictData()
const planstatus = [
    {
        id: 0,
        value: '选项1',
        label: '新建'
    },
    {
        id: 1,
        value: '选项1',
        label: '待审核'
    },
    {
        id: 2,
        value: '选项1',
        label: '未通过'
    },
    {
        id: 3,
        value: '选项1',
        label: '已发布'
    }
]
const formdata = ref({
    orgName: '',
    orgNo: '',
    planStartTime: '',
    planEndTime: '',
    planNo: '',
    planName: '',
    leader: '',
    rgeneralSurveyPlanDetailAddParm: [],
    subCount: '',
    busCount: ''
})

const planAddition = ref(false)
const viewDetails = ref(false)
const TableHeaderRef = ref()
const title = ref('')

const ruleFormRef = ref()
const tableStore = new TableStore({
    url: '/system-boot/area/areaSelect',
    publicHeight: 65,
    method: 'POST',
    column: [
        { width: '60', type: 'checkbox' },
        { field: 'orgName', title: '责任单位' },
        {
            field: 'planNo',
            title: '普测计划编号'
        },
        { field: 'planName', title: '普测计划名称' },
        { field: 'planStartTime', title: '开始时间' },
        { field: 'planEndTime', title: '结束时间' },
        { field: 'subCount', title: '普测变电站数量' },
        { field: 'status', title: '计划状态' },

        {
            title: '计划详情',
            width: '180',
            render: 'buttons',
            buttons: [
                {
                    name: 'edit',
                    title: '查看',
                    type: 'primary',

                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: row => {}
                },
                {
                    name: 'edit',
                    title: '编辑',
                    type: '',
                    disabled: row => {
                        return !(row.status == 0 || row.status == 2)
                    },
                    icon: 'el-icon-Plus',
                    render: 'basicButton',
                    click: async row => {}
                }
            ]
        }
    ],

    loadCallback: () => {
        tableStore.table.data = [
            {
                status: 2
            }
        ]
    }
})

tableStore.table.params.searchState = ''
tableStore.table.params.searchValue = ''
tableStore.table.params.type = ''

provide('tableStore', tableStore)
// 新增计划
const add = () => {
    title.value = '普测计划新增'
    planAddition.value = true
}
// 提交
const submitFn = () => {}
// 取消
const cancelFn = () => {
    planAddition.value = false
    viewDetails.value = false
}

onMounted(() => {
    tableStore.index()
})
</script>

<style scoped lang="scss">
.formW {
    width: 240px;
}
</style>
