<template>
  <a-card :bordered="false" v-show="visible" class="card" :title="modalTitle">
    <a-row :gutter="48" slot="extra">
      <a-col :md="48" :sm="48">
        <span class="table-page-search-submitButtons" style="float: right">
          <a-button style="margin-left: 8px" type="default" @click="handleCancel()">返回</a-button>
        </span>
      </a-col>
    </a-row>
    <detail-list title="" :col="2">
      <!--      <detail-list-item term="模板内容">{{ model.content }}</detail-list-item>-->
      <detail-list-item term="类型">{{ BaseTool.Object.getField(this.typeMap,model.type) }}</detail-list-item>
      <detail-list-item term="备注">{{ model.remark }}</detail-list-item>
      <detail-list-item term="更新日期">{{ model.updateTime }}</detail-list-item>
      <detail-list-item term="创建人">{{ model.createdUserId }}</detail-list-item>
      <detail-list-item term="更新人">{{ model.updateUserId }}</detail-list-item>
      <detail-list-item term="更新人名称">{{ model.updateUserName }}</detail-list-item>
      <detail-list-item term="二级类别">{{ model.secondTypeId }}</detail-list-item>
    </detail-list>
    <title-divider title="字段明细" width="90px"></title-divider>
    <a-table
      bordered
      :data-source="data"
      :columns="columns"
      tableLayout="auto"
      rowKey="fieldName">
      <span slot="action" slot-scope="record">
        <template>
          <a @click="handleOptionList(record)">下拉选项</a>
        </template>
      </span>
    </a-table>
    <a-modal
      title="下拉选项"
      :width="800"
      :visible="visibleOptions"
      class="ant-modal2"
      @cancel="handleCancel2">
      <a-table
        bordered
        :data-source="dataOptions"
        :columns="columnOptions"
        tableLayout="auto"
        rowKey="name">
      </a-table>
      <template slot="footer">
        <a-button :loading="confirmLoading" type="default" @click="handleCancel2()">关闭</a-button>
      </template>
    </a-modal>
  </a-card>
</template>

<script>
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item
export default {
  name: 'CustomFieldTemplateDetail',
  components: {
    DetailList,
    DetailListItem
  },
  data () {
    return {
      confirmLoading: false,
      mdl: {},
      modalTitle: null,
      visible: false,
      visibleOptions: false,
      // 下拉框map
      typeMap: {},
      typeFieldMap: {},
      yesNoMap: {},
      model: {
        'content': null,
        'type': null,
        'remark': null,
        'updateTime': null,
        'createdUserId': null,
        'updateUserId': null,
        'updateUserName': null,
        'secondTypeId': null
      },
      data: [],
      dataOptions: [],
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '显示名称',
          dataIndex: 'label'
        },
        {
          title: '字段名称',
          dataIndex: 'fieldName'
        },
        {
          title: '类型',
          dataIndex: 'type',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.typeFieldMap, text)
          }
        },
        {
          title: '是否必填',
          dataIndex: 'required',
          customRender: (text, record, index) => {
            return this.BaseTool.Object.getField(this.yesNoMap, text)
          }
        },
        {
          title: '显示行数',
          dataIndex: 'rows',
          width: 120
        },
        {
          title: '排序',
          dataIndex: 'sort',
          width: 150
        },
        {
          title: '默认值',
          dataIndex: 'defaultValue',
          width: 150
        },
        {
          title: '最小长度',
          dataIndex: 'minLength',
          width: 150
        },
        {
          title: '最大长度',
          dataIndex: 'maxLength',
          width: 150
        },
        {
          title: '操作',
          key: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columnOptions: [
        {
          title: '序号',
          dataIndex: 'index',
          customRender: (text, record, index) => {
            return index + 1
          }
        },
        {
          title: '参数名称',
          dataIndex: 'name'
        },
        {
          title: '参数值',
          dataIndex: 'value'
        }
      ]
    }
  },
  created () {
    // 下拉框map
    this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOM_FIELD_TEMPLATE_TYPE)
    this.typeFieldMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOM_FIELD_TEMPLATE_FILED_TYPE)
    this.yesNoMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  },
  methods: {
    base (record) {
      this.visible = true
      this.modalTitle = '详情'
      this.model = record
      this.data = JSON.parse(record.content)
    },
    handleCancel () {
      this.visible = false
      this.confirmLoading = false
      this.$emit('ok')
    },
    handleCancel2 () {
      this.visibleOptions = false
      this.dataOptions = []
    },
    handleOptionList (record) {
      this.visibleOptions = true
      this.dataOptions = record.optionList
    }
  }
}
</script>
