<template>
  <div class='app-container'>
    <el-form :model="form" ref="form" :rules="rules" label-width="100px">
      <el-form-item label="用户Id：">
        <span>{{ form.uid }}</span>
      </el-form-item>
      <el-form-item label="手机号：">
        <span>{{ form.phone }}</span>
      </el-form-item>
      <el-form-item label="图片：">
        <el-image v-for="item in form.url" :key="item" :src="item" :preview-src-list="form.url">
          <span slot="error" />
        </el-image>
      </el-form-item>
      <el-form-item label="反馈类型：">
        <span>{{ form.type }}</span>
      </el-form-item>
      <el-form-item label="反馈内容：">
        <span>{{ form.content }}</span>
      </el-form-item>
      <el-form-item v-if="reply" label="回复：" prop="reply" style="width: 500px;">
        <el-input v-model="form.reply" type="textarea" :readonly="disabled" :autosize="{ minRows: 5, maxRows: 20 }"
          placeholder="请输入回复" />
      </el-form-item>
    </el-form>
    <div class="form-btn">
      <el-button @click="close">取消</el-button>
      <el-button v-if="!disabled" type="primary" @click="getSubmit">确定</el-button>
    </div>
  </div>
</template>

<script>
import { detail, submit } from '@/api/operation/feedbacklist'
export default {
  data() {
    return {
      // 表单
      form: {
        id: this.$route.query.id
      },
      // 校验
      rules: {
        reply: [{
          required: true, message: '请输入回复', trigger: 'blur'
        }]
      },
      // 只读
      disabled: this.$route.query.boolean ? Boolean(this.$route.query.boolean) : false
    }
  },
  computed: {
    reply() {
      return this.disabled ? this.form.reply ? true : false : true
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    // 详情
    getDetail() {
      detail(this.form.id).then(res => {
        if (res.code === 0) {
          this.form = res.data
          this.form.url = res.data.url.split(',')
        }
      })
    },

    // 取消
    close() {
      this.$tab.closeOpenPage("/operation/feedback/feedbacklist");
    },

    // 提交
    getSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          submit(this.form).then(res => {
            if (res.code === 0) {
              this.$message.success('提交成功！')
              this.close()
            }
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.el-image {
  width: 200px;
  margin-right: 10px;
}
</style>