<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-06-08 11:27:30
 -->

<!--
  我的客户应用：
  <app-detail ></app-detail>
 -->
<template>
  <div class="app-detail-wrap">
    <el-form>
      <el-form-item>
        <el-checkbox v-model="myCustomData.searchFlag" :true-label="1" :false-label="0">允许全品牌搜索</el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="myCustomData.handoverFlag" :true-label="1" :false-label="0">离职继承</el-checkbox>
        <div class="set-tip-text">保存勾选项后，店长可以选择离职的导购名下的好友会员，选择离职继承</div>
      </el-form-item>
    </el-form>
    <div class="m-t-46">
      <el-button v-if="$getButtonLimit($buttonCode.searchSetSave)" :limit-code="$buttonCode.searchSetSave" type="primary" :loading="loading" @click="setData">保 存</el-button>
    </div>
  </div>
</template>
<script>
import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
import { postRequest } from '@/api/api';
export default {
  name: 'app-detail',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      wxEnterpriseRelatedId: JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId,
      myCustomData: {
        searchFlag: 0,
        handoverFlag: 0
      },
      loading: false
    };
  },
  methods: {
    /**
     * 保存-API
     */
    setData() {
      let para = {
        enterpriseId: this.brandId,
        wxEnterpriseRelatedId: this.wxEnterpriseRelatedId
        // enterpriseId: JSON.parse(localStorage.getItem('userInfos')).enterpriseId
      };
      para.searchFlag = this.myCustomData.searchFlag;
      para.handoverFlag = this.myCustomData.handoverFlag;

      postRequest('/haoban-app-customer-web/customer/save-customer-setting', para).then(res => {
        let resData = res.data;
        if (resData.errorCode == 1) {
          showMsg.showmsg('保存成功', 'success');
          return;
        }
        errMsg.errorMsg(resData);
      });
    },
    /**
     * 获取全品牌搜索设置数据
     */
    getCustomerSet() {
      const para = {
        enterpriseId: this.brandId,
        wxEnterpriseRelatedId: this.wxEnterpriseRelatedId
      };
      postRequest('/haoban-app-customer-web/customer/find-customer-setting', para).then(res => {
        const { errorCode, result } = res.data || {};
        if (errorCode == 1) {
          if (result) {
            this.myCustomData.searchFlag = result.searchFlag;
            this.myCustomData.handoverFlag = result.handoverFlag;
          }
          return;
        }
        errMsg.errorMsg(res.data);
      });
    }
  },
  mounted() {
    this.getCustomerSet();
  }
};
</script>
<style lang="scss" scoped>
.app-detail-wrap {
  padding: 20px;
}
.set-tip-text {
  padding: 0 0 0 25px;
  font-size: 12px;
  font-weight: 400;
  color: #909399;
  line-height: 17px;
}
</style>
