<template>
  <!-- <el-dialog
    title="查看"
    width="70%"
    :close-on-click-modal="false"
    :visible.sync="visible"> -->
  <div>
    <div class="my-title">查看</div>
    <div style="margin-left: 20px;margin-right: 20px">
      <!-- 工作流 -->
      <div v-show="dataForm.workFlowBusinessExt">
        <el-steps :active="activeNo" finish-status="success" align-center style="margin-bottom: 20px">
          <template v-for="(item, i) in stepList">
            <el-step :icon="item.icon" :title="item.title" :description="item.description"></el-step>
          </template>
        </el-steps>
        <el-collapse style="margin-bottom: 20px">
          <el-collapse-item>
            <template slot="title">
              <span style="color: red">审批日志（展开查看更多）：</span>
            </template>
            <template v-for="(item, i) in logList">
              <div>{{++i}}：{{item.approverName}}  {{item.createTime}}  {{item.approvalValue}}</div>
            </template>
          </el-collapse-item>
        </el-collapse>
      </div>
      <div v-if="isFlow">
        <approve-component ref="approve" @approveFinished="approveFinished"/>
      </div>
      <el-collapse v-model="activeNames">
        <el-collapse-item name="1">
          <template slot="title">
            <h3 style="color: blue">基本信息：</h3>
          </template>
          <e-desc column="3">
            <e-desc-item label="评审编码">{{dataForm.reCode}}</e-desc-item>
            <e-desc-item label="沟通编码">{{dataForm.coCode}}</e-desc-item>
            <e-desc-item label="评审类别">{{dataForm.reTypeValue}}</e-desc-item>
            <e-desc-item label="客户名称">{{dataForm.customerName}}</e-desc-item>
            <e-desc-item label="联系人">{{dataForm.contact}}</e-desc-item>
            <e-desc-item label="合同号">{{dataForm.contractCode}}</e-desc-item>
            <e-desc-item label="备注说明" span="3">{{dataForm.notes}}</e-desc-item>
            <e-desc-item label="与物料有关要求的明确性、符合性" span="3">
              1、顾客对物料的要求与潜在要求是否明确 -- {{ dataForm.part11 && Number(dataForm.part11) === 1 ? '是' : '否' }}
              <br>
              2、合同的合法性、完性整性、规范性 -- {{ dataForm.part12 && Number(dataForm.part12) === 1 ? '是' : '否' }}
            </e-desc-item>
            <e-desc-item label="风险控制能力" span="3">
              1、图样和技术要求能否满足生产要求，物料服务和培训能否满足要求 -- {{ dataForm.part21 && Number(dataForm.part21) === 1 ? '是' : '否' }}
              <br>
              2、外购器材风险的控制情况，能否保障生产 -- {{ dataForm.part22 && Number(dataForm.part22) === 1 ? '是' : '否' }}
              <br>
              3、质量控制情况能否满足要求（生产、检验和验收设备能否满足要求） -- {{ dataForm.part23 && Number(dataForm.part23) === 1 ? '是' : '否' }}
              <br>
              4、财务能否满足生产要求（成本、价格、结算方式与付款能否接受） -- {{ dataForm.part24 && Number(dataForm.part24) === 1 ? '是' : '否' }}
              <br>
              5、规格数量能否满足，运输、交货方式能否满足，生产进度能否满足 -- {{ dataForm.part25 && Number(dataForm.part25) === 1 ? '是' : '否' }}
            </e-desc-item>
            <e-desc-item label="满足规定要求的能力" span="3">
              项目组对履行承诺的风险（包括技术、质量、生产能力、进度、经费）识别： {{ Number(dataForm.part31) === 1 ? '高' : Number(dataForm.part31) === 2 ? '中' : '低' }}
              <br>
              控制能力： {{ Number(dataForm.part32) === 1 ? '可控' : Number(dataForm.part32) === 2 ? '基本可控' : '不可控' }}
              <br>
              采取措施： {{ dataForm.takeStep || '无' }}
            </e-desc-item>
          </e-desc>
        </el-collapse-item>
        <el-collapse-item name="2">
          <template slot="title">
            <h3 style="color: blue">合同评审表：</h3>
          </template>
          <upload-component :display="true" :display-title="false" :accept="'*'" :file-obj-list="fileList"/>
        </el-collapse-item>
        <el-collapse-item name="3">
          <template slot="title">
            <h3 style="color: blue">合同沟通信息：</h3>
          </template>
          <div style="margin-top: 20px" v-if="isCommVisible">
            <communicate-detail ref="commDetail"/>
          </div>
        </el-collapse-item>
      </el-collapse>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="onChose">返回</el-button>
    </span>
  </div>
  <!-- </el-dialog> -->
</template>

<script>
  import EDesc from '../common/e-desc'
  import EDescItem from '../common/e-desc-item'
  import { geTreDetail } from '@/api/cus'
  import uploadComponent from '../common/upload-component'
  import { dealStepData, dealStepLogs } from '@/api/util'
  import ApproveComponent from '../common/approve-component'
  import CommunicateDetail from '@/views/modules/cus/communicate-detail'
  export default {
    name: 'contract-detail',
    components: {
      CommunicateDetail,
      EDesc,
      EDescItem,
      uploadComponent,
      ApproveComponent
    },
    data () {
      return {
        activeNames: ['1', '2', '3'],
        visible: false,
        isCommVisible: false,
        isFlow: false,
        id: 0,
        dataForm: {},
        cusRCommProductVOS: [],
        fileList: [],
        fileList1: [],
        activeNo: 0,
        stepList: [],
        logList: []
      }
    },
    methods: {
      onChose () {
        this.isCommVisible = false
        this.$emit('onChose')
      },
      async init (id, businessType) {
        this.visible = true
        this.isFlow = !!(businessType && businessType !== '')
        this.id = id || 0
        this.dataForm = {}
        this.cusRCommProductVOS = []
        this.fileList = []
        this.fileList1 = []
        this.stepList = []
        this.logList = []
        this.getDetails(businessType)
      },
      getDetails (businessType) {
        geTreDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
            // 流程图展示
            if (data.data.workFlowBusinessExt) {
              dealStepData(data.data.workFlowBusinessExt.workFlowProcessStepList, this.stepList)
              dealStepLogs(data.data.workFlowBusinessExt.processLogList, this.logList)
            }
            if (data.data.workFlowProcessStepList) {
              this.activeNo = Number(data.data.workFlowProcessStepList.activeNo)
            }
            // 合同评审表附件显示
            this.fileList = []
            data.data.attachList.forEach((item) => {
              this.fileList.push({
                name: item.fileName,
                url: item.url,
                id: item.url
              })
            })
            // 沟通信息表附件显示
            this.fileList1 = []
            if (data.data.communicationAttachList) {
              data.data.communicationAttachList.forEach((item) => {
                this.fileList1.push({
                  name: item.fileName,
                  url: item.url,
                  id: item.url
                })
              })
            }
            // 获取沟通详情
            if (data.data.cusCommunicationExt) {
              let id = data.data.cusCommunicationExt.coId
              this.isCommVisible = true
              this.$nextTick(() => {
                this.$refs.commDetail.init(id, null, true)
              })
            }
            // 初始化审批Form
            this.showApproveForm(businessType, this.id)
          }
        })
      },
      // 初始化审批Form
      showApproveForm (businessType, businessId) {
        if (this.isFlow) {
          this.$nextTick(() => {
            this.$refs.approve.init(businessType, businessId)
          })
        }
      },
      // 审批完成
      approveFinished () {
        this.onChose()
        this.$emit('approveFinished')
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
.title{
  padding: 10px 0 ;
}
</style>
