<template>
  <div class="app-container">
    <div v-show="viewState== 1">
      <!--标题按钮部分开始-->
      <div class="tab-header webtop">
        <!--标题-->
        <div>{{ viewTitle }}</div>
        <!--start 添加修改按钮-->
        <div>
          <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
        </div>
      </div>
      <!--标题按钮部分结束-->
      <!--Start 新增修改部分-->
      <div class="listconadd">
        <el-form ref="form_obj" :model="formobj" :rules="rules" class="formaddcopy02">
          <el-row style="border-left: 0px !important;">
            <el-col :span="12" style="border-right: 0px !important;">
              <div class="span-sty spanOneWidth" style="border-right: 0px !important;"><span>车架号:</span></div>
              <el-form-item><span>{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
            <el-col :span="12" style="border-right: 0px !important;">
              <div class="span-sty spanOneWidth" style="border-right: 0px !important;"><span>车型:</span></div>
              <el-form-item>{{ formobj.modelName }}</el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty spanOneWidth"><span>巡检情况说明:</span></div>
              <el-form-item><span>{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty spanOneWidth"><span>存在问题及处理结果:</span></div>
              <el-form-item><span>{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty spanOneWidth"><span>相关责任人:</span></div>
              <el-form-item><span>{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="span-sty spanOneWidth"><span>相关照片:</span></div>
              <el-form-item><span>{{ formobj.vinNo }}</span></el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import req from '@/api/weishoumaiduan/unsold'
import { typeValues } from '@/api/cheliang/dictcommons'

export default {
  name: 'cheliangxunjiancaozuo',
  data() {
    return {
      viewTitle: '车辆巡检操作',
      listLoading: false,
      viewState: 1,
      index: 0,
      tableKey: 0,
      list: [],
      warehouse_list: [],
      staff_list: [],
      // 表单数据
      formobj: {
        sid: '', // 一条数据的sid
        applicationName: window.sessionStorage.getItem('name'),
        createTime: '',
        reason: '',
        userSid: window.sessionStorage.getItem('userSid'),
        detailsList: []
      },
      rules: {},
      submitdisabled: false
    }
  },
  methods: {
    init() {
      typeValues({ type: 'warehouse' }).then((res) => {
        if (res.success) {
          this.warehouse_list = res.data
        }
      })
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    showEdit(row) {
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      console.log('编辑回显', row.sid)
      req.fetchBySid(row.sid).then((resp) => {
        const data = resp.data
        this.formobj.applicationName = data.applicationName
        this.formobj.sid = data.sid
        this.formobj.reason = data.reason
        this.formobj.createTime = data.createTime
        this.formobj.detailsList = data.voList
      }).catch((e) => {
        this.formobj = row
      })
    },
    save() {
      this.$refs['form_obj'].validate((valid) => {
        if (valid) {
          this.submitdisabled = true
          req.saveOrUpdate(this.formobj).then((resp) => {
            this.submitdisabled = false
            if (resp.success) {
              this.$message({
                showClose: true,
                type: 'success',
                message: resp.msg
              })
              this.handleReturn('true')
            }
          }).catch(() => {
            this.submitdisabled = false
          })
        } else {
          return false
        }
      })
    },
    // 返回（===既判断）
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      // 表单数据
      this.formobj = {
        sid: '', // 一条数据的sid
        applicationName: window.sessionStorage.getItem('name'),
        createTime: '',
        reason: '',
        userSid: window.sessionStorage.getItem('userSid'),
        detailsList: []
      }
      this.$refs['form_obj'].resetFields()
      this.$refs['divVehicle'].getList()
      this.$emit('doback')
    },
    closePage() {
      this.viewState = 1
    }
  }
}
</script>

<style scoped>
.spanOneWidth {
  width: 180px !important;
}
</style>

