<template>
  <div class="audit-config">
    <h3 class="audit-config-title">需要进行审核的事项</h3>
    <div class="audit-config-content">
      <el-switch :value="clerkAddFlag == 1" v-loading="loading" @change="saveAuditConfig"></el-switch>
      <div class="audit-config-desc">
        <p class="desc-content">导购账号新增</p>
        <p class="desc-tip">门店角色添加导购账号，需要经过管理员审批同意后才能新增成功，管理员新增导购无需审核</p>
      </div>
    </div>
  </div>
</template>

<script>
import fetch from '@/api/review';
const { findAuditSetting, saveAuditSetting } = fetch;
export default {
  name: 'AuditConfig',
  data() {
    return {
      wxEnterpriseId: '',
      clerkAddFlag: 1, // 1,开启，0关闭
      loading: false,
    };
  },
  created() {
    const haobanUser = JSON.parse(localStorage.getItem('haoBanUser') || '{}');
    this.wxEnterpriseId = haobanUser.wxEnterpriseId;
    this.getAuditConfig();
    this.$emit('showTab', '/audit-config');
  },
  methods: {
    getAuditConfig() {
      findAuditSetting({ wxEnterpriseId: this.wxEnterpriseId }).then(res => {
        const { clerkAddFlag } = res.result || {};
        this.clerkAddFlag = clerkAddFlag;
      });
    },
    saveAuditConfig(flag) {
      const params = {
        clerkAddFlag: Number(flag),
        wxEnterpriseId: this.wxEnterpriseId
      };
      this.loading = true;
      saveAuditSetting(params).then(res => {
        this.$message.success('保存成功！');
        this.getAuditConfig();
      }).finally(() => this.loading = false);
    }
  }
};
</script>

<style lang="less" scoped>
.audit-config {
  padding: 30px;
  min-height: 100%;
  background-color: #fff;
  .audit-config-title {
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 700;
    color: @gray01;
    line-height: 20px;
  }
  .audit-config-content {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    .audit-config-desc {
      margin-left: 17px;
    }
    .desc-content {
      font-size: 14px;
      font-weight: 400;
      color: @gray02;
      line-height: 20px;
    }
    .desc-tip {
      font-size: 12px;
      font-weight: 400;
      color: @gray03;
      line-height: 22px;
    }
  }
}
</style>
