<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-03-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-03-17 18:06:51
 -->
<template>
  <div class="app-detail-wrap">
    <div class="task-set-content border-box">
      <div class="task-set-cell font-0">
        <div class="inline-block font-14 color-606266 m-b-10 w-100">日报开关设置：</div>
        <div class="inline-block font-14 ">
          <el-switch v-model="setData.status" active-text=" " inactive-text=" "> </el-switch>
        </div>
        <div class="inline-block m-l-10 font-14 color-606266 m-b-16">开启后，日报将定时发送</div>
      </div>
      <div class="task-set-cell  font-0">
        <div class="inline-block font-14 color-606266 m-b-10 w-100"></div>
        <div class="inline-block m-l-10 vertical-top font-14 right-set-body">
          <div class="font-14 color-606266 m-b-10 font-w-500">日报每日下发时间设置</div>
          <div class=" font-14 color-606266 m-b-16">该事件设置将在次日生效，为避免影响当日日报的发送，请在日报发送后设置</div>
          <div>
            <el-time-select
              class="w-118"
              :editable="false"
              :clearable="false"
              v-model="setData.time"
              :picker-options="{
                start: '00:00',
                step: '00:15',
                end: '23:45'
              }"
              placeholder="选择时间"
            >
            </el-time-select>
          </div>
          <!-- <div class="set-line-item">
            <span class="set-line-item_title font-14 color-606266 ">云日报释放：</span><el-checkbox v-model="setData.releaseFlag"></el-checkbox
            ><el-tooltip class="item" effect="dark" content="开启后，导购换绑导购code后，原导购code任务将被释放给门店店长" placement="top-start">
              <span :class="['font-14 color-606266 m-l-10']" style="cursor: pointer;padding-bottom: 2px; border-bottom: 1px dashed #2F54EB;">释放未绑定/解绑导购任务</span>
            </el-tooltip>
          </div> -->
        </div>
      </div>
      <div class="task-set-cell font-0">
        <div class="inline-block font-14 color-606266 m-b-10 w-100"></div>
        <div class="inline-block m-l-10 task-set-save m-t-50 font-14">
          <el-button type="primary" @click="saveSet">保 存</el-button>
        </div>
      </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',
      activeBrand: this.brandId, // 商户(品牌) id
      topMenuData: [
        {
          id: '1',
          name: '任务下发设置'
        }
      ],
      activeId: '1',
      setData: {
        status: false,
        time: '12:00',
        releaseFlag: false
      }
    };
  },
  computed: {},
  methods: {
    /**
     * 保存
     */
    saveSet: _debounce(function() {
      let that = this;
      that.postSave();
    }, 500),
    postSave() {
      let that = this;
      let para = {
        enterpriseId: that.activeBrand,
        status: !!that.setData.status ? '1' : '0',
        time: that.setData.time,
        releaseFlag: that.setData.releaseFlag ? 1 : 0
      };
      postRequest('/haoban-app-daily-three-web/daily/create-setting', 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
          });
        });
    },
    /**
     * 获取设置数据
     */
    getData() {
      let that = this;
      let para = {
        enterpriseId: that.activeBrand
      };
      postRequest('/haoban-app-daily-three-web/daily/get-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            that.setData.status = resData.result.status == 1 ? true : false;
            that.setData.releaseFlag = resData.result.releaseFlag == 1 ? true : false;
            that.setData.time = resData.result.time;
            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', '2');
    if (!!that.brandId) {
      that.getData();
    }
  },
  destroyed() {
    document.documentElement.style.backgroundColor = '#fff';
  },
  components: {}
};
</script>
<style type="text/scss" lang="scss" scoped>
.w-100 {
  width: 100px;
}
.m-t-50 {
  margin-top: 50px;
}
.task-set-content {
  padding: 20px;
  .task-set-cell {
    // padding: 30px 0;
    // border-bottom: 1px solid #e4e7ed;
    .right-set-body {
      padding: 18px;
      background: #f5f7fa;
    }
    .set-line-item {
      margin-top: 24px;
    }
    .el-date-editor.el-input {
      width: 118px;
    }
  }
}
</style>
