<template>
 <div class="h100">
   <common-layout
     ref="layoutRef"
     :get-table-list="getTableList"
     :table-header="labelTaskHomeTableHeader"
     :filter-form="labelTaskHomeFilterForm()"
     :table-attrs="{
       'has-operation':true
     }"
     :form-attrs="{
      spanAttrs: {
        span:5
      }
      }"

   >
     <template #TASK_STATES="{data}">
       {{labelTaskHomeStatus.find(i => i.value === data.TASK_STATES)?.label || '未配置'}}
     </template>
     <template #operation="{data}">
       <template v-if="!(+data['TASK_STATES']) ">
         <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
       </template>

       <template v-if="['1','2','3'].includes(data['TASK_STATES'])">
         <el-button type="info" @click="$emit('changeOperation','detail',data)">查看</el-button>
         <el-button type="danger" @click="changeState(data,'4')">停用</el-button>
       </template>
       <template v-if="['4'].includes(data['TASK_STATES'])">
         <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
         <el-button type="info" @click="changeState(data,'1')">启用</el-button>
       </template>
     </template>
   </common-layout>
 </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {labelTaskHomeFilterForm, labelTaskHomeStatus} from "@/data/all-forms";
import {labelTaskHomeTableHeader} from "@/data/all-table-header";
import {ref} from "vue";
import {changeLabelTaskDetailStateHome, getLabelTaskTableData} from "@/service/label-task";
import {handleMes} from "@/unit/element-ui/tip";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "LabelTaskHome",
  components: {CommonLayout},
  setup() {
    useActiveGetTableData(getTableList)
    const layoutRef = ref(null)
    function changeState(data,taskStatus){
      changeLabelTaskDetailStateHome({
        "LABEL_TASK_ID": data.LABEL_TASK_ID,
        "FREQUENT": "2",
        "TASK_STATES": taskStatus
      }).then(res => {
        handleMes(res,() => {
          getTableList()
        })
      })
    }
    function getTableList(){
      getLabelTaskTableData({
        PAGEINDEX:layoutRef.value.pageIndex,
        PAGESIZE:layoutRef.value.pageSize,
        CATALOG_NAME:layoutRef.value.form.CATALOG_NAME,
        UNIT_CODE:layoutRef.value.form.UNIT_CODE,
        TASK_STATES:layoutRef.value.form.TASK_STATES,

      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)

      })

    }
    return {
      labelTaskHomeFilterForm,
      labelTaskHomeTableHeader,
      layoutRef,
      getTableList,
      labelTaskHomeStatus,
      changeState
    }
  }
}
</script>

<style scoped lang="scss">

</style>
