<template>
  <div class="layout-no-flex">
    <el-toolbar>
      <el-button @click="$router.back()" type="primary" size="medium" round class="shadow-primary"><i class="fa fa-chevron-left"></i> 返回上页</el-button>
    </el-toolbar>
    <el-row>
      <span >
        <el-form :model="formdata" :rules="formRules" ref="form">
         <el-form-item prop="replyContent">
            <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 4}" v-model="formdata.replyContent"></el-input>
         </el-form-item>
        </el-form>
        <div style="float:right">
          <el-button @click="sendMessage" type="primary" size="small" round class="shadow-primary" :loading="confirmLoading">发送</el-button>
        </div>
      </span>
     </el-row>
    <div class="padding-top-bottom">
      <el-list-view ref="messageList" :data-read-url="getMessageListURL" :pageSize="10" >
        <template slot-scope="item">
          <div class="panel-card">
            <div class="card-header">
              <el-row>
                <el-col :span="6">
                  <span><img src="${item.headImgUrl}">{{item.remark?item.remark+'（'+item.nickName+'）':item.nickName}}</span>
                </el-col>
                <el-col :span="6">
                  <span><i class="fa fa-clock-o"></i>{{item.addTime | fixDateTime}}</span>
                </el-col>
              </el-row>
            </div>
            <div class="card-content">
              <el-row class="gray f12">消息内容：</el-row>
              <el-row><span class="black">{{item.msgContent}}</span></el-row>
            </div>
          </div>
        </template>
      </el-list-view>
    </div>
  </div>
</template>

<script>
import util from '@src/common/util.js'
export default {
  filters: {
    fixDateTime: function(val) {
      return val ? util.formatDate(val, 'yyyy-MM-dd HH:mm') : '　'
    }
  },
  props: {
    openID: {
      type: [String, Number]
    }
  },
  data() {
    return {
      confirmLoading: false,
      accountID: this.$route.query.accountID,
      formdata: {
        replyContent: ''
      },
      formRules: {
        replyContent: [
          { required: true, message: '不能为空', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.$parent.activeMenu = '粉丝管理'
    this.formdata.accountID = this.accountID
    this.formdata.openID = this.openID
  },
  methods: {
    async sendMessage() {
      try {
        this.confirmLoading = true
        await util.validateForm(this.$refs['form'])
        let res = await axios.post('/ui/fansmessages', this.formdata)
        this.confirmLoading = false
        util.showResponseMessage(res.data)
      } catch (e) {
        this.confirmLoading = false
        util.showErrorMessageBox(e)
      }
    },
    getMessageListURL() {
      return ['/ui/fansmessages', {params: {openID: this.openID}}]
    }
  }
}
</script>
