<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-08-07 10:55:41
 * @LastEditors: 无尘
 * @LastEditTime: 2019-10-28 16:49:00
 -->
<!--
<back-info-table></back-info-table>

import backInfoTable from '@/components/api/back-info-table.vue';
-->
<template>
  <div>
    <template v-for="(itemValue, itemName, index) in itemData.properties">
      <table
        :key="index + itemName + 121"
        cellspacing="0"
        cellpadding="0"
        border="0"
        class="el-table__body"
        style="width: 100%;table-layout: fixed;">
        <tbody>
          <tr class="el-table__row">
            <td
              rowspan="1"
              colspan="1"
              class="el-table_1_column_1"
              style="width: 36px;">
              <div
                v-if="itemValue.type == 'object' || itemValue.type == 'array'"
                class="cell">
                <i class="el-icon-minus" />
              </div>
            </td>
            <td
              rowspan="1"
              colspan="1"
              class="el-table_1_column_1">
              <div class="cell el-tooltip">
                {{ itemName }}
              </div>
            </td>
            <td
              rowspan="1"
              colspan="1"
              class="el-table_1_column_2">
              <div class="cell el-tooltip">
                {{ itemValue.type }}
              </div>
            </td>
            <td
              rowspan="1"
              colspan="1"
              class="el-table_1_column_3">
              <div class="cell el-tooltip">
                {{ itemValue.example }}
              </div>
            </td>
            <td
              v-if="isDes"
              rowspan="1"
              colspan="1"
              class="el-table_1_column_4">
              <div class="cell el-tooltip">
                {{ itemValue.description }}
              </div>
            </td>
          </tr>
        </tbody>
      </table>
      <table-row
        v-if="itemValue.type == 'array' && Object.keys(itemValue.items.properties).length"
        :key="index + '122' + itemName"
        class="el-table__row"
        style="padding-left: 10px;"
        :item-data="itemValue.items" />
      <table-row
        v-if="itemValue.type == 'object' && Object.keys(itemValue.properties).length"
        :key="index + '122' + itemName"
        class="el-table__row"
        style="padding-left: 10px;"
        :item-data="itemValue" />
    </template>
  </div>
</template>
<script>
export default {
  name: 'TableRow',
  props: {
    itemData: {
      type: [ Object, Array ],
      default() {
        return {};
      }
    },
    isDes: {
      type: Boolean
    }
  },
  data() {
    return {
      trData: {
        protocol: 'http',
        interfaceUrl: '/',
        requestType: 'post',
        frontParams: {
          type: 'object', // object，array,string,number,boolean,
          properties: {
            name: {
              originType: 'query', // 来源类型 query,body,header
              type: 'object',
              isBackendField: 0, // 是否后端字段
              defaultVal: 'val', // 默认值
              isRootKey: 0, // 是否是后端参数字段
              rootKey: '', // 后端参数字段
              objectClass: '', // 如果是object 并且是dubbo
              description: '描述',
              check: true,
              required: [],
              properties: {
                nameId: {
                  originType: 'query', // 来源类型 query,body,header
                  type: 'object',
                  isBackendField: 0, // 是否后端字段
                  defaultVal: 'val', // 默认值
                  isRootKey: 0, // 是否是后端参数字段
                  rootKey: '', // 后端参数字段
                  objectClass: '', // 如果是object 并且是dubbo
                  description: '描述',
                  check: true
                }
              }
            },
            id: {
              originType: 'query', // 来源类型 query,body,header
              type: 'string',
              isBackendField: 0, // 是否后端字段
              defaultVal: 'val', // 默认值
              isRootKey: 0, // 是否是后端参数字段
              rootKey: '', // 后端参数字段
              objectClass: '', // 如果是object 并且是dubbo
              description: '描述',
              check: true
            }
          },
          required: []
        }
      }
    };
  },
  mounted() {
    const that = this;
    that.trData = that.itemData;
  },

  watch: {
    itemData: function(newData, oldData) {
      const that = this;
      that.trData = newData;
    }
  }
};
</script>
<style lang="less" scoped>
.w-320 {
  width: 320px;
}
.m-t-14 {
  margin-top: 14px;
}
</style>
