<template>
    <div class="app-container">
        <div class="searchPanel">
            <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" class="searchPanelForm">
                <el-form-item label="反馈人:" prop="postCode">
                    <el-input v-model="queryParams.postCode" placeholder="请输入反馈人" clearable style="width: 140px" />
                </el-form-item>
                <el-form-item label="反馈时间:" prop="postName">
                    <el-date-picker v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
                        start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
                </el-form-item>
            </el-form>
        </div>
        <el-card>  
            <el-row :gutter="10" class="my_row">
                <el-col :span="24">
                    <el-button type="primary" class="primaryBtn" @click="handleQuery">搜索</el-button>
                    <el-button type="primary" class="primaryBtn" @click="resetQuery">重置</el-button>
                </el-col>
            </el-row>

            <el-table v-loading="loading" :data="postList" @selection-change="handleSelectionChange"
                height="calc(100vh - 302px)"> 
                 <el-table-column label="序号" align="center" width="80">
                    <template #default="scope">
                        {{ scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column label="反馈内容" align="center" prop="postId" />
                <el-table-column label="反馈人" align="center" prop="postCode" width="150"/> 
                <el-table-column label="反馈时间" align="center" prop="createTime" width="210">
                    <template #default="scope">
                        <span>{{ parseTime(scope.row.createTime) }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="130" align="center" class-name="small-padding fixed-width">
                    <template #default="scope">
                        <!-- <el-button link type="primary" @click="handleUpdate(scope.row)"
                            v-hasPermi="['problemFeedback:edit']">修改</el-button> -->
                        <el-button link type="primary" @click="handleDelete(scope.row)"
                            v-hasPermi="['problemFeedback:remove']">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
                @pagination="getList" />
        </el-card> 
    </div>
</template>

<script setup name="Post">
import { onMounted, ref } from 'vue';
import { listPost, addPost, delPost, getPost, updatePost } from "@/api/system/post"
import { useBackgroundStore } from '@/store/modules/background'
import otherbg from '@/assets/images/otherbg.png'
const bgStore = useBackgroundStore()

const { proxy } = getCurrentInstance()
const { sys_normal_disable } = proxy.useDict("sys_normal_disable")

const postList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const dateRange = ref([])
const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        postCode: undefined,
        postName: undefined,
        status: undefined
    },
    rules: {
        postName: [{ required: true, message: "岗位名称不能为空", trigger: "blur" }],
        postCode: [{ required: true, message: "岗位编码不能为空", trigger: "blur" }],
        postSort: [{ required: true, message: "岗位顺序不能为空", trigger: "blur" }],
    }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询岗位列表 */
function getList() {
    loading.value = true
    listPost(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
        postList.value = response.rows
        total.value = response.total
        loading.value = false
    })
}
 

/** 表单重置 */
function reset() {
    form.value = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
    }
    proxy.resetForm("postRef")
}

/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1
    getList()
}

/** 重置按钮操作 */
function resetQuery() {
    proxy.resetForm("queryRef")
    handleQuery()
}
     
/** 删除按钮操作 */
function handleDelete(row) {
    const postIds = row.postId || ids.value
    proxy.$modal.confirm('是否确认删除岗位编号为"' + postIds + '"的数据项？').then(function () {
        return delPost(postIds)
    }).then(() => {
        getList()
        proxy.$modal.msgSuccess("删除成功")
    }).catch(() => { })
}
 
// 初始化
onMounted(() => {
    bgStore.setBgImage(otherbg)
    getList()
}); 
</script>
