<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-03-16 15:12:59
 * @LastEditors: 无尘
 * @LastEditTime: 2020-05-29 10:42:07
 -->
<template>
  <div class="unreview-wrap common-set-wrap">
    <div class="right-content">
      <div class="right-box" style="min-height: calc(100vh - 126px)">
        <div>
          <el-switch v-model="storeSwitch" active-text="" inactive-text="" @change="changeSwitch"> </el-switch>
          <el-tooltip content="开启后，所有门店在小程序端修改门店资料需要审核通过后才能修改" placement="top">
            <span class="inline-block font-14 color-303133 m-l-20" style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">开启门店资料修改审核</span>
          </el-tooltip>
        </div>
        <div class="m-t-20">
          <el-switch v-model="clerkChangeFlag" active-text="" inactive-text="" @change="changeSwitch"> </el-switch>
          <el-tooltip content="开启后，企业微信成员在好办小程序店长删除或新增导购需要进行审核" placement="top">
            <span class="inline-block font-14 color-303133 m-l-20" style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">门店导购变更审核</span>
          </el-tooltip>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
// import { _debounce } from '@/common/js/public';
import { getRequest, postRequest } from '@/api/api';
export default {
  name: 'unreview',
  data() {
    return {
      storeSwitch: false,
      clerkChangeFlag: false,
      wxEnterpriseId: localStorage.getItem('userInfos') ? JSON.parse(localStorage.getItem('userInfos')).wxEnterpriseId : ''
    };
  },
  methods: {
    /**
     * 设置数据
     */
    changeSwitch(e) {
      const that = this;
      that.postData();
    },
    postData(val) {
      const that = this;
      let para = {
        wxEnterpriseId: that.wxEnterpriseId,
        auditFlag: that.storeSwitch ? 1 : 0,
        clerkChangeFlag: that.clerkChangeFlag ? 1 : 0
      };
      postRequest('/haoban-manage3-web/audit/open-or-close', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            showMsg.showmsg('操作成功', 'success');
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取数据
     */
    getData(val) {
      const that = this;
      let para = {
        wxEnterpriseId: that.wxEnterpriseId
      };
      getRequest('/haoban-manage3-web/audit/find-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.storeSwitch = resData.result.auditFlag == 1 ? true : false;
            that.clerkChangeFlag = resData.result.clerkChangeFlag == 1 ? true : false;
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  mounted() {
    const that = this;
    that.$emit('showTab', 3);
    that.getData();
  }
};
</script>
<style lang="less" scoped>
.m-l-20 {
  margin-left: 20px;
}

.right-content {
  min-height: calc(100% - 126px);
  .right-box {
    background: #fff;
    min-height: 500px;
    padding: 20px;
  }
}
</style>
