<!--
 * @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" :true-label="1" :false-label="0">展示微盟商城订单</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" :true-label="1" :false-label="0">展示达摩商城订单</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.integralOrderShow" :true-label="1" :false-label="0">展示积分商城订单</el-checkbox>
        <div class="font-14 color-909399 set-tip-item">注：保存勾选项后，客户详情 - 消费记录中将展示GIC积分商城交易成功的订单</div>
      </div>
      <div class="m-t-46 m-l-25">
        <el-button type="primary" :loading="loading" @click="submit('showFlag')" :disabled="$store.state.wxEnterpriseType">保 存</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 '';
      }
    }
  },
  data() {
    return {
      projectName: '', // 当前项目名
      wxEnterpriseRelatedId: JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId,
      myCustomData: {
        wmOrderShow: 0,
        damoOrderShow: 0,
        integralOrderShow: 0
      },
      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,
        damoOrderShow: that.myCustomData.damoOrderShow,
        integralOrderShow: this.myCustomData.integralOrderShow
      };
      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) {
              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.getShowSet(that.brandId);
  },
  components: {}
};
</script>
<style lang="scss" 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>
