<template>
    <div class="app-container">
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="plus" size="mini" @click="handleAdd" v-if="optType != 'view'&&checkstatus != 'FINISHED'"
                    v-hasPermi="['pms:checkplan:add']">{{ tLang('common','新增') }}</el-button>
            </el-col>
        </el-row>

        <el-table v-loading="loading" :data="checksubjectList">
            <el-table-column :label="tLang('pms','项目名称')" align="center" prop="subjectCode" width="200px">
                <template #default="scope">
                    <el-select v-model="scope.row.subjectCode"
                        :placeholder="tLang('common', '请选择') + tLang('device', '项目名称')"
                        @change="changeSubject(scope.row)" :disabled="optType == 'view'||checkstatus == 'FINISHED'">
                        <el-option v-for="item in subjectList" :key="item.value" :label="item.label"
                            :value="item.value" />
                    </el-select>
                </template>
            </el-table-column>
            <el-table-column :label="tLang('pms','项目编码')" align="center" prop="subjectCode"></el-table-column>
            <el-table-column :label="tLang('pms','项目类型')" align="center" prop="subjectType" >
                <template #default="scope">
                    <dict-tag :options="pms_dvsubject_type" :value="scope.row.subjectType" />
                </template>
            </el-table-column>
            <el-table-column :label="tLang('pms','项目内容')" align="center" width="200px" prop="subjectContent"
                :show-overflow-tooltip="true" />
            <el-table-column :label="tLang('pms','标准')" align="center" width="100px" prop="subjectStandard"
                :show-overflow-tooltip="true" />
            <el-table-column :label="tLang('common','操作')" align="center" class-name="small-padding fixed-width">
                <template #default="{ row, $index }">
                    <el-button size="mini" type="text" icon="delete" v-if="optType != 'view'&&checkstatus != 'FINISHED'"
                        @click="handleDelete($index)" v-hasPermi="['pms:checkplan:remove']">{{ tLang('common','删除') }}</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script setup>
import { getCurrentInstance } from 'vue';
const prop = defineProps({
    subjectList: {
        type: Array,
        default: () => []
    },
    checksubjectList: {
        type: Array,
        default: () => []
    },
    optType: {
        type: String,
        default: "add"
    },
    checkstatus: {
        type: String,
        default: "PREPARE"
    }
});
const { proxy } = getCurrentInstance();
const { sys_yes_no, pms_dvsubject_type } = proxy.useDict("sys_yes_no", "pms_dvsubject_type");
// 遮罩层
let loading = ref(false);
const emit = defineEmits();


//修改项目编码
function changeSubject(row) {
    let subject = prop.subjectList.find(item => item.value == row.subjectCode);
    row.subjectName = subject.subjectName;
    row.subjectType = subject.subjectType;
    row.subjectContent = subject.subjectContent;
    row.subjectStandard = subject.subjectStandard;
}









/** 新增按钮操作 */
function handleAdd() {
    let list = prop.checksubjectList || [];
    list.push({
        subjectCode: "",
        subjectName: "",
        subjectType: "",
        subjectContent: "",
        subjectStandard: "",
    });
    emit("update:checksubjectList", list);
}


/** 删除按钮操作 */
function handleDelete(i) {

    let list = prop.checksubjectList || [];
    let length = list.length;
    list.splice(i, 1);
    emit("update:checksubjectList", list);
}

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

<style lang="scss" scoped></style>
