<template>
  <div class="process-mb h100">
    <common-layout
      @getCheckedTable="getC"
      @changeOperation="changeOperation"
      :table-control-btns="btns"
      :form-attrs="{
      spanAttrs: {
        span:5
      }
      }"
      :is-show-table-btn="true"
       ref="layoutRef"
       :table-attrs="{
      'has-operation':true,
       'multi-select':true
       }"
      :filter-form="processHomeFilterForm"
      :table-header="processMbHomeTableHeader"
      :get-table-list="getTableList"

    >

      <template #operation="{data}">
        <el-button type="info" @click="$emit('changeOperation','set',data)">配置</el-button>
      </template>
    </common-layout>
  </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {processHomeFilterForm} from "@/data/all-forms";
import {processMbHomeTableHeader} from "@/data/all-table-header";
import {ref} from "vue";
import {deleteProcessMb, geeProcessMbHomeTableData} from "@/service/zsk/process-mb";
import {elAlert, handleMes, showConfirm} from "@/unit/element-ui/tip";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";


export default {
  name: "ProcssMbHome",
  components: {CommonLayout},
  setup(props,{emit}) {
    useActiveGetTableData(getTableList)
    const layoutRef = ref(null)
    const checkedTable = ref([])
    function getC(checked) {
      checkedTable.value = checked

    }
    const btns =   [
      {
        id:'9af449d8-cdb4-4804-b15e-0f60d866c15f',
        type:'新增',
        className:'glyphicon glyphicon-plus'
      },
      {
        id:'c9af72ac-bab5-48a4-b119-a9b82ac053a7',
        type:'刷新',
        className:'glyphicon glyphicon-repeat'
      },
      {
        id:'ff55c172-2676-4379-afe0-b6b181b08767',
        type:'删除',
        className:'glyphicon  glyphicon-trash'
      }
    ]
    function delData() {
      if (checkedTable.value.length !== 1){
        elAlert('只能选择一条数据删除')
      }else {
        showConfirm(() => {
          deleteProcessMb(checkedTable.value[0].ID).then(res => {
            handleMes(res,() => {
              getTableList()
            })
          })
        },'确定要删除吗','系统提示',{
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })



      }
    }
    function changeOperation(type,item) {
      if (type === 'add'){

        emit('changeOperation',type,item || {})
      }else if (type === 'delete'){
        delData()
      }

    }
    function getTableList() {
      geeProcessMbHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        TITLE:layoutRef.value.form.TITLE,
      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows,res.msg[0].TotalRowCount)
      })

    }
    return {
      processHomeFilterForm,
      processMbHomeTableHeader,
      layoutRef,
      getTableList,
      btns,
      changeOperation,
      getC,
      delData
    }
  }
}
</script>

<style scoped lang="scss">

</style>
