<template>
  <div>
    <el-form :model="formData" label-position="right" label-width="80px">
      <el-form-item label="发布人:">
        <el-input v-model.number="formData.oper" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="处理人:">
        <el-input v-model.number="formData.handler" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="关联图片:">
        <el-input v-model="formData.imgs" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="关联视频:">
        <el-input v-model="formData.video" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="站点id:">
        <el-input v-model.number="formData.siteId" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="经纬度:">
        <el-input v-model="formData.position" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="问题列表:">
        <el-input v-model="formData.matter" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="站点类型:">
        <el-input v-model="formData.siteType" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="处理状态:">
        <el-input v-model="formData.status" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="处理图片:">
        <el-input v-model="formData.handImgs" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="处理内容:">
        <el-input v-model="formData.handText" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item label="责任部门:">
        <el-input v-model="formData.department" clearable placeholder="请输入" />
      </el-form-item>
      <el-form-item>
        <el-button size="mini" type="primary" @click="save">保存</el-button>
        <el-button size="mini" type="primary" @click="back">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  createProblemInfo,
  updateProblemInfo,
  findProblemInfo
} from '@/api/problemInfo' //  此处请自行替换地址
import infoList from '@/mixins/infoList'
export default {
  name: 'ProblemInfo',
  mixins: [infoList],
  data() {
    return {
      type: '',
      formData: {
        oper: 0,
        handler: 0,
        imgs: '',
        video: '',
        siteId: 0,
        position: '',
        matter: '',
        siteType: '',
        status: '',
        handImgs: '',
        handText: '',
        department: '',
      }
    }
  },
  async created() {
    // 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
    if (this.$route.query.id) {
      const res = await findProblemInfo({ ID: this.$route.query.id })
      if (res.code === 0) {
        this.formData = res.data.reproblemInfo
        this.type = 'update'
      }
    } else {
      this.type = 'create'
    }
  },
  methods: {
    async save() {
      let res
      switch (this.type) {
        case 'create':
          res = await createProblemInfo(this.formData)
          break
        case 'update':
          res = await updateProblemInfo(this.formData)
          break
        default:
          res = await createProblemInfo(this.formData)
          break
      }
      if (res.code === 0) {
        this.$message({
          type: 'success',
          message: '创建/更改成功'
        })
      }
    },
    back() {
      this.$router.go(-1)
    }
  }
}
</script>

<style>
</style>
