<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-06-08 13:40:59
 -->
<template>
  <div class="app-detail-wrap">
    <div class="task-set-content boder-box">
      <div class="task-set-cell">
        <div class="set-line-item"><span class="set-line-item_title font-14 color-606266  text-right">任务归属：</span><el-radio v-model="setObj.taskBelong" label="1">成员所属专属导购 > 协管导购，若无专属导购，则随机分配给一名协管导购</el-radio></div>
        <div class="set-line-item">
          <span class="set-line-item_title font-14 color-606266  text-right">逾期设置：</span><span class="font-14 color-606266">话务任务下发后 </span><el-input-number controls-position="right" class="w-100" v-model="setObj.overDayJudge" placeholder="请输入内容" :step="1" :step-strictly="true" :min="0" :max="99999999"></el-input-number><span class="font-14 color-606266 p-l-10">天</span>
          <span class="font-14 color-606266">注：0天即为当天下发，当天完成，1天即为当天下发，次日24：00之前完成</span>
        </div>
        <div class="set-line-item">
          <span class="set-line-item_title font-14 color-606266 text-right"></span>
          <el-button type="primary" :loading="loadingBtn" @click="saveSet">保存并用于全部商户</el-button>
        </div>
      </div>
      <div class="task-set-save m-t-30">
        <!-- <el-button type="primary" @click="saveSet">保 存</el-button> -->
      </div>
    </div>
  </div>
</template>
<script>
import { _debounce } from '@/common/js/public';
import errMsg from '@/common/js/error';
import showMsg from '@/common/js/showmsg';
import { postRequest } from '@/api/api';
export default {
  name: 'reviewed',
  props: {
    brandId: {
      type: String,
      default() {
        return '';
      }
    }
  },
  data() {
    return {
      activeTab: '1',
      activeId: '1',
      activeBrand: this.brandId, // 商户(品牌) id
      wxEnterpriseId: localStorage.getItem('userInfos') ? JSON.parse(localStorage.getItem('userInfos')).wxEnterpriseId : '',

      setObj: {
        taskBelong: '1',
        overDayJudge: ''
      },
      loadingBtn: false
    };
  },
  computed: {},
  methods: {
    /**
     * 保存
     */
    saveSet: _debounce(function() {
      let that = this;
      that.loadingBtn = true;
      that.postSave();
    }, 500),
    postSave() {
      let that = this;
      let para = {
        taskBelong: that.setObj.taskBelong,
        overDayJudge: that.setObj.overDayJudge,
        wxEnterpriseId: that.wxEnterpriseId
      };
      postRequest('/haoban-app-tel-task-three-web/setting/save-session-task-setting', para)
        .then(res => {
          let resData = res.data;
          that.loadingBtn = false;
          if (resData.errorCode == 1) {
            showMsg.showmsg('保存成功', 'success');
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loadingBtn = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },
    /**
     * 获取设置数据
     */
    getData() {
      let that = this;
      let para = {
        wxEnterpriseId: that.wxEnterpriseId
      };
      postRequest('/haoban-app-tel-task-three-web/setting/find-session-task-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result) {
              resData.result.taskBelong = String(resData.result.taskBelong);
            } else {
              resData.result = {};
              resData.result.taskBelong = '1';
              resData.result.overDayJudge = '';
            }
            that.setObj = 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;
      if (!!newData) {
        that.activeBrand = newData;
        that.getData();
      }
    }
  },
  mounted() {
    let that = this;
    document.documentElement.style.backgroundColor = '#f0f2f5';
    that.$emit('showTab', '22');
    that.getData();
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {}
};
</script>
<style type="text/scss" lang="scss" scoped>
.w-100 {
  width: 100px;
}
.vertical-top {
  vertical-align: top;
}
.task-set-content {
  padding: 30px;
  .task-set-cell {
    /* padding: 30px 0; */
    .el-date-editor.el-input {
      width: 118px;
    }
  }
  .set-line-item {
    margin-bottom: 20px;
    table {
      tr {
        td {
          padding: 17px 30px;
          border: 1px solid #ebeef5;
        }
      }
    }
    .set-line-item_title {
      display: inline-block;
      width: 120px;
      &.w-320 {
        width: 320px;
        i {
          font-style: normal;
          padding-left: 10px;
        }
      }
    }
  }
}
</style>
