<template>
  <div class="data-dictionary h100">
    <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':true
   }" :form-attrs="{
     'span-attrs':{
       span:4
     }
   }" :table-header="HeaderConfig" :get-table-list="getTableData" :filter-form="formConfig">
      <template  v-if="store.isManager"  #plusBtn>
        <el-button  type="primary" :icon="Plus" @click="openDialog('add')">新增</el-button>
      </template>
      <template #operation="{data}">
        <el-button  type="info" @click="openDialog('detail',data)">查看</el-button>
        <el-button  type="info"  v-if="store.isManager"  @click="openDialog('edit',data)">修改</el-button>
        <el-button  type="info"  v-if="store.isManager"  @click="deleteObj(data)">删除</el-button>
      </template>
    </common-layout>

    <template v-if="isEditDialogShow && currentQDType == '1'">
      <commission-three-inventory-information-manage-s-j-q-d-setting-dialog @getTableData="getTableData" :dialog-operation-type="dialogOperationType" :current-dialog-obj="currentDialogOpObj" v-model:dialog-visible="isEditDialogShow"/>
    </template>
    <template v-if="isEditDialogShow && currentQDType == '2'">
      <commission-three-inventory-information-manage-x-w-q-d-setting-dialog @getTableData="getTableData"   :dialog-operation-type="dialogOperationType" :current-dialog-obj="currentDialogOpObj" v-model:dialog-visible="isEditDialogShow"/>
    </template>
    <template v-if="isEditDialogShow && currentQDType == '3'">
      <commission-three-inventory-information-manage-y-y-q-d-setting-dialog  @getTableData="getTableData"  :dialog-operation-type="dialogOperationType" :current-dialog-obj="currentDialogOpObj" v-model:dialog-visible="isEditDialogShow"/>
    </template>
    <template v-if="isEditDialogShow && currentQDType == '4'">
      <commission-three-inventory-information-manage-b-b-m-c-j-c-s-setting-dialog  @getTableData="getTableData"  :dialog-operation-type="dialogOperationType" :current-dialog-obj="currentDialogOpObj" v-model:dialog-visible="isEditDialogShow"/>
    </template>
    <template v-if="isEditDialogShow && currentQDType == '5'">
      <commission-three-inventory-information-manage-q-t-b-m-c-j-c-s-setting-dialog  @getTableData="getTableData"  :dialog-operation-type="dialogOperationType" :current-dialog-obj="currentDialogOpObj" v-model:dialog-visible="isEditDialogShow"/>
    </template>
  </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {commissionThreeInventoryInformationManageHome} from "@/data/all-form";
import {commissionThreeInventoryInformationManageHeaderSJQD,commissionThreeInventoryInformationManageHeaderQTBMJCQD,
    commissionThreeInventoryInformationManageHeaderBBMJCQD,commissionThreeInventoryInformationManageHeaderXWQD,
    commissionThreeInventoryInformationManageHeaderYYQD
} from "@/data/all-table-header";
import CommissionThreeInventoryInformationManageBBMCJCSSettingDialog
  from "@/views/main/c-views/credit-information/commission-three-inventory-information-manage/CommissionThreeInventoryInformationManageBBMCJCSSettingDialog.vue";
import CommissionThreeInventoryInformationManageQTBMCJCSSettingDialog
  from "@/views/main/c-views/credit-information/commission-three-inventory-information-manage/CommissionThreeInventoryInformationManageQTBMCJCSSettingDialog.vue";
import CommissionThreeInventoryInformationManageSJQDSettingDialog
  from "@/views/main/c-views/credit-information/commission-three-inventory-information-manage/CommissionThreeInventoryInformationManageSJQDSettingDialog.vue";
import CommissionThreeInventoryInformationManageXWQDSettingDialog
  from "@/views/main/c-views/credit-information/commission-three-inventory-information-manage/CommissionThreeInventoryInformationManageXWQDSettingDialog.vue";
import CommissionThreeInventoryInformationManageYYQDSettingDialog
  from "@/views/main/c-views/credit-information/commission-three-inventory-information-manage/CommissionThreeInventoryInformationManageYYQDSettingDialog.vue";
import {Plus} from "@element-plus/icons-vue";
import {onBeforeMount, ref} from "vue";
import {useDetailOrEdit} from "@/units/use-method/usePagination";
import {
  proDeleteXyxxSqd,
  proSelectUnitNewBbmjccsBBH,
  proSelectUnitNewBbmjccsBMMC,
  proSelectUnitNewBbmjccsYYSX, proSelectUnitNewQtbmjccsBBH, proSelectUnitNewQtbmjccsBMMC,
  proSelectUnitNewQtbmjccsZDYJ,
  proSelectUnitNewSjqdBBH,
  proSelectUnitNewSjqdBZBM,
  proSelectUnitNewSjqdSXLB, proSelectUnitNewXwqdBBH,
  proSelectUnitNewXwqdBMMC,
  proSelectUnitNewXwqdCDFJ, proSelectUnitNewYyqdBBH,
  proSelectUnitNewYyqdBMMC,
  proSelectUnitNewYyqdSXLB, proSelectXyxxSqd
} from "@/service/credit-information/commission-three-inventory-information-manage/commission-three-inventory-information-manage";
import {handleMes} from "@/units/element-ui/tip";
import {useRootStore} from "@/pinia/useStore";
import {InsertSyslog} from "@/units/use-method/user-log";
export default {
  name: "CommissionThreeInventoryInformationManage",
  components:{
    CommonLayout,
    CommissionThreeInventoryInformationManageBBMCJCSSettingDialog,
    CommissionThreeInventoryInformationManageQTBMCJCSSettingDialog,
    CommissionThreeInventoryInformationManageSJQDSettingDialog,
    CommissionThreeInventoryInformationManageXWQDSettingDialog,
    CommissionThreeInventoryInformationManageYYQDSettingDialog
  },
  computed: {
    Plus(){
      return Plus
    }
  },
  setup(){
    const store =useRootStore();
    const layoutRef = ref(null);
    const isEditDialogShow = ref(false);
    const HeaderConfig = ref([]);
    const formConfig = ref({...commissionThreeInventoryInformationManageHome});
    const currentQDType = ref('');
    const {changeOperation,currentOpObj:currentDialogOpObj,operationType:dialogOperationType} = useDetailOrEdit();
    function getTableData(){
      debugger
      proSelectXyxxSqd({
        conditionZero:layoutRef.value.form.QDMC,
        conditionOne:layoutRef.value.form.BZBM,
        conditionTwo:layoutRef.value.form.SXLB,
        conditionThree:layoutRef.value.form.XDRLB,
        conditionFour:layoutRef.value.form.YEAR,
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize
      }).then(res =>{
        InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息查询", "三清单查询成功", "委三清单信息管理", "")
        layoutRef.value.getResData(res.msg[0].Rows,res.msg[0].TotalRowCount)
      })
    }

    function openDialog(type,data){
      isEditDialogShow.value = true;
      changeOperation(type,data)
    }
    function deleteObj(data){
      debugger
      proDeleteXyxxSqd({
        CONDITIONZERO:layoutRef.value.form.QDMC,
        ID:data.ID
      }).then(res =>{
        handleMes(res,() => {
          InsertSyslog(localStorage.getItem("xyxx_usercode"),localStorage.getItem("xyxx_unitcode"), "信息删除", "三清单删除成功", "委三清单信息管理", "")
          getTableData()
        })
      })
    }
    function getHeader(val){
      switch (val){
        case "1":
          HeaderConfig.value = commissionThreeInventoryInformationManageHeaderSJQD;
            break;
        case "2":
          HeaderConfig.value = commissionThreeInventoryInformationManageHeaderXWQD;
          break;
        case "3":
          HeaderConfig.value = commissionThreeInventoryInformationManageHeaderYYQD;
          break;
        case "4":
          HeaderConfig.value = commissionThreeInventoryInformationManageHeaderBBMJCQD;
          break;
        case "5":
          HeaderConfig.value = commissionThreeInventoryInformationManageHeaderQTBMJCQD;
          break;
      }
    }
    function handleOptionResult(tempData,optionItem){   //处理下拉框返回结果
      let returnOption = [];
      returnOption =  tempData.map(i => ({
        ...i,
        label:i.NAME,
        value:i.NAME,
      }));
      let option = [
        {
          value:'',
          label:'请选择'
        }
      ].concat(returnOption);
      const formItem = formConfig.value.formItemsArr.find(i => i.modelValue === optionItem);
      formItem.options = [...option];
    }
    function getSXLB(val){
      switch (val){
        case "1":
          proSelectUnitNewSjqdSXLB().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"SXLB");
          })
          break;
        case "2":
          proSelectUnitNewXwqdCDFJ().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"SXLB");
          })
          break;
        case "3":
          proSelectUnitNewYyqdSXLB().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"SXLB");
          })
          break;
        case "4":
          proSelectUnitNewBbmjccsYYSX().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"SXLB");
          })
          break;
        case "5":
          proSelectUnitNewQtbmjccsZDYJ().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"SXLB");
          })
          break;
      }
    }
    function getBZBM(val){
      switch (val){
        case "1":
          proSelectUnitNewSjqdBZBM().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"BZBM");
          })
          break;
        case "2":
          proSelectUnitNewXwqdBMMC().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"BZBM");
          })
          break;
        case "3":
          proSelectUnitNewYyqdBMMC().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"BZBM");
          })
          break;
        case "4":
          proSelectUnitNewBbmjccsBMMC().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"BZBM");
          })
          break;
        case "5":
          proSelectUnitNewQtbmjccsBMMC().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"BZBM");
          })
          break;
      }
    }
    function getYERA(val){
      switch (val){
        case "1":
          proSelectUnitNewSjqdBBH().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"YEAR");
          })
          break;
        case "2":
          proSelectUnitNewXwqdBBH().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"YEAR");
          })
          break;
        case "3":
          proSelectUnitNewYyqdBBH().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"YEAR");
          })
          break;
        case "4":
          proSelectUnitNewBbmjccsBBH().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"YEAR");
          })
          break;
        case "5":
          proSelectUnitNewQtbmjccsBBH().then(res =>{
            let tempData = res.msg[0].Rows;
            handleOptionResult(tempData,"YEAR");
          })
          break;
      }
    }
    onBeforeMount(()=>{
      getSXLB('1');
      getBZBM('1');
      getYERA('1');
      getHeader('1');
      currentQDType.value = '1';
      let qdmcItem = formConfig.value.formItemsArr.find(i => i.modelValue==="QDMC");
      qdmcItem.events = {
        'change'(val){
          currentQDType.value = val;
          getSXLB(val);  //获取事项类别
          getBZBM(val);  //获取编制部门
          getYERA(val);  //获取年度
          getHeader(val);  //获取表头
          getTableData(); //获取数据
        }
      }
    })
    return{
      store,
      layoutRef,
      HeaderConfig,
      formConfig,
      isEditDialogShow,
      currentQDType,
      getTableData,
      openDialog,
      deleteObj,
      dialogOperationType,
      currentDialogOpObj
    }
  }
}
</script>

<style scoped>

</style>