<template>
  <div class="app-container mt20">
    <Form :formList="formList" :ruleFormData="ruleForm" :config="paramsData && paramsData.readonly === 'true' ? {buttonGroup: []} : {}" @fnClick="callback"></Form>
    <div v-if="paramsData && paramsData.readonly === 'true'" class="w100 mt50">
      <p style="font-size: 1.2rem;font-weight: 500;border-bottom: 1px solid #e7e7e7;">{{netWorkCard.title}}</p>
      <div v-for="item of netWorkCard.list" class="mt50">
        <div v-for="(val,index) of item.data" style="width: 80%;margin: auto;" :class="index + 1 === item.data.length ? 'border' : 'borderType'">
          <div style="width: 20%;border-right: 1px solid #e7e7e7;" class="ml10 disInlineBlock"><p>{{val.name}}</p></div>
          <p style="width: 75%" class="ml10 disInlineBlock">{{val.content}}</p>
        </div>
      </div>
    </div>
    <el-button v-if="paramsData && paramsData.readonly === 'true'" class="mb20 mt20" style="float: right;" @click="callback({fnCode: 'cancel'})">返回</el-button>
  </div>
</template>

<script setup name="Handle">
  import Form from '@/components/form/index.vue';
  import {addGroup, getGroup, updateGroup, resNameList} from "@/api/disRevenue/resource"
  export default {
    name: 'FileManageView',
    components: {Form},
    data() {
      return {
        ruleForm: {},
        formList: [],
        paramsData: {},
        netWorkCard: {
          title: '网卡信息',
          list: [
            {
              data: [
                {name: '接口名称', content: 'eno1(Intel Corporation Ethernet Connection X722 for 10GbE SFP+)'},
                {name: 'MAC地址', content: '7c:c3:85:b6:61:bf'},
                {name: '接口类型', content: 'Ethernet'},
                {name: 'IPv4地址', content: '172.16.15.103'}
              ]
            },
            {
              data: [
                {name: '接口名称', content: 'eno1(Intel Corporation Ethernet Connection X722 for 10GbE SFP+)'},
                {name: 'MAC地址', content: '7c:c3:85:b6:61:bf'},
                {name: '接口类型', content: 'Ethernet'},
                {name: 'IPv4地址', content: '172.16.15.103'}
              ]
            },
          ]
        }
      }
    },
    created() {
      this.paramsData = this.$route && this.$route.query;
      if (this.paramsData && this.paramsData.id) {
        this.getFormDataList(this.paramsData.id);
      }
      this.fnFormList();
      this.getResNameList();
    },
    methods: {
      // formList集合
      fnFormList(objVal) {
        this.formList = [{
          config: {title: '', colSpan: 'disBlock', readonly: this.paramsData.readonly},
          controls: {
            id: {label: 'ID',hidden: true},
            groupName: {label: '名称', span: 12, type: 'input'},
            type: {label: '类型', span: 12, type: 'input', disabled: true},
            description: {label: '描述', span: 12, type: 'textarea'},
            createTime: {label: '创建时间', span: 12, type: 'datetime', disabled: true},
            includedDevices: {label: '修改时间', span: 12, type: 'datetime', disabled: true},
            num: {label: '大小(KB)', span: 12, type: 'input', disabled: true},
            md5: {label: 'MD5值', span: 12, type: 'input', disabled: true},
            router: {label: '路径', span: 12, type: 'input', disabled: true},
            createBy: {label: '创建人', span: 12, type: 'input', disabled: true},
          }
        }];
      },
      // 获取详情
      getFormDataList(id) {
        getGroup(id).then(val => {
          if (val && val.data) {
            this.ruleForm = val.data;
          }
        }).catch(() => {
          this.$modal.msgError("操作失败")
        });
      },
      // 包含设备
      getResNameList() {
        resNameList().then(val => {
          this.formList[0].controls['includedDevices']['options']= val && val.map(item => {
            return Object.assign({label: item.resourceName, key: item.resourceName});
          });
        }).catch(() => {
          this.$modal.msgError("操作失败")
        });
      },
      // 监听事件
      callback(result, dataVal, formVal) {
        if (result && result.fnCode) {
          switch (result.fnCode) {
            case 'submit':
              let fnType = addGroup;
              if (dataVal && dataVal.id) {
                fnType = updateGroup;
              }
              fnType(dataVal).then(response => {
                this.$modal.msgSuccess(response.msg);
                this.$router.push("/resource/fileManage")
              }).catch(() => {
                this.$modal.msgError("操作失败")
              });
              break;
            case 'cancel':
              this.$router.push("/resource/fileManage");
              break;
            default:
          }
        }
      }
    }
  }
</script>
<style scoped>
  .borderType {
    border-top: 1px solid #e7e7e7;
    border-left: 1px solid #e7e7e7;
    border-right: 1px solid #e7e7e7;
  }
  .border {
    border: 1px solid #e7e7e7;
  }
</style>
