<template>
  <div>
    <!-- 执行顺序 -->
    <Alert class="equip_alert">
      <div>
        <table class="tableClass">
          <tbody>
            <tr>
              <th colspan="4" style="text-align: center;font-size: 15px">
                人员培训计划
              </th>
            </tr>
            <tr>
              <th>状态</th>
              <td>{{obj.status}}</td>
              <th>培训名称</th>
              <td>{{obj.name}}</td>
            </tr>
            <tr>
              <th>培训类型</th>
              <td>{{obj.type}}</td>
              <th>负责人</th>
              <td>{{obj.chargerName}}</td>
            </tr>
            <tr>
              <th>培训人员</th>
              <td>{{obj.staffNames}}</td>
              <th>培训日期</th>
              <td>{{$dateformat(obj.trainDate,'yyyy-mm-dd')}}</td>
            </tr>
            <tr>
              <th>培训内容</th>
              <td>{{obj.trainContent}}</td>
              <th>培训目标</th>
              <td>{{obj.trainAim}}</td>
            </tr>
            <tr>
              <th>考核办法</th>
              <td>{{obj.assessmentMethod}}</td>
              <th>备注</th>
              <td>{{obj.remark}}</td>
            </tr>
            <tr>
              <th>编制人</th>
              <td>{{obj.userName}}</td>
              <th>编制时间</th>
              <td>{{$dateformat(obj.compacteDate,'yyyy-mm-dd')}}</td>
            </tr>
            <tr>
              <th>审批人</th>
              <td>{{obj.approver}}</td>
              <th>审批时间</th>
              <td>{{$dateformat(obj.approvDate,'yyyy-mm-dd')}}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <Form inline :label-width="80">
        <FormItem label="审批意见：" style="width:70%;margin-top: 10px">
          <Input name="reason" placeholder="请输入审批意见..." size="large" value="同意" />
        </FormItem>
        <div align="left" style="margin-top: 12px;display: inline-block;">
          <Button type="success" style="margin-left: 15px" @click="_approve('pass','确定通过？')">
            同意
          </Button>
          <Button style="margin-left: 15px" type="error" @click="_approve('back','确定驳回？')">
            驳回
          </Button>
        </div>
      </Form>
    </Alert>
  </div>
</template>
<script>
import global from '../../../api/config'
import { staffTrainPlan } from '../../../api'
export default {
  components: {},
  data() {
    return {
      obj: {},
      id: {},
      showModal: false
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this._staffTrainCheck()
  },
  methods: {
    _staffTrainCheck: async function() {
      this.obj = await staffTrainPlan.getById(this.id)
      this.obj.status = this.obj.status
    },
    _approve(status, content) {
      this.$Modal.confirm({
        title: '提示',
        content: content,
        onOk: () => {
          const data = {}
          data.taskId = $('#flowFrame', parent.document).attr('data-tid')
          data.status = status
          data.reason = $('input[name="reason"]').val()
          this._approveOk(data)
        }
      })
    },
    _approveOk: async function(data) {
      const result = await staffTrainPlan.approve(data)
      if (result) {
        this.$Message.success('审批成功！')
        setTimeout(() => {
          parent.location.replace(global.webURL + '/sys/workflow/flow_task')
        }, 200)
      }
    },
    _cancel() {
      this.showModal = false
    }
  }
}
</script>
