<template>
    <div class="app-container">
        <div class="searchPanel">
            <el-form :inline="true" v-show="showSearch" class="searchPanelForm">
                <el-form-item label="供应商:">
                    <el-select v-model="queryParams.supplierId" placeholder="请选择" style="min-width: 30px;" clearable>
                        <el-option v-for="item in supplierList" :key="item.supplierId" :label="item.supplierName"
                            :value="item.supplierId" />
                    </el-select>
                </el-form-item>
                <el-form-item label="类型:">
                    <el-select v-model="queryParams.type" placeholder="请选择" style="min-width: 30px;" clearable>
                        <el-option v-for="item in types" :key="item.value" :label="item.label" :value="item.value" />
                    </el-select>
                </el-form-item>
            </el-form>
        </div>
        <el-card class="mt20">
            <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-button type="primary" class="primaryBtn" @click="handleImport">导入</el-button>
                </el-col>
            </el-row>

            <el-table v-if="queryParams.type == 0" v-loading="loading" :data="feedbackList"
                height="calc(100vh - 308px)">
                <el-table-column label="序号" align="center" width="80">
                    <template #default="scope">
                        {{ scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column label="供应商" align="left" prop="content" width="230" />
                <el-table-column label="城市" align="center" prop="feedbackUser" width="150" />
                <el-table-column label="场站" align="center" prop="feedbackUser" width="150" />
                <el-table-column label="媒体位置" align="center" prop="feedbackUser" min-width="260" />
                <el-table-column label="频次" align="center" prop="feedbackUser" width="120" />
                <el-table-column label="刊例价" align="center" prop="feedbackUser" width="120" />
                <el-table-column label="单位" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="折扣" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="首次制作安装费(元/次)" align="center" prop="feedbackUser" min-width="230" />
                <el-table-column label="换画费(RMB)" align="center" prop="feedbackUser" width="150" />
                <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>
            <el-table v-if="queryParams.type == 1" v-loading="loading" :data="feedbackList"
                height="calc(100vh - 308px)">
                <el-table-column label="序号" align="center" width="80">
                    <template #default="scope">
                        {{ scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column label="供应商" align="left" prop="content" width="230" />
                <el-table-column label="城市" align="center" prop="feedbackUser" width="150" />
                <el-table-column label="资源描述" align="center" prop="feedbackUser" min-width="260" />
                <el-table-column label="刊例价" align="center" prop="feedbackUser" width="120" />
                <el-table-column label="单位" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="折扣" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="首次制作安装费(元/次)" align="center" prop="feedbackUser" min-width="230" />
                <el-table-column label="换画费(RMB)" align="center" prop="feedbackUser" width="150" />
                <el-table-column label="备注" align="center" prop="feedbackUser" min-width="230" />
                <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>
            <el-table v-if="queryParams.type == 2" v-loading="loading" :data="feedbackList"
                height="calc(100vh - 308px)">
                <el-table-column label="序号" align="center" width="80">
                    <template #default="scope">
                        {{ scope.$index + 1 }}
                    </template>
                </el-table-column>
                <el-table-column label="供应商" align="left" prop="content" width="230" />
                <el-table-column label="城市" align="center" prop="feedbackUser" width="150" />
                <el-table-column label="媒体名称" align="center" prop="feedbackUser" min-width="150" />
                <el-table-column label="频次" align="center" prop="feedbackUser" width="120" />
                <el-table-column label="刊例价" align="center" prop="feedbackUser" width="120" />
                <el-table-column label="单位" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="折扣" align="center" prop="feedbackUser" width="100" />
                <el-table-column label="首次制作安装费(元/次)" align="center" prop="feedbackUser" min-width="230" />
                <el-table-column label="换画费(RMB)" align="center" prop="feedbackUser" width="150" />
                <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.pageIndex" v-model:limit="queryParams.pageSize"
                @pagination="getBusProblemFeedbackPage" />
        </el-card>

    </div>
</template>

<script setup name="Post">
import { onMounted, ref } from 'vue';
import { listBusSupplier } from "@/api/supplier"
import { useBackgroundStore } from '@/store/modules/background'
import otherbg from '@/assets/images/otherbg.png'
const bgStore = useBackgroundStore()

const { proxy } = getCurrentInstance()

const supplierList = ref([])
const types = ref([
    { value: 0, label: '高铁' },
    { value: 1, label: '候车亭' },
    { value: 2, label: '门禁道闸' },
])

const feedbackList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const total = ref(0)
const dateRange = ref([])
const data = reactive({
    form: {},
    queryParams: {
        pageIndex: 1,
        pageSize: 10,
        supplierId: undefined,
        type: 0
    },
    rules: {
        content: [{ required: true, message: "反馈内容不能为空", trigger: "blur" }]
    }
})

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

const getSupplierList = () => {
    listBusSupplier({}).then(res => {
        supplierList.value = res.data
    })
}

// 处理日期变化
const handleDateChange = (val) => {
    dateRange.value = val;
    queryParams.value.startDate = val[0]
    queryParams.value.endDate = val[1]
};
/** 查询反馈问题列表 */
const getBusProblemFeedbackPage = () => {
    loading.value = false
    // busProblemFeedbackPage(queryParams.value).then(response => {
    //     feedbackList.value = response.data.list
    //     total.value = response.data.total
    //     loading.value = false
    // })
}

/** 搜索按钮操作 */
const handleQuery = () => {
    queryParams.value.pageIndex = 1
    getBusProblemFeedbackPage()
}

/** 重置按钮操作 */
const resetQuery = () => {
    queryParams.value = {
        pageIndex: 1,
        pageSize: 10,
        feedbackUser: undefined,
        startDate: undefined,
        endDate: undefined
    }
    handleQuery()
}
// 导入
const handleImport = () => {

}
// 修改问题
const handleUpdate = (row) => {
    form.value = {
        feedbackUser: undefined,
        content: undefined
    }
    getBusProblemFeedback(row.id).then(res => {
        form.value = res.data
        open.value = true
    })
}


const cancel = () => {
    open.value = false
    form.value = {}
}
const submitForm = () => {
    proxy.$refs["feedBackRef"].validate(valid => {
        if (valid) {
            updateBusProblemFeedback(form.value).then(response => {
                proxy.$modal.msgSuccess("修改成功")
                getBusProblemFeedbackPage()
                open.value = false
                form.value = {}
                proxy.resetForm("feedBackRef")
            })
        }
    })
}

/** 删除按钮操作 */
const handleDelete = (row) => {
    proxy.$modal.confirm('是否确认删除该问题吗？').then(function () {
        return deleteBusProblemFeedback(row.id)
    }).then(() => {
        getBusProblemFeedbackPage()
        proxy.$modal.msgSuccess("删除成功")
    }).catch(() => { })
}

// 初始化
onMounted(() => {
    bgStore.setBgImage(otherbg)
    getBusProblemFeedbackPage()
    getSupplierList()
}); 
</script>
