<template>
  <div class="app-container">
    <page-search
      :searchFormConfig="searchFormConfig"
      @resetBtnClick="handleResetClick"
      @queryBtnClick="handleQueryClick"
    />
    <page-content
      ref="pageContentRef"
      :contentTableConfig="contentTableConfig"
      :isExport="false"
      pageName="/system/notice"
      @newBtnClick="handleNewData"
      @editBtnClick="handleEditData"
    >
    <template #noticeType="scope">
      <span>{{ scope.row.noticeType == '1' ? '通知' : '公告' }}</span>
    </template>
    <template #noticestatus="scope">
      <span>{{ scope.row.status == '0' ? '正常' : '关闭' }}</span>
    </template>
    <template #noticeStarttime="scope">
      <span>{{ scope.row.startTime  }}-{{ scope.row.endTime  }}</span>
    </template>
    <template #handler="scope">
      <el-button
        icon="Setting"
        size="small"
        type="primary"
        link
        @click="handleTop(scope.row)"
      >
        置顶
      </el-button>
  </template>
    </page-content>
    <page-modal
      :defaultInfo="defaultInfo"
      ref="pageModalRef"
      pageName="/system/notice"
      :modalConfig="modalConfig"
    ></page-modal>
  </div>
</template>

<script>
import { defineComponent,getCurrentInstance } from 'vue'

import PageSearch from '@/components/page-search'
import PageContent from '@/components/page-content'
import PageModal from '@/components/page-modal'

import { searchFormConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

import { usePageSearch } from '@/hooks/use-page-search'
import { usePageModal } from '@/hooks/use-page-modal'
import { getPageListData } from '@/api/main/system/system';

export default defineComponent({
  name: 'Notice',
  components: {
    PageSearch,
    PageContent,
    PageModal
  },
  setup() {
    const [pageContentRef, handleResetClick, handleQueryClick] = usePageSearch()
    const { proxy } = getCurrentInstance()
    const handleTop = (row) => {
      proxy
        .$confirm('确认置顶吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          closeOnClickModal: false,
        })
        .then(({ value }) => {
          const params = {
            id:row.noticeId
          }
          getPageListData("/system/notice/settop/"+row.noticeId).then((res)=>{
              if (res.state === 'success') {
                proxy.$modal.msgSuccess('置顶成功')
                pageContentRef.value.getPageData()
              }
          })
           
        })
        .catch(() => {})
    }
    // 1.处理逻辑
    const newCallback = () => {}
    const editCallback = () => {}

    // 2.动态添加部门和角色列表
    // const modalConfigRef = computed(() => {
    //   return modalConfig
    // })

    // 3.调用hook获取公共变量和函数
    const [pageModalRef, defaultInfo, handleNewData, handleEditData] =
      usePageModal(newCallback, editCallback)
    return {
      handleTop,
      searchFormConfig,
      contentTableConfig,
      pageContentRef,
      handleResetClick,
      handleQueryClick,
      modalConfig,
      pageModalRef,
      defaultInfo,
      handleNewData,
      handleEditData
    }
  }
})
</script>
