<template>
  <div class="auto" id="orderApplyDispose">
    <validator name='v'>
      <form novalidate class="form-horizontal select-overspread">
        <ul class="nav nav-tabs">
          <li class="active"><a href="#">{{title}}</a></li>
        </ul>
        <div class="auto">
          <partial-view v-ref:pv>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">用户编号:</label>
              <span class="col-sm-9">{{ row.f_userinfo_code }}</span>
            </div>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">用户姓名:</label>
              <span class="col-sm-9">{{ row.f_user_name }}</span>
            </div>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">用户类型:</label>
              <span class="col-sm-9">{{ row.f_user_type }}</span>
            </div>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">用户地址:</label>
              <span class="col-sm-9">{{ row.f_user_address }}</span>
            </div>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">隐患照片:</label>
              <img-self :src="defect.f_path" v-if="defect.f_path" :width="100" :height="100"></img-self>
              <img-self :src="defect.f_p1_path" v-if="defect.f_p1_path" :width="100" :height="100"></img-self>
              <img-self :src="defect.f_p2_path" v-if="defect.f_p2_path" :width="100" :height="100"></img-self>
              <img-self :src="defect.f_p3_path" v-if="defect.f_p3_path" :width="100" :height="100"></img-self>
            </div>
            <div class="row text-left" style="padding-bottom: 10px">
              <label class="col-sm-3 control-label">整改备注:</label>
              <span class="col-sm-9">{{ row.f_orderremark }}</span>
            </div>
            <div class="row text-left" style="padding-bottom: 10px;display: flex">
              <label class="col-sm-3 control-label">整改照片:</label>
              <img-self :src="row.f_repaire_path" v-if="row.f_repaire_path" :width="100" :height="100"></img-self>
              <img-self :src="row.f_repaire_path1" v-if="row.f_repaire_path1" :width="100" :height="100" style="margin-left: 10px"></img-self>
            </div>
          </partial-view>
        </div>


        <div class="form-group">
          <div class="col-sm-12" style="margin-top: 10px">
            <p>处理意见：</p>
            <textarea class="form-control" v-model="f_suggest" rows="4" :placeholder="处理意见"></textarea>
          </div>
        </div>

        <div style="text-align:right;height:auto;margin-top:10px;margin-right:30px;">
          <span v-if="row.f_orderstate === '预约成功' || row.f_orderstate === '预约失败'">该隐患已审核</span>
          <br>
          <button type="button" :disabled="row.f_orderstate === '预约成功' || row.f_orderstate === '预约失败'" class="btn btn-warning" @click="confirm(row)" style="width:80px;margin-left:20px;">审核失败</button>
          <button type="button" :disabled="row.f_orderstate === '预约成功' || row.f_orderstate === '预约失败'" class="btn btn-primary" @click="confirm1(row)" style="width:80px;margin-left:20px;">审核成功</button>
        </div>
      </form>
    </validator>

  </div>
</template>
<script>
  import {HttpResetClass} from "vue-client";
  import Vue from "vue";

  export default {
    data () {
      return {
        show: false,
        f_operator: this.$login.f.name,
        f_suggest: '',
        placeholder: '',
        defect: {}
      }
    },
    props: {
      row: {
        type: Object
      },
      title: {
        type: String
      },
      userInfo: {
        type: Array
      },
      imgInfo: {
        type: Array
      }
    },
    ready(){
      this.getDefectByUserinfoId(this.row)
    },
    methods: {
      showModal () {
        this.show = true
      },
      close () {
        this.show = false
      },
      confirm (row) {
        if (this.f_suggest === '') {
          Vue.showMessage("请给用户一些处理意见！")
          return;
        }
        // 预约失败处理
        let data = {
          f_suggest: this.f_suggest,
          f_orderstate: '预约失败',
          f_dispose_operator: this.f_operator,
          f_disposedate: this.toStandardTimeString(),
          id: row.id
        }
        this.$resetpost('/rs/logic/amendOrderApply', data, {resolveMsg: '处理成功', rejectMsg: '处理失败!!'}).then((res) => {
          if (res.data.status === 0) {
            this.f_suggest = ''
          }
        })
        this.$parent.completeCheck()
      },
      confirm1 (row) {
        // 预约成功处理
        let data = {
          f_suggest: this.f_suggest,
          f_orderstate: '预约成功',
          f_dispose_operator: this.f_operator,
          f_disposedate: this.toStandardTimeString(),
          //  审核成功后需要修改的安检单的数据
          defect: {
            f_is_repaired: '已处理',
            f_repairman: this.f_operator,
            f_repair_path: row.f_repaire_path,
            f_repair1_path: row.f_repaire_path1 || '',
            f_repair_path_source: '微信',
            f_paper_id: this.defect.check_paper_id,
            f_userinfo_code: row.f_userinfo_code,
            id: row.f_defect_id,
          },
          id: row.id
        }
        this.$resetpost('/rs/logic/amendOrderApply', data, {resolveMsg: '处理成功', rejectMsg: '处理失败!!'}).then((res) => {
          if (res.data.status === 0) {
            this.f_suggest = ''
          }
        })
        this.$parent.completeCheck()
      },
      clear (placeholder) {
        this.placeholder = placeholder
        this.showModal()
      },
      toStandardTimeString () {
        let dt = new Date()
        let month = dt.getMonth() + 1
        let date = dt.getDate()
        let hour = dt.getHours()
        let min = dt.getMinutes()
        let sec = dt.getSeconds()
        return dt.getFullYear() + '-' + (month < 10 ? '0' + month : month) + '-' + (date < 10 ? '0' + date : date) +
          ' ' + (hour < 10 ? '0' + hour : hour) + ':' + (min < 10 ? '0' + min : min) + ':' + (sec < 10 ? '0' + sec : sec)
      },
      async getDefectByUserinfoId(row) {
        const http = new HttpResetClass()
        const res = await http.load('post','/rs/sql/GetDefectByUserinfoId',{data:{condition: `f_userinfo_id = '${row.f_userinfo_id}' and tdi.id = '${row.f_defect_id}'`}})
        this.defect = res.data[0]
        this.defect.f_path = '/rs/image/file/' +  this.defect.f_path
        if (this.defect.f_p1_path) this.defect.f_p1_path = '/rs/image/file/' +  this.defect.f_p1_path
        if (this.defect.f_p2_path) this.defect.f_p2_path = '/rs/image/file/' +  this.defect.f_p2_path
        if (this.defect.f_p3_path) this.defect.f_p3_path = '/rs/image/file/' +  this.defect.f_p3_path
      }
    },
    watch: {
      'row'(val) {
        this.getDefectByUserinfoId(val)
      }
    }
  }
</script>
<style lang="less">
  #orderApplyDispose{
    .modal-header {
      border: none;
      .close {
        position: absolute;
        top: 7px;
        right: 10px;
      }
    }
    .modal-body {
      padding-bottom: 0px;
    }
    .modal-footer {
      padding: 10px 15px;
      border: none;
    }
    .outbox {
      height: 390px;
      overflow-y: auto;
    }
  }
</style>
