<template>
  <div>
    <!--1.技术主管审批-->
    <div>
      <!-- 执行顺序 -->
      <Alert class="equip_alert">
        <div>
          <table class="tableClass table1Class">
            <tbody>
              <tr>
                <th colspan="4" style="text-align: center;font-size: 15px">
                  仪器预约申请单
                </th>
              </tr>
              <tr>
                <th>设备名称</th>
                <td>{{ getObj.name }}</td>
                <th>预约使用地点</th>
                <td>{{ getObj.orderLocationName }}</td>
              </tr>
              <tr>
                <th>预约开始时间</th>
                <td>{{ this.$dateformat(getObj.orderStartTime, "yyyy-mm-dd HH:MM") }}</td>
                <th>预约结束时间</th>
                <td>{{ this.$dateformat(getObj.orderEndTime, "yyyy-mm-dd HH:MM") }}</td>
              </tr>
              <tr>
                <th>申请原因</th>
                <td>{{ getObj.applyReason }}</td>
                <th>申请人</th>
                <td>{{ getObj.applyName }}</td>
              </tr>
              <tr>
                <th>申请时间</th>
                <td>{{ this.$dateformat(getObj.applyTime, "yyyy-mm-dd HH:MM") }}</td>
                <th>备注</th>
                <td>{{ getObj.remark }}</td>
              </tr>
            </tbody>
          </table>
        </div>
        <Form inline>
          <Form-item label="技术主管意见" prop="firstStepAdvice" style="width: 98.6%;">
            <Input name="firstStepAdvice" type="textarea" :rows="2" />
          </Form-item>
        </Form>
      </Alert>
    </div>
    <!--操作-->
    <div align="center" style="margin-top:350px">
      <Button type="error" @click="_approve(false)">
        驳回
      </Button>
      <Button type="success" @click="_approve(true)">
        同意
      </Button>
    </div>
  </div>
</template>
<script>
import global from '../../../../api/config'
import { equipOrder } from '../../../../api'
export default {
  data() {
    return {
      id: {},
      getObj: {}
    }
  },
  mounted() {
    this.id = this.$route.query.id
    this._order()
  },
  methods: {
    _order: async function() {
      this.getObj = await equipOrder.getById(this.id)
    },
    _approve(allow) {
      this.$Modal.confirm({
        title: '提示',
        content: allow ? '确定通过？' : '确定驳回？',
        onOk: () => {
          const data = {}
          data.id = $('#flowFrame', parent.document).attr('data-tid')
          data.status = allow ? '2' : '3' // 2技术主管审批，3申购驳回
          data.reason = $('textarea[name="firstStepAdvice"]').val()
          this._approveOk(data)
        }
      })
    },
    _approveOk: async function(data) {
      const result = await equipOrder.approve(data)
      if (result) {
        this.$Message.success('审批成功！')
        setTimeout(() => {
          parent.location.replace(global.webURL + '/sys/workflow/flow_task')
        }, 200)
      }
    }
  }
}
</script>
