<template>
    <headerTop @search="searchFn" @reset="resetFn" @export="exportFn" @add="addFn"></headerTop>
    <addCom ref="addComRef"></addCom>
    <el-card shadow="always" class="content_body_row">
        <el-table :data="tableListInfo.list" style="width: 100%" border show-overflow-tooltip
        :max-height="'calc(100vh - 72px - 48px - 65px - 12px - 60px - 48px)'"
            :height="'calc(100vh - 72px - 48px - 65px - 12px - 60px  - 48px)'">>
            <el-table-column type="index" width="72" label="序号" />
            <el-table-column prop="v_code" label="模板编号" min-width="100" />
            <el-table-column prop="v_applyModule" label="应用模块" min-width="120" />
            <el-table-column prop="v_attachment" label="附件" min-width="120" />
            <el-table-column prop="v_isEnable" label="是否启用" min-width="220">
                <template #default="scope">
                    <el-switch v-model.trim="scope.row.v_isEnable" :before-change="beforeChange" />
                </template>
            </el-table-column>
            <el-table-column label="操作" width="210" align="center">

                <template #default="scope">
                    <el-button type="primary" size="small" @click.prevent="showRowFn(scope.row)">
                        查看
                    </el-button>
                    <el-button type="primary" size="small" @click.prevent="editRowFn(scope.row)">
                        编辑
                    </el-button>
                    <el-button type="danger" size="small" @click.prevent="deleteRowFn(scope.row)">
                        删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="paination_out">
            <Pagination :currentPage="paginationInfo.currentPage" :pageSize="paginationInfo.pageSize" @sendPage="getPageFn"></Pagination>
        </div>
    </el-card>
</template>

<script lang="ts" setup>
import headerTop from "./com/headerTop.vue"
import addCom from "./com/addCom.vue"
import { ElConfirmBeforeOpert } from "utils/elementCom"
const addComRef = ref()
const paginationInfo = reactive({
    currentPage: 1,
    pageSize: 15
})
const tableData = [
    {
        v_id: '1',
        v_code: '2016-05-03',
        v_applyModule: 'Tom',
        v_attachment: 'California',
        v_isEnable:false,
    },
    {
        v_id: '2',
        v_code: '2016-05-03',
        v_applyModule: 'Tom',
        v_attachment: 'California',
        v_isEnable:false,
    },
    {
        v_id: '3',
        v_code: '2016-05-03',
        v_applyModule: 'Tom',
        v_attachment: 'California',
        v_isEnable:false,
    },
    {
        v_id: '4',
        v_code: '2016-05-03',
        v_applyModule: 'Tom',
        v_attachment: 'California',
        v_isEnable:false,
    },
    {
        v_id: '5',
        v_code: '2016-05-03',
        v_applyModule: 'Tom',
        v_attachment: 'California',
        v_isEnable:false,
    },

]

let tableListInfo = reactive({
    list: tableData
})

const showRowFn = (row: any) => {
    addComRef.value.showFn({
        title: "111"
    })
}


const editRowFn = (row: any) => {
    addComRef.value.edit({
        a: "111"
    })

}

const deleteItem = (row: any) => {
    const itemID = row.v_id
    console.log("ITEMid", row)
}

const deleteRowFn = (row: any) => {
    ElConfirmBeforeOpert(
        '操作确认',
        '是否确定删除数据？',
        deleteItem,
        '确定',
        '取消',
        row
    )

}

const searchFn = () => {

}

const resetFn = () => {

}

const exportFn = () => {

}

const addFn = () => {
    addComRef.value.open({
        a: "111"
    })
}

const beforeChange = (ev:any) => {
    return new Promise((resolve, reject)=>{
        resolve(true)
      })
 
}
const getPageFn =(val:any)=>{
    paginationInfo.currentPage  =  val.currentPage
    paginationInfo.pageSize  =  val.pageSize
    initTableList()
}

const initTableList =()=>{

}



</script>

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