<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-12-18 15:10:29
 -->

<template>
  <div class="app-detail-wrap">
    <div class="app-detail-pane border-box p-20">
      <div class="m-b-20">
        <span class="font-14 p-r-10"></span>
        <el-switch v-model="myCustomData.guideReplyFlag" :active-value="1" :inactive-value="0"></el-switch>
        <span class="p-r-10 font-14 color-303133">禁止订单关联导购回复评价</span><span class="font-12 color-909399 p-l-10">注：开启后，订单关联导购不可回复评价</span>
      </div>
      <div class="m-b-20">
        <span class="font-14 p-r-10"></span>
        <el-switch v-model="myCustomData.allOrderFlag" :active-value="1" :inactive-value="0"></el-switch>
        <span class="p-r-10 font-14 color-303133">允许店员查看所有订单评价</span>
      </div>
      <div class="m-t-46">
        <el-button type="primary" :loading="loading" @click="submit('searchFlag')" :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, getRequest } from '@/api/api';
export default {
  name: 'evaluate-set',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    },
    tabType: {
      type: String,
      default() {
        return '1';
      }
    }
  },
  data() {
    return {
      projectName: '', // 当前项目名
      wxEnterpriseRelatedId: sessionStorage.getItem('userInfos') ? JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId : '',
      myCustomData: {
        guideReplyFlag: 0,
        allOrderFlag: 0
      },
      activeId: '1',
      loading: false
    };
  },
  methods: {
    /**
     * 保存
     */
    submit: _debounce(function(type) {
      const that = this;
      that.loading = true;
      that.setData(type);
    }, 500),

    /**
     * 保存-API
     */
    setData(type) {
      const { allOrderFlag, guideReplyFlag } = this.myCustomData;
      let para = {
        enterpriseId: this.brandId,
        guideReplyFlag,
        allOrderFlag
      };
      const url = '/haoban-app-aggregation-web/order-evaluation-setting';
      postRequest(url, para)
        .then(res => {
          let resData = res.data;
          this.loading = false;
          this.getCustomerSet();
          if (resData.errorCode == 1) {
            showMsg.showmsg('保存成功', 'success');
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          this.loading = false;
          this.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    /**
     * 获取数据
     */
    getCustomerSet(brandId) {
      const that = this;
      let para = {
        enterpriseId: that.brandId,
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId
      };
      getRequest('/haoban-app-aggregation-web/order-evaluation-find', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result) {
              const { guideReplyFlag, allOrderFlag } = resData.result;
              that.myCustomData.guideReplyFlag = guideReplyFlag;
              that.myCustomData.allOrderFlag = allOrderFlag;
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      if (newData) {
        that.getCustomerSet(that.brandId);
      }
    }
  },
  mounted() {
    const that = this;
    that.$emit('showTab', '1');
    if (that.brandId) {
      that.getCustomerSet(that.brandId);
    }
  },
  components: {}
};
</script>
<style lang="scss" 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;
}

.app-detail-wrap {
  height: 100%;
  background: #fff;
  .el-tabs {
    background: #fff;
    >>> .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>
