<template>
  <div class="daily-set-wrap ">
    <div class="daily-set-content border-box">
      <div class="admin-tip-body">
        <div role="alert" class="el-alert el-alert--info">
          <i class="el-alert__icon el-icon-info"></i>
          <div class="el-alert__content">
            <p class="el-alert__title">
              1. 因企业微信接口限制，若在企微管理端为相关人员配置欢迎语，好办设置欢迎语不会生效；<br />
              2. 若使用好办欢迎语，请关闭其他企业自建应用/第三方应用的欢迎语配置； <br />
              3. 欢迎语的业务场景是为了支持在代理商主体下的外部联系人与总部的会员能互联，暂不支持其他需求场景
            </p>
          </div>
        </div>
      </div>
      <div class="salutatory-wrap m-t-20">
        <div class="top">
          <p class="left">欢迎语标题 {{ form.title || '系统默认' }}</p>
          <p class="right">
            <span class="date">最近编辑时间：{{ form.updateTime | formatTimeStamp }}</span>
            <el-button type="text" style="margin-right:43px;" @click="changeRoute">编辑</el-button>
            <el-switch v-model="openFlag" :active-value="1" :inactive-value="0" @change="setWelcome"> </el-switch>
          </p>
        </div>
        <p class="line"></p>
        <div class="bottom">
          <el-form label-width="70px" ref="form" :model="form">
            <el-form-item label="文本内容">
              <p class="welcome-text">{{ form.welcomeContent || '你好，&lt; 微信昵称 &gt;' }}</p>
            </el-form-item>
            <!-- <el-form-item label="附件"></el-form-item> -->
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getRequest } from '@/api/api';
// import { _debounce } from '@/common/js/public';
// import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
export default {
  props: {},
  data() {
    return {
      form: {},
      openFlag: 0
    };
  },
  filters: {},
  methods: {
    /**
     * 跳转
     */
    changeRoute() {
      this.$router.push('/salutatorySet');
    },

    /**
     * 获取数据
     */
    getData() {
      const that = this;
      getRequest('/haoban-manage3-web/get-welcome', {})
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1 && resData.result) {
            that.form = { ...resData.result };
            that.openFlag = resData.result.openFlag;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    setWelcome(val) {
      const that = this;
      that.$refs.form.validate(value => {
        if (value) {
          this.$confirm('是否确定修改欢迎语启用状态？', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          })
            .then(() => {
              getRequest('/haoban-manage3-web/set-welcome', { openFlag: val })
                .then(res => {
                  let resData = res.data;
                  if (resData.errorCode == 1) {
                    that.$message.success({
                      duration: 1000,
                      message: '设置成功'
                    });
                    window.location.reload();
                  }
                  errMsg.errorMsg(resData);
                })
                .catch(function(error) {
                  that.$message.error({
                    duration: 1000,
                    message: error.message
                  });
                });
            })
            .catch(() => {
              that.openFlag = that.openFlag === 1 ? 0 : 1;
            });
        }
      });
    }
  },
  watch: {},
  mounted() {
    const that = this;
    that.$emit('showTab', 4);
    document.documentElement.style.backgroundColor = '#f0f2f5';
    that.getData();
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {}
};
</script>
<style type="text/scss" lang="scss" scoped>
.bg-ebecf0 {
  background: #ebecf0;
}
.color-c0c4cc {
  display: inline-block;
  line-height: 34px;
  padding-left: 10px;
  color: #c0c4cc;
}
.condition-tips {
  display: inline-block;
  vertical-align: middle;
  line-height: 32px;
}
.p-l-30 {
  padding-left: 30px;
}
.p-l-40 {
  padding-left: 40px;
}
.p-l-55 {
  padding-left: 55px;
}
.p-l-85 {
  padding-left: 85px;
}
.m-l-20 {
  margin-left: 20px;
}
.line-50 {
  height: 50px;
  line-height: 50px;
}
.el-alert--info {
  align-items: flex-start;
  width: 700px;
  padding-top: 5px;
  font-size: 14px;
  color: #606266;
  background: rgba(240, 245, 255, 1);
  border-radius: 2px;
  border: 1px solid rgba(133, 165, 255, 1);
}
.el-icon-info {
  width: 12px;
  font-size: 12px;
  color: #2f54eb;
  margin-top: 5px;
}
.el-alert__content {
  padding-left: 9px;
  .el-alert__title {
    font-size: 13px;
    font-weight: 400;
    color: #303133;
    line-height: 22px;
  }
}
.daily-set-wrap {
  height: 100%;
  .daily-set-content {
    padding: 20px;
    .table-condition-left {
      font-size: 0;
    }
  }
}
.salutatory-wrap {
  // height: 160px;
  background: #f5f7fa;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 47px;
    padding: 0 20px 0 29px;
    .left {
      font-size: 14px;
      font-weight: 600;
      color: #303133;
      line-height: 20px;
    }
    .right {
      .date {
        font-size: 12px;
        font-weight: 400;
        color: #909399;
        line-height: 17px;
        margin-right: 30px;
      }
    }
  }
  .line {
    box-sizing: border-box;
    border: 1px solid #e4e7ed;
    border-style: none none solid none;
  }
  .bottom {
    padding: 16px 20px 21px 29px;
    .el-form-item {
      >>> .el-form-item__label {
        padding: 0;
      }
      >>> .el-form-item__label,
      >>> .el-form-item__content {
        line-height: 20px;
        font-size: 14px;
        font-weight: 400;
        color: #303133;
      }
    }
  }
}
.welcome-text {
  text-align: left;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
</style>
