<template>
  <div>
    <div style="padding: 10px 0px 66px 0px;min-height: 100px">
      <!--标题-->
      <h4 style="text-align:center">{{title}}</h4>
      <el-card>
        <!--详情页面-->
        <component ref="form" :businessId="businessId" :is="form" :processDefKey="processDefKey"></component>
        <!--操作按钮-->
        <div class="FlowFormFooter">
          <el-button v-if="type === 'audit'" type="primary" :loading="loading" @click="agree" v-noMoreClick plain>同意</el-button>
          <el-button v-if="type === 'audit'" type="danger" :loading="loading" @click="reject" v-noMoreClick plain>驳回</el-button>
          <el-button :loading="loading" @click="close" v-noMoreClick plain>关闭</el-button>
        </div>
      </el-card>
    </div>

  </div>
</template>

<script>
  import FlowService from '@/api/centerservice/ccpm/CcpmService'
  export default {
    flowService: null,
    created () {
      this.flowService = new FlowService()
    },
    activated () {
      this.init()
    },
    components: {
    },
    watch: {
    },
    methods: {
      init () {
		  this.businessId = this.$route.query.id
		  this.processDefKey = this.$route.query.processDefKey
		  this.title = this.$route.query.title
		  this.type = this.$route.query.type
		  this.jsonData = []
		  this.comments = ''
		  this.$nextTick(async () => {
			  this.loading = true
			  this.$refs.upLoadComponent.clearUpload()
			  this.$refs.flowHisTableCcpm.clearFlowHis()
			  await this.ccpmService.getByIdGenerate(this.businessId, this.processDefKey).then((data)=>{
				  if (data) {
					  console.log('data',data)
					  this.loading = false
					  this.jsonData = JSON.parse(JSON.stringify(data))
					  if (this.commonJS.isEmpty(this.jsonData.files)) {
						  this.jsonData.files = []
					  }
					  let filesLabel = '附件'
					  if (this.commonJS.isNotEmpty(this.jsonData.filesLabel)) {
						  filesLabel = this.jsonData.filesLabel
					  }
					  this.$refs.upLoadComponent.newUpload('view', this.jsonData.files, null, null, filesLabel)
					  this.$refs.flowHisTableCcpm.setFlowHis(this.jsonData.flowChart, this.jsonData.histoicFlow)
					  this.$nextTick(() => {
						  this.$refs.generateForm.refresh()
					  })
				  } else {
					  this.loading = false
				  }
			  })

		  })
      },
      // 关闭
      close () {
		  this.$refs.upLoadComponent.clearUpload()
		  this.$refs.flowHisTableCcpm.clearFlowHis()
		  this.jsonData = []
		  this.comments = ''
		  this.$store.dispatch('tagsView/delView', {fullPath: this.$route.fullPath})
		  if (this.$route.query.backPath) {
			  this.$router.push(this.$route.query.backPath)
		  } else {
			  this.$router.push('/dashboard/index')
		  }
      },
      agree () {
        this.$refs.form.agree(this.$route.query.backPath)
      },
      reject () {
        this.$refs.form.reject(this.$route.query.backPath)
      },
      reapply () {
        this.$refs.form.reapply()
      },
      deleteFlow () {
        this.$refs.form.deleteFlow()
      },
      changeLoading (loading) {
        if (this.commonJS.isNotEmpty(loading)) {
          this.loading = loading
        } else {
          this.loading = false
        }
      }
    },
    data () {
      return {
        title: '',
        form: '',
        businessId: '',
        loading: false,
        type: ''
      }
    }
  }
</script>
