<template>
  <div>
    <template>
      <component :is="fromName" :id="id"></component>
    </template>
    <template v-for="(fromReData,i) in forms.data">
      <el-divider content-position="left">{{fromReData.taskName}}</el-divider>
      <el-card class="box-card">
        <ele-form
          :isShowSubmitBtn=false
          :isShowBackBtn=false
          :isShowResetBtn=false
          :rules="fromReData.formObj.rules"
          :form-desc="fromReData.formObj.formDesc"
          v-model="fromReData.formObj.formData"
        >
        </ele-form>
      </el-card>
      <br/>
      <el-card class="box-card">
        <template>
          <el-tag>处理人&nbsp;:&nbsp;{{fromReData.createUser}}</el-tag>
          <br/>
          <br/>
          <el-tag>处理部门&nbsp;:&nbsp;{{fromReData.createDept}}</el-tag>
          <br/>
          <br/>
          <el-tag>处理时间&nbsp;:&nbsp;{{fromReData.createTime}}</el-tag>
        </template>
      </el-card>
      <br/>
      <br/>
    </template>
  </div>
</template>
<script>
  import { showForms } from '@/api/activiti/formsActiviti.js'

  import { getHis } from '@/api/assets/his.js'

  //入库表单
  import inputForm from '@/views/activiti/formsActiviti/inputForm.vue'

  import outForm from '@/views/activiti/formsActiviti/outForm.vue'

  import scrapForm from '@/views/activiti/formsActiviti/scrapForm.vue'

  import allotForm from '@/views/activiti/formsActiviti/allotForm.vue'

  export default {
    components: {
      inputForm,
      outForm,
      scrapForm,
      allotForm,
    },
    props: {
      instanceId: String
    },
    data: function() {
      return {
        currentView: undefined,
        id:undefined,
        forms: {
          data: []
        },
        fromName: undefined
      }
    },
    // 初始化方法
    created() {
    },
    methods: {

      showHiForms(instanceId) {
        showForms(instanceId).then(response => {
          if (response.code === 200) {
            let list = response.data
            //进行数据处理
            for (var i = 0; i < list.length; i++) {
              //将json字符串转化为对象
              list[i].formObj = JSON.parse(list[i].formObj)
              let mapElement = list[i].formObj.formDesc
              for (var key in mapElement) {
                let type = mapElement[key].type
                mapElement[key].disabled = true
                // if ('upload-file' === type) {
                //   let canDelete = mapElement[key].attrs.isCanDelete
                //   if (canDelete !== undefined) {
                //     mapElement[key].attrs.isCanDelete = true
                //   }
                //   let disabled = mapElement[key].attrs.disabled
                //   if (disabled !== undefined) {
                //     mapElement[key].attrs.disabled = false
                //   }
                // }
              }
            }
            this.forms.data = list
            this.forms.open = true
            this.forms.title = '查看审核流程'
          } else {
            this.msgError(response.msg)
          }
        })
      },
      showForms(instanceId) {
        getHis(instanceId).then(response => {
          let data = response.data
          let tableName = data.tableName
          console.log(data)
          if (response.code === 200) {
            switch (tableName) {
              case 'db_assets_stock_in':
                this.fromName = 'inputForm'
                this.id = data.tableId;
                this.showHiForms(instanceId)
                break
              case 'db_assets_stock_out':
                this.fromName = 'outForm'
                this.id = data.tableId;
                this.showHiForms(instanceId)
                break
              case 'db_assets_stock_scrap':
                this.fromName = 'scrapForm'
                this.id = data.tableId;
                this.showHiForms(instanceId)
                break
              case 'db_assets_stock_allot':
                this.fromName = 'allotForm'
                this.id = data.tableId;
                this.showHiForms(instanceId)
                break
              default:
                restatus = '其他状态'
            }
          } else {
            this.msgError(response.msg)
          }
        })
      }
    }
  }
</script>

<style scoped>
  .el-upload-list--picture-card .el-upload-list__item-actions span + span {
    margin-left: 0;
  }

  .el-upload-list__item-actions .el-icon-delete {
    display: none;
    width: 0;
    height: 0
  }

  .ele-upload-file-uploader {
    display: none;
  }

  .ele-upload-list__item-content-action .el-link.el-link--danger .el-link--inner {
    display: none;
  }

  .el-input.is-disabled .el-input__inner {
    color: #333;
  }
</style>
