<template>
  <slide-view
    :listener-ids="listenerIDs"
    :no-listener-ids="noListenerIDs"
    :no-listener-class="noListenerClass"
    :body-style="{padding: 0, height: '100%'}"
    xs-empty-icon="nopermission"
    xs-empty-text="暂无权限"
    @side-close="hideView">
    <flexbox
      v-loading="loading"
      direction="column"
      align="stretch"
      class="d-container">
      <c-r-m-detail-head
        :detail="detailData"
        
        :id="id"
       :crm-type="crmType"
        @handle="detailHeadHandle"
        @close="hideView"/>
      <div class="tabs">
        <el-tabs
          v-model="tabCurrentName"
          @tab-click="handleClick">
          <el-tab-pane
            v-for="(item, index) in tabnames"
            :key="index"
            :label="item.label"
            :name="item.name"/>
        </el-tabs>
      </div>
      <div
        id="follow-log-content"
        class="t-loading-content">
        <keep-alive>
          <component
            :is="tabName"
            :detail="detailData"
            :id="id"
            :crm-type="crmType"/>
        </keep-alive>
      </div>
    </flexbox>
    <c-r-m-create-view
      v-if="isCreate"
      :action="{type: 'update', id: id, batchId: detailData.batchId}"
      :crm-type="crmType"
      @save-success="editSaveSuccess"
      @hiden-view="isCreate=false"/>
  </slide-view>
</template>

<script>
import { crmDictsRead } from '@/api/dict/dict'

import SlideView from '@/components/SlideView'
import CRMDetailHead from '../components/CRMDetailHead'
import ClueFollow from './components/ClueFollow' 
import DictSubtable from './components/DictSubtable' // 子表信息
import CRMBaseInfo from '../components/CRMBaseInfo' // 基本信息
import RelativeFiles from '../components/RelativeFiles' // 相关附件
import CRMCreateView from '../components/CRMCreateView' // 新建页面

import detail from '../mixins/detail'

export default {
  /** 线索管理 的 线索详情 */
  name: 'DictDetail',
  components: {
    SlideView,
    CRMDetailHead,
    ClueFollow,
    CRMBaseInfo,
    RelativeFiles,
    CRMCreateView,
    DictSubtable
  },
  mixins: [detail],
  props: {
    // 详情信息id
    id: [String, Number],
    // 监听的dom 进行隐藏详情
    listenerIDs: {
      type: Array,
      default: () => {
        return ['crm-main-container']
      }
    },
    // 不监听
    noListenerIDs: {
      type: Array,
      default: () => {
        return []
      }
    },
    noListenerClass: {
      type: Array,
      default: () => {
        return ['el-table__body']
      }
    }
  },
  data() {
    return {
      loading: false, // 展示加载loading
      crmType: 'dicts',
      detailData: {}, // read 详情
      // headDetails: [
      //   { title: '字典编码', value: '' },
      //   { title: '字典名称', value: '' },
      //   { title: '字典描述', value: '' },
      //   // { title: '是否可用', value: '' },
      // ],
      tabnames: [
        { label: '基本信息', name: 'basicinfo' },
        // //{ label: '跟进记录', name: 'followlog' },
        // //{ label: '附件', name: 'file' },
        { label: '子表信息', name: 'subtable' },
      ],
      tabCurrentName: 'basicinfo',
      isCreate: false // 编辑操作
    }
  },
  computed: {
    tabName() {
      // if (this.tabCurrentName == 'followlog') {
      //   return 'clue-follow'
     if (this.tabCurrentName == 'basicinfo') {
        return 'c-r-m-base-info'
      }
    // else if (this.tabCurrentName == 'file') {
      //   return 'relative-files'
      else if(this.tabCurrentName=='subtable'){
        return 'dict-subtable'
      }
      return ''
    }
  },
  created(){
  },
  mounted() {
  },
  methods: {
    getDetial() {
      this.loading = true
      crmDictsRead(this.id)
        .then(res => {
          this.detailData=res;
          // //this.headDetails[0].value = res.Code
          // //this.headDetails[1].value = res.Name
          // //this.headDetails[2].value = res.Description
          // //this.headDetails[3].value = res.Enabled  
          this.loading = false
        })
        .catch(() => {
          this.loading = false
        })
    },
    //* * 点击关闭按钮隐藏视图 */
    hideView() {
      this.$emit('hide-view')
    },
    //* * tab标签点击 */
    handleClick(tab, event) {},
    editSaveSuccess() {
      this.$emit('handle', { type: 'save-success' })
      this.getDetial()
    }
  },
  watch: {
    id: {
      handler(newVal) {
      },
      immediate: true
    }
  },
}
</script>

<style lang="scss" scoped>
@import '../styles/crmdetail.scss';
</style>
