<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container" id="winxin-subscribe-replu-box">
      <reply-nav activeName="subscribe"></reply-nav>
      <el-form ref="form" :model="form" >
        <el-form-item label="">
          <el-input type="textarea" v-model="form.message_content" rows='5'></el-input>
        </el-form-item>
        <el-form-item>
          <!-- <el-col :span="24" style="text-align: right;"> -->
            <el-button type="primary" align="right" @click="saveReply">保存</el-button>
          <!-- </el-col> -->
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import BreadCrumb from "../components/bread-crumb";
import replyNav from "./components/replyNav";
import {GetAuthorizationInfo} from "@/api/mpwechat/mpwechat";
import {GetSubscribeRplay,SaveSubscribeRplay} from "@/api/mpwechat/mpreply";

export default {
  name: "subscribereply",
  components: {
    BreadCrumb,
    replyNav,
  },
  data() {
    return {
      crumbs: [
        { path: false, name: "系统设置" },
        { path: false, name: "关注后回复" }
      ],
      initReply:false,
      form:{
        'message_content':'',
      },
    };
  },
  methods: {
    GetAuthorizationInfo:function(){
      GetAuthorizationInfo().then(response=>{
        var res =  response.data;
        if(res.state===1) {
          if(res.data.authorization) {
            this.authData = res.data.authorization;
            if (this.authData.authorizer_status != 1) {
              this.$message.error("公众号未授权");
              this.$router.push({path:"/weixinmp/authorization"})
              return false;
            }else if (this.authData.authorizer_verify_type_info>=0 || this.authData.authorizer_service_type_info==2) {
              this.initReply = true;
            }
          }else {
              this.$message.error("公众号未授权");
              this.$router.push({path:"/weixinmp/authorization"})
          }
        }else {
          this.$message.error(res.msg);
        }
      }).catch(e=>{});
    },
    GetSubscribeRplay:function(){
      GetSubscribeRplay().then(response=>{
        var res = response.data;
        if (res.state==1) {
          if (res.data.message) {
            this.form.message_content = res.data.message.message_content;
          }
        }else {
          this.$message.error(res.msg);
        }
      }).catch(e=>{});
    },
    saveReply:function(){
      SaveSubscribeRplay(this.form).then(response=>{
        var res = response.data;
        if (res.state === 1) {
          this.$message.success('保存成功');
        }else {
          this.$message.error(res.msg);
        }
      }).catch(e=>{});
    }
  },
  created() {
    this.GetAuthorizationInfo();
  },
  computed:{
  },
  watch:{
    'initReply':function(){
      this.GetSubscribeRplay();
    }
  },
};
</script>

<style scoped>
/*.app-container .cell.clearfix .time ul li {*/
/*float: left;*/
/*list-style: none;*/
/*cursor: pointer;*/
/*padding: 6px 20px;*/
/*color: #606266;*/
/*border-radius: 4px;*/
/*margin: 0 8px 0 0;*/
/*font-size: 14px;*/
/*text-align: center;*/
/*}*/
</style>