<style>
  .weixinappmsg {
    position: relative;
  }

  .weixinappmsg .mimitBody {
    padding: 20px;
    background-color: #fff;
    margin: 10px 0 20px 0;
    display: table;
    width: 100%;
  }

  .weixinappmsg .mimitList {
    margin-bottom: 15px;
    display: flex;
    flex-direction: row;
  }

  .weixinappmsg .mimitBody .el-tag {
    min-width: 120px;
    padding-right: 50px;
  }

  .weixinappmsg .el-button--small {
    padding: 9px 15px;
  }

  .wexin_Header {
    padding: 0 20px;
    height: 56px;
    line-height: 56px;
    background-color: #fff;
    margin-bottom: 10px;
  }

  .weixinTopBtn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
  }

  .weixin_warmTips {
    margin: 0px 20px 20px;
    background-color: rgb(244, 244, 245);
    padding: 10px 15px;
    color: rgb(144, 147, 153);
    display: inline-block;
    font-size: 15px;
  }

</style>
<template>
  <div class="weixinappmsg">
    <el-button class="weixinTopBtn" type="primary" size="small" @click="getWeChatMessageTemplate">一键添加订阅信息</el-button>
    <div class="wexin_Header">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="微信小程序" name="1"></el-tab-pane>
      </el-tabs>
    </div>
    <template v-if="checkIndex==1">
      <div class="mimitBody">
        <div class="el-col el-col-24">
          <div class="weixin_warmTips">温馨提示：获取前请先确认您已获得订阅消息的使用权限，并且订阅消息中没有任何数据。获取后请不要到小程序后台 删除相应的订阅消息，否则会影响订阅消息正常使用。
          </div>
          <el-form label-width="300px">
            <el-form-item label="拼团成功通知(类目: 服装/鞋/箱包 )">
              <el-input type="text" style="width:30%" size="small" maxlength="200"
                v-model="wechatMsg.WeChat_pintuan_success_notice">
              </el-input>
              <el-button plain size="small">查看订阅消息示例</el-button>
            </el-form-item>
            <el-form-item label="拼团失败通知(类目: 服装/鞋/箱包 )">
              <el-input type="text" style="width:30%" size="small" maxlength="200"
                v-model="wechatMsg.WeChat_pintuan_fail_notice">
              </el-input>
              <el-button plain size="small">查看订阅消息示例</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <el-button size="small" type="primary" @click="saveMsg()">保 存</el-button>
      <el-button size="small" type="primary">生成测试二维码</el-button>
    </template>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        //商城订阅消息
        activeName: '1',
        checkIndex: 1,
        wechatMsg: {
          GroupByConfigId: 0,
          WeChat_pintuan_success_notice: '',
          WeChat_pintuan_fail_notice: ''
        },
      };
    },
    created() {

    },
    methods: {
      //切换
      handleClick(tab) {
        this.checkIndex = tab.name;
      },
      getWeChatMessageTemplate() {
        this.apipost("/api/Mall/GetMessageTemplate", {}, res => {
          if (res.data.resultCode == 1) {
            var dataArray = res.data.data;
            if (dataArray && dataArray.length > 0) {
              dataArray.forEach(item => {
                if (item.Tid == "1953") {
                  //拼团失败模板
                  this.wechatMsg.WeChat_pintuan_fail_notice = item.MessageTemplateId;
                } else if (item.Tid == "980") {
                  //拼团成功模板
                  this.wechatMsg.WeChat_pintuan_success_notice = item.MessageTemplateId;
                }
              });
            }
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //保存信息
      saveMsg() {
        this.apipost("/api/GroupBuy/SetGroupBuyConfigMessage", this.wechatMsg, res => {
          if (res.data.resultCode == 1) {
            this.getGroupBuyConfig();
            this.Success(res.data.message);
          } else {
            this.Info(res.data.message);
          }
        })
      },
      //获取拼团配置
      getGroupBuyConfig() {
        this.apipost("/api/GroupBuy/GetGroupBuyConfig", {}, res => {
          if (res.data.resultCode == 1) {
            var dataObj = res.data.data;
            if (dataObj) {
              this.wechatMsg.WeChat_pintuan_success_notice = dataObj.WeChat_pintuan_success_notice;
              this.wechatMsg.WeChat_pintuan_fail_notice = dataObj.WeChat_pintuan_fail_notice;
            }
          } else {
            this.Info(res.data.message);
          }
        })
      }
    },
    mounted() {
      this.getGroupBuyConfig();
    }
  };

</script>
