<template>
 <div class="h100">
   <common-layout

     :form-attrs="{
     spanAttrs: {
       span:4
     }
     }"
     :get-table-list="getTableData"
     ref="layoutRef"
     :table-header="taskSetHomeTableHeader"
     :filter-form="taskSetHomeFilterForm()"
     :table-attrs="{
       'has-operation':true
     }"
   >
     <template #STATE="{data}">
       {{getState(data.STATE)}}
     </template>
     <template #STATES="{data}">
       {{getStateS(data.STATES)}}
     </template>
   <template #operation="{data}">
     <el-button type="info" @click="$emit('changeOperation','detail',data)">详情</el-button>
     <template v-if="+data['STATE'] === 2">
       <el-button type="info" @click="changeState(data,'1')">停止</el-button>
     </template>
     <template v-else-if="+data['STATE'] === 5">
       <el-button type="info" disabled>执行中</el-button>
     </template>
     <template v-else-if="+(data['STATE'] + '')">
       <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
       <el-button type="info" @click="changeState(data,'2')">启动</el-button>
     </template>


     <template v-else>
       <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>

     </template>

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

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {ref} from "vue";
import {taskSetHomeFilterForm} from "@/data/all-forms";
import {taskSetHomeTableHeader} from "@/data/all-table-header";
import {changeTaskSetStatus, taskSetHomeTableData} from "@/service/task-manage/task-set";
import {handleMes} from "@/unit/element-ui/tip";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "TaskSetHome",
  components: {CommonLayout},
  setup() {
    useActiveGetTableData(getTableData)
    function getState(state){
      switch (state) {
        case "0":
          return "未配置";
        case "1":
          return "未启用";
        case "2":
          return "已启用";
        case "5":
          return "执行中";
        case "10":
          return "执行异常";
        default:
          return "未配置";
      }
    }

    function changeState(data,state) {
      changeTaskSetStatus(data.CATALOG_CODE,state).then(res => {
        handleMes(res,() => {
          getTableData()
        })
      })
    }

    function getStateS(value){
      switch (value) {
        case 8:
          return "审核通过";
        case 9:
          return "已发布";
      }
    }
    function getTableData(){
      taskSetHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        CATALOG_NAME:layoutRef.value.form.CATALOG_NAME,
        UNIT_CODE:layoutRef.value.form.UNIT_CODE,
        STATE:layoutRef.value.form.STATE,
      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)
      })

    }
    const layoutRef = ref(null)
    return {
      layoutRef,
      getTableData,
      taskSetHomeFilterForm,
      taskSetHomeTableHeader,
      getState,
      getStateS,
      changeState
    }
  }
}
</script>

<style scoped lang="scss">

</style>
