<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-08-14 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-14 14:40:36
 -->

<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.wmOrderShow">展示微盟商城订单</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.damoOrderShow">展示达摩商城订单</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，顾客详情 - 消费记录中将展示达摩商城交易成功的订单</div>
      </div>
      <div class="m-t-46 m-l-25">
        <el-button type="primary" :loading="loading" @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: {
        wmOrderShow: false,
        damoOrderShow: false
      },
      loading: false
    };
  },
  methods: {
    /**
     * 保存
     */
    submit: _debounce(function(type) {
      const that = this;
      that.loading = true;
      that.setData(type);
    }, 500),

    /**
     * 保存-API
     */
    setData(type) {
      const that = this;
      let para = {
        enterpriseId: that.brandId,
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId,
        wmOrderShow: that.myCustomData.wmOrderShow ? 1 : 0,
        damoOrderShow: that.myCustomData.damoOrderShow ? 1 : 0
      };
      const url = '/haoban-app-customer-web/customer/save-consume-setting';
      postRequest(url, para)
        .then(res => {
          const resData = res.data;
          that.loading = false;
          if (resData.errorCode == 1) {
            showMsg.showmsg('保存成功', 'success');
            that.getShowSet();
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    /**
     * 获取设置数据
     */
    getShowSet(brandId) {
      const that = this;
      const para = {
        enterpriseId: that.brandId,
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId
      };
      postRequest('/haoban-app-customer-web/customer/find-consume-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result) {
              resData.result.wmOrderShow = resData.result.wmOrderShow == 1 ? true : false;
              resData.result.damoOrderShow = resData.result.damoOrderShow == 1 ? true : false;
              that.myCustomData = resData.result;
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      that.getShowSet(that.brandId);
    }
  },
  mounted() {
    const that = this;
    that.$emit('showTab', '14');
    that.getShowSet(that.brandId);
  },
  components: {}
};
</script>
<style lang="less" scoped>
.w-195 {
  width: 195px;
}

.p-20 {
  padding: 20px;
}

.m-l-25 {
  margin-left: 25px;
}

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

.app-detail-wrap {
  height: 100%;
  background: #fff;
}
</style>
