<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors  : 无尘
 * @LastEditTime : 2020-02-19 14:40:47
 -->

<!--
  我的顾客应用：
  <app-detail ></app-detail>
 -->
<template>
  <div class="app-detail-wrap">
    <div class="app-detail-pane border-box p-20">
      <div class="m-b-20">
        <el-checkbox class="w-195" v-model="myCustomData.mainStoreFlag">展示服务门店会员</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，门店导购和店长可查看本门店作为服务门店名下会员</div>
      </div>
      <div class="m-b-20">
        <el-checkbox class="w-195" v-model="myCustomData.minorStoreFlag">展示协管门店会员</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，门店导购和店长可查看本门店作为协管门店名下会员</div>
      </div>
      <div class="m-b-20">
        <el-checkbox class="w-195" v-model="myCustomData.openCardStoreFlag">展示开卡门店会员</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，门店导购和店长可查看本门店作为开卡门店名下会员</div>
      </div>
      <div class="m-b-20">
        <el-checkbox class="w-195" v-model="myCustomData.isSeeAuthMember">展示已开卡会员</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，门店导购和店长可查看本门店微信会员（不含未开卡会员）及POS会员，不勾选将展示微信会员（即微信总量，含未开卡会员）及POS会员</div>
      </div>
      <div class="m-b-20">
        <el-checkbox class="w-195" v-model="myCustomData.clerkSeeOtherFlag">允许导购查看其他导购会员</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，门店导购可查看本门店其他导购名下会员</div>
      </div>
      <div class="m-b-20">
        <el-tooltip class="item" effect="dark" content="注：开启后，可选择导购在 &lt; 我的顾客 &gt; 中是否通过以下方式联系会员" placement="top-start"> <span style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;" class="font-14 color-606266 m-r-20">导购联系会员方式：</span></el-tooltip>
        <el-checkbox v-model="myCustomData.allowGuideMobile" @change="changeContact">电话</el-checkbox>
        <el-checkbox v-model="myCustomData.allowGuideMessage" @change="changeContact">短信</el-checkbox>
        <el-checkbox v-model="myCustomData.allowGuideOnlineChat" @change="changeContact">添加会员/发消息</el-checkbox>
      </div>
      <div class="m-t-46">
        <el-button type="primary" @click="submit('showFlag')">保 存</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
import { _debounce } from '@/common/js/public';
import { postRequest } from '@/api/api';
export default {
  name: 'app-detail',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    },
    tabType: {
      type: String,
      default() {
        return '1';
      }
    },
    activeGroupId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      projectName: '', // 当前项目名
      activeName: 'first',
      activeGroup: this.activeGroupId, // 商户(品牌) groupId
      wxEnterpriseRelatedId: JSON.parse(localStorage.getItem('userInfos')).wxEnterpriseId,
      myCustomData: {
        searchFlag: false,
        chatFlag: false,
        mainStoreFlag: false, // 服务门店显示，1显示0不现实
        minorStoreFlag: false, // 协管门店显示，1显示0不显示
        openCardStoreFlag: false, // 开卡门店显示，1显示0不显示
        clerkSeeOtherFlag: false, // 导购查看其他导购，1显示0不显示
        isSeeAuthMember: false,
        allowGuideContact: false,
        allowGuideMobile: false,
        allowGuideMessage: false,
        allowGuideOnlineChat: false
      }
    };
  },
  methods: {
    /**
     * 保存
     */
    submit: _debounce(function(type) {
      const that = this;
      that.setData(type);
    }, 500),

    /**
     * 保存-API
     */
    setData(type) {
      const that = this;
      let para = {
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId
        // enterpriseId: JSON.parse(localStorage.getItem('userInfos')).enterpriseId
      };
      let url;
      if (type != 'showFlag') {
        para[type] = !!that.myCustomData[type] ? 1 : 0;
        url = '/haoban-app-customer-web/customer/save-online-chat-setting';
        if (type === 'searchFlag') {
          url = '/haoban-app-customer-web/customer/save-customer-setting';
        }
      } else {
        para['mainStoreFlag'] = !!that.myCustomData['mainStoreFlag'] ? 1 : 0;
        para['minorStoreFlag'] = !!that.myCustomData['minorStoreFlag'] ? 1 : 0;
        para['openCardStoreFlag'] = !!that.myCustomData['openCardStoreFlag'] ? 1 : 0;
        para['clerkSeeOtherFlag'] = !!that.myCustomData['clerkSeeOtherFlag'] ? 1 : 0;
        para['allowGuideContact'] = !!that.myCustomData['allowGuideContact'] ? 1 : 0;
        para['allowGuideMobile'] = !!that.myCustomData['allowGuideMobile'] ? 1 : 0;
        para['allowGuideMessage'] = !!that.myCustomData['allowGuideMessage'] ? 1 : 0;
        para['allowGuideOnlineChat'] = !!that.myCustomData['allowGuideOnlineChat'] ? 1 : 0;
        para['isSeeAuthMember'] = !!that.myCustomData['isSeeAuthMember'] ? 1 : 0;
        para.chatFlag = that.myCustomData.chatFlag; // 总的
        para.isMessageRemind = that.myCustomData.isMessageRemind; // 短信
        para.messageRemindTime = that.myCustomData.messageRemindTime;
        para.isTemplateMessage = that.myCustomData.isTemplateMessage; // 模板消息
        para.isImgMessage = that.myCustomData.isImgMessage; // 图文
        para.isGoodMessage = that.myCustomData.isGoodMessage;
        para.isIntegralGoodMessage = that.myCustomData.isIntegralGoodMessage;
        url = '/haoban-app-customer-web/customer/save-member-show-setting';
      }
      postRequest(url, 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
          });
        });
    },

    /**
     * 改变
     */
    changeAllowGuide(e) {
      const that = this;
      that.myCustomData.allowGuideMobile = e;
      that.myCustomData.allowGuideMessage = e;
      that.myCustomData.allowGuideOnlineChat = e;
    },

    /**
     * 改变联系
     */
    changeContact() {
      const that = this;
      if (!that.myCustomData.allowGuideMobile && !that.myCustomData.allowGuideMessage && !that.myCustomData.allowGuideOnlineChat) {
        that.myCustomData.allowGuideContact = false;
      }
    },

    /**
     * 获取会员展示设置数据
     */
    getShowSet(brandId) {
      const that = this;
      let para = {
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId
      };
      postRequest('/haoban-app-customer-web/customer/find-member-show-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result) {
              resData.result.mainStoreFlag = resData.result.mainStoreFlag == 1 ? true : false;
              resData.result.minorStoreFlag = resData.result.minorStoreFlag == 1 ? true : false;
              resData.result.openCardStoreFlag = resData.result.openCardStoreFlag == 1 ? true : false;
              resData.result.clerkSeeOtherFlag = resData.result.clerkSeeOtherFlag == 1 ? true : false;
              resData.result.allowGuideContact = resData.result.allowGuideContact == 1 ? true : false;
              resData.result.allowGuideMobile = resData.result.allowGuideMobile == 1 ? true : false;
              resData.result.allowGuideMessage = resData.result.allowGuideMessage == 1 ? true : false;
              resData.result.allowGuideOnlineChat = resData.result.allowGuideOnlineChat == 1 ? true : false;
              resData.result.isSeeAuthMember = resData.result.isSeeAuthMember == 1 ? true : false;
              resData.result.searchFlag = resData.result.searchFlag == 1 ? true : false;
              that.myCustomData = resData.result;
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {},
  mounted() {
    const that = this;
    that.$emit('showTab', '11');
    that.getShowSet(that.brandId);
  },
  components: {}
};
</script>
<style lang="less" scoped>
.w-500 {
  width: 500px;
}

.w-195 {
  width: 195px;
}

.color-1890ff {
  color: #2f54eb;
}

.p-20 {
  padding: 20px;
}

.p-l-38 {
  padding-left: 38px;
}

.p-l-199 {
  padding-left: 199px;
}

.set-tip-item {
  padding: 5px 0 0 25px;
}

.app-detail-wrap {
  height: 100%;
  background: #fff;
  .el-tabs {
    background: #fff;
    /deep/ .el-tabs__nav-wrap {
      /* height: 48px;
      line-height: 48px; */
      &::after {
        height: 1px;
      }
      /* .el-tabs__nav-scroll {
        padding-left: 20px;
      } */
    }
  }
  .condition-tip {
    width: 740px;
    .el-alert--info {
      background: #e6f7ff;
      border: 1px solid rgba(145, 213, 255, 1);
      .el-alert__icon {
        font-size: 12px;
      }
    }
  }
}
</style>
