<template>
 <div class="position-re">
   <my-breadcrumb class="my-breadcrumb" :breadcrumb-arr="breadArr"></my-breadcrumb>
   <div class="back" @click="$emit('changeOperation','',{})"><span class="fa fa-reply cur-po " >返回</span></div>
   <div class="my-detail-main">
     <div class="block">
       <div class="my-b-title">基础信息</div>
       <div class="form"><diy-el-form :span="24" v-model:model-form="forms" :forms="unitWatchDetailFormConfig"/></div>
     </div>
<!--     <div class="block">-->
<!--       <div class="my-b-title">单位</div>-->
<!--       <div class="my-search-div btn" v-if="operationType!=='detail'"><el-button :icon="Plus" ></el-button></div>-->
<!--       <my-table-->
<!--         border-->
<!--         :is-height-equal-max-height="true"-->
<!--         :page-size="8"-->
<!--         :headers="unitWatchDetailTableHeader"-->
<!--        :table-data="tableData">-->

<!--       </my-table>-->
<!--     </div>-->

   </div>
   <div class="detail-operation-btn" v-if="operationType!=='detail'">
     <el-button  @click="$emit('changeOperation','',{})">关闭</el-button>
     <el-button type="info" @click="saveS">提交</el-button>
   </div>

 </div>
</template>

<script>
import MyBreadcrumb from "@/components/common/MyBreadcrumb.vue";
import {onBeforeMount, ref, watch} from "vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {unitWatchDetailForm} from "@/data/all-forms";
import MyTable from "@/components/common/MyTable.vue";
import {unitWatchDetailTableHeader} from "@/data/all-table-header";
import AddUnitWatchDialog from "@/view/other/c-views/data-watch/data-gather-watch/unit-watch/AddUnitWatchDialog.vue";
import {addOrDataImputationData, getUnitImputationWatchDetail} from "@/service/data-gather-watch/unit-imputation-watch";
import {Plus} from "@element-plus/icons-vue";
import {handleMes} from "@/unit/element-ui/tip";
import {useRootStore} from "@/stores/useStore";

export default {
  name: "UnitWatchDetail",
  computed: {
    Plus() {
      return Plus
    }
  },
  components: {AddUnitWatchDialog, MyTable, DiyElForm, MyBreadcrumb},
  props:{
    currentOpObj:{

    },
    operationType:{

    }
  },
  setup(props,{emit}) {
    const allSheetNameArr =ref([])
    const forms = ref({

    })
    function saveS() {
      addOrDataImputationData({
       ID:props.currentOpObj.ID,
       TABNAME:forms.value.TABNAME,
       TABCOMMENT:forms.value.TABCOMMENT,
        UNIT:forms.value.PROVIDERUNIT_NAME,
        SOURCEFROM:forms.value.SOURCEFROM,
        RID:props.currentOpObj.RID,
        CID:props.currentOpObj.CID,
        GXJH_SPACE:props.currentOpObj.GXJH_SPACE,
        KETTLE_LOCATION:forms.value.KETTLE_LOCATION || '',
        detailList:[]
      }).then(res =>{
        handleMes(res,() => {
          emit('changeOperation','')
        },() => {},'操作成功','操作失败')
      })
    }
    const unitWatchDetailFormConfig = ref({...unitWatchDetailForm})
    function getSheetName (type) {
      var type_name;
      var list = allSheetNameArr.value;
      switch (type) {
        case '0':
          type_name = 'GXJH';
          break;
        case '1':
          type_name = 'ZWXX';
          break;
        case '2':
          type_name = 'XYXX';
          break;
        case '3':
          type_name = 'LSKJ';
          break;
        default:
          type_name = '';
          break;
      }
      let findSpaceName = unitWatchDetailFormConfig.value.formItemsArr.find(i=>i.modelValue === 'TABNAME')
      findSpaceName.options = [{value:'',label:'空'}].concat(list.filter(i => i.OWNER === type_name).map(it => ({
        value:it.TABLE_NAME,
        label:it.TABLE_NAME,
      })))

    }
    onBeforeMount(() => {
      watch(() => forms.value.SOURCEFROM,(Val) => {
        console.log('变化了SOURCEFROM')
        getSheetName(Val)
      },{

      })
      getUnitImputationWatchDetail().then(res => {
        forms.value = {
          ...props.currentOpObj
        }
        allSheetNameArr.value = res.msg[0].Rows
        getSheetName(forms.value.SOURCEFROM)
      })
    })
    const tableData =ref([])
    const breadArr = [
      {name:'数据采集监控 '},
      {name:' 各单位数据归集监控表 '},
    ]
    return {
      breadArr,
      forms,
      unitWatchDetailFormConfig,
      tableData,
      unitWatchDetailTableHeader,
      allSheetNameArr,
      getSheetName,
      saveS
    }
  }
}
</script>

<style scoped lang="scss">
.form{
  padding-left: 5%;
  max-width:1000px;
}
</style>
