<template>
 <div class="rule position-re">
  <el-breadcrumb separator="/" class="my-breadcrumb">
    <el-breadcrumb-item>知识库</el-breadcrumb-item>
    <el-breadcrumb-item>标签规则</el-breadcrumb-item>
  </el-breadcrumb>
   <div class="back" @click="$emit('changeOperation','',{})"><span class="fa fa-reply cur-po " >返回</span></div>
   <div class="filter-form">
     <diy-el-form :span-attrs="{
     span:5
   }" :forms="labelRuleDetailFilterFormConfig" v-model:model-form="forms">
       <template #searchBtn>
         <el-button type="primary" :icon="Search" @click="getTableList">查询</el-button>
       </template>
       <template #addBtn>
         <el-button type="primary" :icon="Plus" @click="openDialog('add',{})">新增</el-button>
       </template>
     </diy-el-form>
   </div>
   <div class="data-source-a">
     <span class="data-source">数据资源</span>
     <span class="total">共 <strong>{{totalCount}}</strong> 个规则项</span>

   </div>
   <div class="my-detail-main">
     <my-table
       border

       :table-data="tableData"

       :page-size="8"
       :has-operation="true"
       :headers="labelTaskDetailTableHeader"
     >
       <template #operation="{data}">
         <template v-if="data.LABEL_STATES == '2'">
           <el-button type="info"  size="small" @click="changeStatus(data,'1')">启用</el-button>
           <el-button type="primary" size="small" @click="openDialog('edit',data)">编辑</el-button>
           <el-button type="primary" size="small" @click="delLabelRule(data)">删除</el-button>
         </template>
         <template v-else>
           <el-button type="danger"  size="small"  @click="changeStatus(data,'2')">禁用</el-button>
           <el-button type="primary" size="small" @click="openDialog('edit',data)">查看</el-button>

         </template>
       </template>
     </my-table>
     <ele-pagination  ref="refEl"

                      @sizeOrPageChange="handleSizeChange"
                      class="page hidden"
                      :default-page-size="pageSize"


                      :total-count="totalCount">

       <template #default>
         <div class="m-s">
           显示第 {{pageSize * (pageIndex -1) + 1 }} 到第 {{pageSize * pageIndex}} 条记录，总共 {{totalCount}} 条记录 共显示

         </div>
       </template>
     </ele-pagination>
     <div class="m-s">
       显示第 {{1 }} 到第 {{totalCount}} 条记录，总共 {{totalCount}} 条记录

     </div>
   </div>
   <template v-if="isEditDictionaryDialogShow">
     <label-rule-seting-dialog :dialog-operatio-obj="currentDialogOpObj" @getD="getTableList" :dia-operation-type="dialogOperationType" :current-op-obj="currentOpObj" v-model:dialog-visible="isEditDictionaryDialogShow"/>
   </template>
 </div>


</template>

<script>
import DiyElForm from "@/components/common/DiyElForm.vue";
import {onBeforeMount, ref} from "vue";
import {editDataDictionaryForm, labelRuleDetailFilterForm, syncDetailFilterForm} from "@/data/all-forms";
import {Plus, Search} from "@element-plus/icons-vue";
import MyTable from "@/components/common/MyTable.vue";
import {useDetailOrEdit, usePagination} from "@/unit/use-method/usePagination";
import ElePagination from "@/components/common/ElePagination.vue";
import {
  editClearRuleTableHeader,
  editDataDictionaryTableHeader, editLabelRuleTableHeader,
  editSyncRuleTableHeader, labelTaskDetailTableHeader
} from "@/data/all-table-header";
import DataDictionarySetingDialog
  from "@/view/other/c-views/data-handle/zsk/data-dictionary/DataDictionarySetingDialog.vue";
import SyncRuleSetingDialog from "@/view/other/c-views/data-handle/zsk/sync-rule/SyncRuleSetingDialog.vue";
import ClearRuleSetingDialog from "@/view/other/c-views/data-handle/zsk/clear-rule/ClearRuleSetingDialog.vue";
import LabelRuleSetingDialog from "@/view/other/c-views/data-handle/zsk/label-rule/LabelRuleSetingDialog.vue";
import {getQualityDetailRuleAllFieldSelect} from "@/service/zsk/quality-check-rule";
import {delLabelRuleData, editLabelRuleD, getLabelRuleDetailTableData} from "@/service/zsk/label-rule";
import {handleMes, showConfirm} from "@/unit/element-ui/tip";
import {delSyncRule} from "@/service/zsk/sync-rule";
import {requestInstance} from "@/service";

export default {
  name: "LabelRuleEdit",
  computed: {
    Plus() {
      return Plus
    },
    Search() {
      return Search
    }
  },
  components: {
    LabelRuleSetingDialog,
    ClearRuleSetingDialog,
    SyncRuleSetingDialog, DataDictionarySetingDialog, ElePagination, MyTable, DiyElForm},
  props:{
    currentOpObj:{

    },

  },
  setup(props) {
    function changeStatus(data,state) {
      editLabelRuleD({
        LABEL_CONFIG_ID:data.LABEL_CONFIG_ID,
        LABEL_RULE_ID:data.LABEL_RULE_ID,
        CATALOG_JOIN_FIELD:data.CATALOG_JOIN_FIELD,
        ASSOCIATED_FIELD_NAME:data.ASSOCIATED_FIELD_NAME,
        JUDGMENT_BASIS:data.JUDGMENT_BASIS,
        OPERATOR:data.OPERATOR,
        LABEL_STATES:state
      }).then(res => {
        handleMes(res,() => {
          getTableList()
        })
      })
    }
    const isEditDictionaryDialogShow =  ref(false)
    const dialogOperation =  ref('')
    function delLabelRule(data) {
      showConfirm(() => {
        delLabelRuleData(data.LABEL_CONFIG_ID).then(res => {
          handleMes(res,() => {
            getTableList()
          })
        })
      },'确定要删除吗','系统提示',{
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
    }
    function getTableList() {
      getLabelRuleDetailTableData({
        pageIndex:pageIndex.value,
        pageSize:pageSize.value,
        CATALOG_ID:props.currentOpObj.CATALOG_ID,
        ASSOCIATED_FIELD_NAME:forms.value.ASSOCIATED_FIELD_NAME,
        LABEL_STATES:forms.value.LABEL_STATES,
      }).then(res => {
        tableData.value = res.msg[0].Rows
        totalCount.value = res.msg[0].TotalRowCount
      })
    }
    const {changeOperation,currentOpObj:currentDialogOpObj,operationType:dialogOperationType} = useDetailOrEdit()
    const labelRuleDetailFilterFormConfig = ref({...labelRuleDetailFilterForm})
    const {pageIndex,pageSize,tableData,totalCount,handleSizeChange,refEl}  = usePagination(getTableList.bind(null))
    const forms = ref({

    })
    onBeforeMount(() => {
      getQualityDetailRuleAllFieldSelect(props.currentOpObj.CATALOG_ID).then(res => {
       //    INFOITEMENGLISHNAME
        let findItem = labelRuleDetailFilterFormConfig.value.formItemsArr.find(i => i.modelValue === 'ASSOCIATED_FIELD_NAME')
        findItem.options = [
          {
            value:'',
            label:'全部字段'
          }
        ].concat(res.msg[0].Rows.map(i => ({
          ...i,
          label:i.INFOITEMENGLISHNAME,
          value:i.INFOITEMENGLISHNAME,
        })))
      })

    })
    function openDialog(dialogOperationw,item){

      isEditDictionaryDialogShow.value = true
      changeOperation(dialogOperationw,item)
    }
    return {
      forms,
      labelRuleDetailFilterFormConfig,
      pageIndex,pageSize,tableData,totalCount,handleSizeChange,refEl,getTableList,
      labelTaskDetailTableHeader,
      isEditDictionaryDialogShow,
      openDialog,
      dialogOperation,
      changeOperation,
      dialogOperationType,
      currentDialogOpObj,
      delLabelRule,
      changeStatus

    }
  }
}
</script>

<style scoped lang="scss">
.filter-form{
  margin-top: 20px;
  border-bottom: 1px solid #e7eaec !important;
}
.my-breadcrumb{
  padding: 20px 20px 20px 20px;
  border-bottom: 1px solid #e7eaec !important;
}
.data-source-a{
  margin: 20px 0;
}
.data-source{

  margin-right: 10px;
  color: rgb(103, 106, 108);
  font-size: 16px;
  font-weight: 600;
}
.total{
  strong{
    color: rgb(55, 99, 156);
    font-weight: 700;
  }
  color: rgb(103, 106, 108);
  font-size: 13px;
}
.data-source-a,.filter-form{
  margin-left: 20px;
  margin-right: 20px;
}

</style>
