<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-if="dataForm.workFlowBusinessExt && dataForm.workFlowBusinessExt.workFlowProcessStepList">
        <el-steps :active="stepActive" align-center finish-status="success" style="margin-bottom: 20px">
        <template v-for="(item, i) in dataForm.workFlowBusinessExt.workFlowProcessStepList">
            <el-step :title="item.stepName" :description="item.assigneeName"></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 dataForm.workFlowBusinessExt.processLogList">
            <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>
      <e-desc title="基本信息" column="3">
        <e-desc-item label="编码">{{dataForm.code}}</e-desc-item>
        <e-desc-item label="发生日期">{{dataForm.happenTime}}</e-desc-item>
        <e-desc-item label="报销金额">{{dataForm.submitExpenseAmount}}</e-desc-item>
        <e-desc-item label="报销内容" span="3">{{dataForm.happenContent}}</e-desc-item>
        <e-desc-item label="备注说明" span="3">{{dataForm.notes}}</e-desc-item>
      </e-desc>
      <e-desc title="报销证明附件">
        <upload-component :display="true" :display-title="false" :accept="'*'" :file-obj-list="fileList"/>
      </e-desc>
    </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 uploadComponent from '../common/upload-component'
  import { getExpenseDetail } from '@/api/finance'
  import ApproveComponent from '@/views/modules/common/approve-component'
  export default {
    name: 'expense-detail',
    components: {
      ApproveComponent,
      EDesc,
      EDescItem,
      uploadComponent
    },
    data () {
      return {
        isFlow: false,
        visible: false,
        id: 0,
        dataForm: {},
        cusRCommProductVOS: [],
        fileList: []
      }
    },
    computed: {
      stepActive () {
        if (!(this.dataForm.workFlowBusinessExt && this.dataForm.workFlowBusinessExt.workFlowProcessStepList)) {
          return 0
        }
        let stepIndex = this.dataForm.workFlowBusinessExt.workFlowProcessStepList.findIndex(item => item.stepId === this.dataForm.workFlowBusinessExt.currentStepId)
        return stepIndex !== -1 ? stepIndex : 0
      }
    },
    methods: {
      onChose () {
        this.$emit('onChose')
      },
      async init (id, businessType) {
        this.isFlow = !!(businessType && businessType !== '')
        this.visible = true
        this.id = id || 0
        if (!id) return
        await getExpenseDetail(this.id).then(({data}) => {
          if (data && data.code === '200') {
            this.dataForm = data.data
            // 文件列表
            this.fileList = []
            if (data.data.attachList) {
              data.data.attachList.forEach((item) => {
                this.fileList.push({
                  name: item.fileName,
                  url: item.url,
                  id: item.url
                })
              })
            }
            // 初始化审批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>
