<!--统筹人页面-->
<template>
  <div class="coordFeedBackMain">
   <el-tabs v-model="mainActive" type="card" class="main-tab marginCard">
    <el-tab-pane :label="$t('coordManageMain.mainTab')" name="first">
    </el-tab-pane>
  </el-tabs>
  <up-down-layout :handleFlag.sync="handleFlag" :headerVisible="false">
    <search-form  :formValue.sync="queryParas"
                  searchPerms="search"
                  slot="query"
                  resetPerms="reset"
                  @clearParam="clearParam"
                  @handleFilter="handleFilter"
                  :componentList="componentList">
    </search-form>
      <template slot="table">
        <data-table :api="coordPageApi"
                    :loadCount.sync="loadCount"
                    :sourceData.sync="sourceData"
                    :queryParas="queryParas"
                    :showPage="false"
                    :columns="columns"
                    :menuFlag="false"
                    @getTableData="getTableData"
                    max-height="190"
                    @current-change="handleCurrentChange"
                    ref="dataTable">
          <template slot="showFlag" slot-scope="scope">
              <div class="iconfont icontanhao1 fengxian2" v-if="scope.data.row.showFlag==='1'"></div>
          </template>
          <template slot="currentShow" slot-scope="scope">
              <div class="iconfont icongou showColor"  v-if="isSelected === scope.data.row.keyId"></div>
          </template>
        </data-table>
      </template>
        <!--tab区域-->
      <template slot="table">
        <div v-if="dataShowFlag">
          <el-tabs v-model="activeName" type="card" class="myeltab" @tab-click="handleTabs">
            <el-tab-pane v-for="item in tabList" :key="item.index" :name="item.index">
              <span slot="label">{{item.label}}<span class="iconfont iconyichangshujutiaozheng unsolveColor" v-if="item.dealing==='1'"></span></span>
            </el-tab-pane>
          </el-tabs>
          <keep-alive>
            <component v-bind:is="tabList[activeName].component" :projectInfo="projectInfo" :activeName="activeName" :key="activeName" :fileAll="fileType" @solveFlag="solveFlag"></component>
          </keep-alive>
        </div>
    </template>
  </up-down-layout>
  <!--发起评审-->
  <review-material-pop v-if="reviewVisible" visible.sync="reviewVisible" :editModel="editModel" :item="{}"></review-material-pop>
  </div>
</template>
<script>
import { searchForm, upDownLayout, DataTable, amountInput } from 'newepoch-components'
import coordManageApi from '@/api/assetoutfeedback/coordManage/coordManageApi'
import absFileSelectList from '@/components/element/assetoutfeedback/absFileSelectList'
import coordFeedBackSub from '@/pages/assetoutfeedback/coordManage/coordFeedBackSub'
import relationUserSub from '@/pages/assetoutfeedback/coordManage/relationUserSub'
import relationReportSub from '@/components/element/assetoutfeedback/relationReportSub'
import reviewMaterialPop from '@/pages/assetaudit/reviewMaterial/reviewMaterial-add'
import componentsApi from '@/api/assetoutfeedback/componentsApi'
import * as format from '@/filters/index'
import BasePage from '@/pages/basePage'
export default {
  extends: new BasePage(),
  components: {
    searchForm,
    upDownLayout,
    DataTable,
    absFileSelectList,
    coordFeedBackSub,
    relationUserSub,
    relationReportSub,
    amountInput,
    reviewMaterialPop
  },
  name: 'coordManageMain',
  data () {
    return {
      mainActive: 'first',
      activeName: '0',
      handleFlag: true,
      reviewVisible: false,
      dataShowFlag: false,
      editModel: 'C',
      currentRow: '', // 当前选中行
      isSelected: '',
      newData: [],
      projectInfo: {},
      fileType: [], // 文件类型
      tabList: [
        {
          index: '0',
          label: this.$t('coordManageMain.lawFeedback'),
          dealing: '0',
          component: coordFeedBackSub
        },
        {
          index: '1',
          label: this.$t('coordManageMain.manageFeedback'),
          dealing: '0',
          component: coordFeedBackSub
        },
        {
          index: '2',
          label: this.$t('coordManageMain.relatedUser'),
          dealing: '0',
          component: relationUserSub
        },
        {
          index: '3',
          label: this.$t('coordManageMain.relatedList'),
          dealing: '0',
          component: relationReportSub
        },
        {
          index: '4',
          label: this.$t('coordManageMain.startReview'),
          dealing: '0',
          component: ''
        }
      ],
      componentList: [
        {
          // 产品名称
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.projectName,
          disabled: false,
          value: 'projectId',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '100px',
          filterable: true,
          clearable: true,
          name: 'projectId',
          componentName: absFileSelectList
        },
        {
          // 期数
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.periods,
          disabled: false,
          value: 'periods',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          labelWidth: '100px',
          clearable: true,
          name: 'periods',
          componentName: amountInput
        }
      ],
      columns: [
        {
          // 是否已处理
          prop: 'showFlag',
          slot: true,
          align: 'center',
          width: '50px',
          label: ''
        },
        {
          // 当前显示
          prop: 'currentShow',
          slot: true,
          align: 'center',
          width: '80px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.currentShow
        },
        {
          // 产品名称
          prop: 'projectName',
          align: 'left',
          width: '400px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.projectName
        },
        {
          // 期数
          prop: 'periods',
          align: 'center',
          width: '50px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.periods
        },
        {
          // 拟入池笔数
          prop: 'estimateAssetTotal',
          align: 'center',
          width: '130px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.estimateAssetTotal,
          format: (row) => {
            return this.numCountFormat(row.estimateAssetTotal)
          }
        },
        {
          // 现笔数
          prop: 'realAssetTotal',
          align: 'center',
          width: '130px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.realAssetTotal,
          format: (row) => {
            return this.numCountFormat(row.realAssetTotal)
          }
        },
        {
          // 总金额
          prop: 'totalAmount',
          align: 'right',
          width: '250px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.totalAmount,
          format: (row) => {
            return format.thousandFilter(row.totalAmount, 2)
          }
        },
        {
          // 已退单笔数
          prop: 'returnAssetTotal',
          align: 'center',
          width: '130px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.returnAssetTotal,
          format: (row) => {
            return this.numCountFormat(row.returnAssetTotal)
          }
        },
        {
          // 预计抽样笔数
          prop: 'planSampleCount',
          align: 'center',
          width: '130px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.planSampleCount,
          format: (row) => {
            return this.numCountFormat(row.planSampleCount)
          }
        },
        {
          // 尽调时间
          prop: 'dueDiligenceDate',
          align: 'center',
          width: '250px',
          label: this.$i18n.messages[this.$i18n.locale].coordManageMain.dueDiligenceDate,
          format: (row) => {
            if (format.formatDate(row.dueDiligenceStartDate) === '' && format.formatDate(row.dueDiligenceEndDate) !== '') {
              return format.formatDate(row.dueDiligenceEndDate)
            } else if (format.formatDate(row.dueDiligenceStartDate) !== '' && format.formatDate(row.dueDiligenceEndDate) === '') {
              return format.formatDate(row.dueDiligenceStartDate)
            } else if (format.formatDate(row.dueDiligenceStartDate) === '' && format.formatDate(row.dueDiligenceEndDate) === '') {
              return ''
            } else {
              return format.formatDate(row.dueDiligenceStartDate) + this.$t('coordManageMain.to') + format.formatDate(row.dueDiligenceEndDate)
            }
          }
        }
      ],
      sourceData: []
    }
  },
  mounted () {
    this.handleFilter()
    this.getFileType()
  },
  watch: {
    activeName: function () {
      if (this.activeName === '4') {
        this.reviewVisible = true
      } else {
        this.reviewVisible = false
      }
    }
  },
  methods: {
    handleTabs (tab, event) {

    },
    // 获取所有文件类型
    getFileType () {
      this.fileListApi.getList({ fileQueryType: '4', stampWay: '3' }).then(res => {
        if (res.success) {
          this.fileType = res.data
        }
      })
    },
    // 默认选中第一行
    getTableData (data) {
      if (data && data.length > 0) {
        this.newData = data.filter(item => item.isAssignUser === '1')
        this.dataShowFlag = true
        if (this.newData.length > 0) {
          this.isSelected = this.newData[0].keyId
          this.loadData(this.newData[0])
        } else {
          this.isSelected = data[0].keyId
          this.loadData(data[0])
        }
      } else {
        this.dataShowFlag = false
      }
    },
    handleCurrentChange (val) {
      if (val) {
        this.currentRow = val
        this.isSelected = val.keyId
        this.loadData(val)
      } else {
        this.loadData()
      }
    },
    // 默认加载律所反馈
    loadData (val) {
      if (val && val !== null) {
        this.projectInfo = {
          projectId: val.projectId,
          periods: val.periods,
          projectName: val.projectName,
          coordType: val.isAssignUser// 统筹人类型 1:当前跟进人 0:不是
        }
      } else {
        this.projectInfo = {}
      }
    },
    numCountFormat (data) {
      data = data || '0'
      return data + this.$t('coordManageMain.count')
    },
    solveFlag (data) {
      if (this.activeName === '0') {
        this.tabList[0].dealing = data
      }
      if (this.activeName === '1') {
        this.tabList[1].dealing = data
      }
    }
  },
  computed: {
    coordPageApi () {
      return coordManageApi.getCoordPage
    },
    coordInfoApi () {
      return coordManageApi.getCoordInfo
    },
    fileListApi () {
      return componentsApi.fileList
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~@/styles/assetoutfeedback/common.scss'
</style>
