<script setup name="safeOperationControl">
import ElTree from '@/components/elTree/index.vue'
import { h, reactive, ref } from 'vue'
import store from '@/store'
import { list } from '@/http/apis/projectStoreManage/projectStore'
import moment from 'moment'
const { statusOptions } = store.dictStore.globalDicts || {},
  searchForm = reactive({
    projectName: undefined
  }),
  tableListRef = ref(),
  total = ref(0),
  column = reactive([
    {
      label: '序号',
      type: 'index',
      width: '80'
    },
    {
      label: '项目名称',
      key: 'projectName',
      prop: 'projectName'
    },
    {
      label: '申报单位',
      key: 'buildOrg',
      prop: 'buildOrg'
    },
    {
      label: '项目类型',
      key: 'projectTypeName',
      prop: 'projectTypeName',
      width: '100'
    },
    {
      label: '预算年度',
      key: 'projectYear',
      prop: 'projectYear',
      width: '80'
    },
    {
      label: '项目状态',
      key: 'status',
      prop: 'status',
      width: '220',
      render: row => [
        h('span', {
          class: ['dot mr-4', `bg-${statusOptions[row.status]?.color}`]
        }),
        h(
          'span',
          {
            class: `text-${statusOptions[row.status]?.color}`
          },
          row.status && statusOptions[row.stage]?.name + '-' + statusOptions[row.status]?.name
        )
      ]
    },
    {
      label: '操作',
      slot: 'action',
      width: '100',
      fixed: 'right'
    }
  ]),
  data = ref([]),
  getTableData = async (pageParams = tableListRef.value.pageParams) => {
    const res = await list({
      ...pageParams,
      ...searchForm
    })
    data.value = res.data.records
    total.value = res.data.total
  },
  search = () => {
    getTableData()
  },
  reset = () => {
    searchForm.projectName = undefined
    tableListRef.value.pageParams.pageNumber = 1
    tableListRef.value.pageParams.pageSize = 10
    getTableData()
  },
  getTree = (data) => {
    searchForm.regionCode = data.regionLevel === 3 ? data.regionCode : undefined
    tableListRef.value.pageParams.pageNumber = 1
    getTableData()
  },
  // 详情
  dialogData = reactive({
    visible: false,
    data: [{
      aqxm: '等保',
      ms: '未完成'
    },
    {
      aqxm: '密评',
      ms: '未完成'
    }
    ],
    column: [{
      label: '序号',
      type: 'index',
      width: '60'
    },
    {
      label: '安全项目',
      key: 'aqxm',
      prop: 'aqxm'
    },
    {
      label: '描述',
      key: 'ms',
      prop: 'ms'
    }]
  }),
  showDialog = (data) => {
    dialogData.visible = true
    dialogData.date = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  },
  changeDate = () => {
    dialogData.date = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  }
</script>

<template>
  <el-row>
    <el-col style="padding-right: 16px" :span="4">
      <elTree @get-tree="getTree" />
    </el-col>
    <el-col :span="20">
      <div>
        <el-card class="search mb-16">
          <el-form label-suffix=":" :model="searchForm" size="small">
            <el-row :gutter="16">
              <el-col :span="8">
                <el-form-item label="项目名称">
                  <el-input
                    v-model="searchForm.projectName"
                    placeholder="请输入"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="16">
                <el-form-item class="btn">
                  <el-button type="primary" @click="search">查询</el-button>
                  <el-button @click="reset">重置</el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-card>
        <el-card>
          <template #header>
            <div class="flex justify-between items-center">
              <span>项目列表</span>
            </div>
          </template>
          <table-list
            ref="tableListRef"
            :column="column"
            :data="data"
            :total="total"
            @get-table-data="getTableData"
          >
            <template #action="{scope}">
              <a @click="showDialog(scope.row)">安全分析</a>
            </template>
          </table-list>
        </el-card>
      </div>
    </el-col>
  </el-row>
  <el-dialog
    :model-value="dialogData.visible"
    title="安全分析"
    width="60%"
    @close="dialogData.visible=false"
  >
    <p class="flex justify-between items-center mb-16">
      <span>检测时间：{{ dialogData.date }}</span>
      <a class="flex items-center" @click="changeDate">
        <el-icon>
          <Refresh />
        </el-icon>
        <span>查询检测</span>
      </a>
    </p>
    <table-list :data="dialogData.data" :column="dialogData.column" :pagination="false" />
  </el-dialog>
</template>
