<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>
      <span class="button-separator"></span>
      <el-button type="button" class="el-button el-button--default save" :loading="confirmLoading" @click="confirmClickHandler" priv="SocialMedia.FansManage.Lable"><span><i class="fa fa-save"></i>保存</span></el-button>
    </el-toolbar>
    <div class="detail-panel">
      <div class="panel-header">
        <div class="title">设置备注</div>
      </div>
      <el-form :model="tmpFans" :rules="fansRules" ref="fansRemarkForm" label-width="100px">
        <el-form-item label="粉丝备注：" prop="remark">
          <el-input v-model="tmpFans.remark"></el-input>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import util from '@src/common/util.js'
export default {
  props: {
    openID: {
      type: [String, Number]
    }
  },
  data() {
    return {
      confirmLoading: false,
      // 验证规则
      fansRules: {
        remark: [
          { required: true, message: '请输入粉丝备注', trigger: 'blur,change' },
          {
            pattern: /^([\u4E00-\u9FA50-9a-zA-Z]*)$/,
            message: '只能输入汉字、字母或数字',
            trigger: 'blur,change'
          }
        ]
      },
      tmpFans: {
        remark: this.$route.query.remark,
        aid: this.$route.query.accountID
      }
    }
  },
  created() {
    this.$parent.activeMenu = '粉丝管理'
  },
  methods: {
    async confirmClickHandler() {
      try {
        this.confirmLoading = true
        await util.validateForm(this.$refs['fansRemarkForm'])
        let res = await axios.put(`/ui/fans/${this.openID}/remark`, this.tmpFans)
        this.confirmLoading = false
        util.showResponseMessage(res.data)
      } catch (e) {
        this.confirmLoading = false
        util.showErrorMessageBox(e)
      }
    }
  }
}
</script>
