<!--
 * @Author: wanglj 471442253@qq.com
 * @Date: 2022-12-29 18:00:08
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-06-08 10:17:38
 * @Description: file content
 * @FilePath: \订单全流程管理系统\src\views\base\components\PostComments.vue
-->
<template>
  <el-dialog :title="reply ? '回复' : '发表评论'" :visible.sync="visible">
    <el-form ref="editForm" :model="editForm" :rules="editRules">
      <el-form-item :label="reply ? '回复' : '评论'" prop="content">
        <el-input
          v-model="editForm.content"
          maxlength="500"
          :placeholder="reply ? '请输入回复内容' : '请输入评论内容'"
          resize="none"
          :rows="5"
          show-word-limit
          type="textarea" />
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button :loading="loading" type="primary" @click="postContent">提交</el-button>
      <el-button @click="handleClose">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import api from '@/api/customer/follow'
  import to from 'await-to-js'
  export default {
    data() {
      return {
        loading: false,
        visible: false,
        reply: false,
        editForm: {
          content: '',
        },
        form: {},
        editRules: {
          content: [{ required: true, trigger: 'blur', message: '请输入评论内容' }],
        },
      }
    },
    created() {
      // console.log(this.visible)
      // console.log(this.editForm)
      // console.log(this.editRules)
      console.log(this.form)
      console.log('reply', this.reply)
    },
    methods: {
      async postContent() {
        this.$refs['editForm'].validate(async (valid) => {
          if (valid) {
            this.loading = true
            let params = {
              followId: this.reply ? '' + this.form.followId : '' + this.form.id,
              content: this.editForm.content,
              pid: this.reply ? this.form.id : 0,
            }
            const post = this.reply ? api.addReply : api.addComment
            const [err, res] = await to(post({ ...params }))
            this.loading = false
            if (err) return
            if (res.code == 200) {
              this.$baseMessage('发表成功', 'success', 'vab-hey-message-success')
              this.visible = false
              this.handleSub()
            }
          }
        })
      },
      handleSub() {},
      handleClose() {
        this.visible = false
      },
    },
  }
</script>

<style></style>
