<template>
 <div class="safe-task-home h100">
   <common-layout
     ref="layoutRef"
     :filter-form="safeTaskHomeFilterForm()"
     :table-attrs="{
       'has-operation':true
     }"
     :form-attrs="{
      spanAttrs: {
        span:5
      }
      }"

     :get-table-list="getTableList"
     :table-header="safeTaskHomeTableHeader"

   >
     <template #SQFE_STATES="{data}">
       {{getStaCn(data.SQFE_STATES)}}
     </template>
     <template #operation="{data}">
       <template v-if="!(+data['SQFE_STATES'])">
         <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
       </template>
       <template v-else-if="data['SQFE_STATES'] === '1'">
         <el-button type="danger" @click="changeState(data)">停用</el-button>
         <el-button type="info" @click="$emit('changeOperation','detail',data)">查看</el-button>
       </template>
       <template v-else-if="data['SQFE_STATES'] === '2'">
         <el-button type="info" @click="changeState(data)">启用</el-button>
         <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
       </template>
       <template v-else-if="data['SQFE_STATES'] === '3'">
         <el-button type="info" disabled>执行中</el-button>
         <el-button type="info" @click="$emit('changeOperation','detail',data)">查看</el-button>
       </template>
       <template v-else-if="data['SQFE_STATES'] === '10'">
         <el-button type="info" disabled>执行异常</el-button>

       </template>
     </template>
   </common-layout>
 </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {ref} from "vue";
import {safeTaskHomeFilterForm} from "@/data/all-forms";
import {safeTaskHomeTableHeader} from "@/data/all-table-header";
import {changeSafeTaskTaskStatus, getSfeTaskHomeTableData} from "@/service/zsk/safe-task";
import {handleMes} from "@/unit/element-ui/tip";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "SafeTaskHome",
  components: {CommonLayout},
  setup() {
    useActiveGetTableData(getTableList)
    const layoutRef = ref(null)
    function getStaCn(state){
      switch (state){
        case "0": return "未配置"; case "1": return "待执行"; case "2": return "停止"; case "5": return "执行中"; case "10": return "执行异常";
      }
    }
    function changeState(data){
      changeSafeTaskTaskStatus(data.CATALOG_CODE,data['SQFE_STATES'] ==='2'?'1':'2').then(res=>{
        handleMes(res,() => {
          getTableList()

        })
      })
    }
    function getTableList() {
      getSfeTaskHomeTableData({
        PAGEINDEX:layoutRef.value.pageIndex,
        PAGESIZE:layoutRef.value.pageSize,
        UNIT_CODE:layoutRef.value.form.UNIT_CODE,
        CATALOG_NAME:layoutRef.value.form.CATALOG_NAME,
      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)
      })

    }
    return {
      getTableList,
      layoutRef,
      safeTaskHomeFilterForm,
      safeTaskHomeTableHeader,
      getStaCn,
      changeState
    }
  }
}
</script>

<style scoped lang="scss">

</style>
