<template>
    <!-- 公司业绩管理 -->
    <div class="app-container">
        <el-form :model="queryParam" ref="login" label-width="0px" class="ms-content">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-form-item>
                        <el-input v-model="queryParam.projectName" placeholder="请输入工程名称" clearable> </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item>
                        <el-date-picker
                            v-model="timeValue"
                            type="daterange"
                            range-separator="~"
                            value-format="YYYY-MM-DD"
                            end-placeholder="结束时间"
                            start-placeholder="开始时间"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item>
                        <el-button type="primary">查询</el-button>
                        <el-button>重置</el-button>
                        <el-button type="primary" @click="onHandleAddOrEdit(null, 1)">新增业绩</el-button>
                        <el-button>导出数据</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>

        <el-table :data="tableList" stripe style="width: 100%">
            <el-table-column label="序号" width="55" type="index" />
            <el-table-column
                :key="index"
                align="center"
                :prop="item.prop"
                :label="item.label"
                show-overflow-tooltip
                v-for="(item, index) in tableColumn"
            />

            <el-table-column label="操作" width="200" align="center">
                <template #default="{ row }">
                    <el-button
                        style="color: #67c23a"
                        icon="el-icon-view"
                        type="text"
                        size="mini"
                        @click="onHandleAddOrEdit(row, 2)"
                    >
                        详情
                    </el-button>
                    <el-button
                        style="color: #409eff"
                        icon="el-icon-edit"
                        type="text"
                        size="mini"
                        @click="onHandleAddOrEdit(row, 3)"
                    >
                        编辑
                    </el-button>
                    <el-button
                        style="color: #f56c6c"
                        icon="el-icon-delete"
                        type="text"
                        size="mini"
                        @click="onHandleDelete(row)"
                    >
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <DialogModel :dialogConfig="dialogConfig" @closeDialogOuter="closeDialogOuter">
            <template slot="outerContent">
                <AddAndEditForm :formType="formType" />
            </template>
        </DialogModel>
    </div>
</template>

<script>
import DialogModel from '@/components/DialogModel/index'
import AddAndEditForm from './components/addAndEditForm.vue'
export default {
    components: {
        DialogModel,
        AddAndEditForm,
    },
    data() {
        return {
            formType: 1, // 1新增 2详情 3编辑
            dialogConfig: {
                outerTitle: '新增',
                innerTitle: false,
                outerWidth: '80%',
                outerVisible: false,
                innerVisible: false,
            },
            queryParam: {
                projectName: '',
                startTime: '',
                endTime: '',
            },
            timeValue: [],
            tableList: [
                {
                    projectName: '测试工程1',
                },
                {
                    projectName: '测试工程2',
                },
                {
                    projectName: '测试工程3',
                },
            ],
            tableColumn: [
                { label: '项目名称(按合同)', prop: 'projectName' },
                { label: '建设单位', prop: '' },
                { label: '分包合同额(万元)', prop: '' },
                { label: '开竣工日期', prop: '' },
                { label: '合同身份', prop: '' },
                { label: '派遣人员', prop: '' },
            ],
        }
    },
    methods: {
        // 关闭
        closeDialogOuter() {
            this.dialogConfig.outerVisible = false
        },
        // 删除
        onHandleDelete(row) {
            console.log(row)
            this.$modal
                .confirm('确定删除该业绩吗？')
                .then(() => {
                    console.log('确定')
                })
                .catch(() => {
                    console.log('取消')
                })
        },
        // 新增或编辑
        onHandleAddOrEdit(row, type) {
            console.log(row, type)
            if (type === 1) {
                this.dialogConfig.outerTitle = '新增业绩'
                this.formType = 1
            } else if (type === 3) {
                this.dialogConfig.outerTitle = '编辑业绩'
                this.formType = 3
            } else if (type === 2) {
                this.dialogConfig.outerTitle = '业绩详情'
                this.formType = 2
            }

            this.dialogConfig.outerVisible = true
        },
    },
}
</script>
<style scoped lang="scss"></style>
