<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2019-06-20 14:36:37
 * @LastEditors: 无尘
 * @LastEditTime: 2020-06-22 17:20:01
 -->
<template>
  <div class="app-detail-wrap">
    <div class="app-detail-pane border-box p-20">
      <div class="flex flex-space-between">
        <div>
          <el-input placeholder="搜索门店名称或代码" prefix-icon="el-icon-search" v-model="searchInput" class="w-369" @keyup.native="value => toInput(value, searchInput)" clearable @clear="clearInput"> </el-input>
        </div>
        <div>
          <el-button type="primary" @click="showGroup">选择分组</el-button>
          <el-button type="primary" @click="showGroup">批量移除</el-button>
        </div>
      </div>
      <div>
        <el-table ref="multipleTable" v-loading="loading" :data="tableData" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column label="分组名称">
            <template slot-scope="scope">
              {{ scope.row.groupName || '--' }}
            </template>
          </el-table-column>
          <el-table-column label="分类">
            <template slot-scope="scope">
              {{ scope.row.memberTagGroupClassifyName || '--' }}
            </template>
          </el-table-column>
          <el-table-column prop="" label="是否实时" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.isRealTime == 1 ? '是' : '否' }}</template>
          </el-table-column>
          <el-table-column prop="" label="更新频率" show-overflow-tooltip>
            <template slot-scope="scope"
              >{{ scope.row.updateType == 1 ? '每日' : scope.row.updateType == 2 ? '每周' : scope.row.updateType == 3 ? '每月' : '-' }} {{ scope.row.updateType == 1 ? '一次' : scope.row.updateType == 2 ? '周' + scope.row.updateDay : scope.row.updateType == 3 ? scope.row.updateDay + '号' : '-' }}
            </template>
          </el-table-column>
          <el-table-column prop="" label="状态" show-overflow-tooltip>
            <template slot-scope="scope">{{ scope.row.effectiveStatus == '1' ? '有效' : '失效' }}</template>
          </el-table-column>
          <el-table-column prop="" label="覆盖人数" show-overflow-tooltip>
            <template slot-scope="scope"
              >{{ scope.row.memberCount || 0 }}人</template
            >
          </el-table-column>
          <el-table-column prop="" label="到期时间" show-overflow-tooltip>
            <template slot-scope="scope">
              <div class="line-18">{{ scope.row.effectiveDate | timeStampToYmd }}</div>
              <div class="line-18">{{ scope.row.effectiveDate | timeStampToHms }}</div>
            </template>
          </el-table-column>
        </el-table>
        <div class="block common-wrap__page text-right" v-if="tableData.length != 0">
          <dm-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </dm-pagination>
        </div>
      </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: '', // 当前项目名
      wxEnterpriseRelatedId: localStorage.getItem('userInfos') ? JSON.parse(localStorage.getItem('userInfos')).wxEnterpriseId : '',
      editPerson: localStorage.getItem('userInfos') && JSON.parse(localStorage.getItem('userInfos')).staffDTO ? JSON.parse(localStorage.getItem('userInfos')).staffDTO.staffName : '',
      searchInput: '',
      tableData: [],
      activeId: '1',
      loading: false,
      multipleSelection: [],

      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0,
      groupShow: false
    };
  },
  methods: {
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    }, 500),
    // 搜索清除
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    /**
     * 多选分组
     */
    handleSelectionChange(val) {
      const that = this;
      that.multipleSelection = val;
    },
    /**
     * 显示分组
     */
    showGroup() {
      const that = this;
      that.groupShow = true;
    },
    /**
     * 分页---页码变化
     */
    handleSizeChange(val) {
      const that = this;
      that.pageSize = val;
    },

    /**
     * 分页---当前页变化
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
    },
    /**
     * 保存
     */
    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
        // enterpriseId: JSON.parse(localStorage.getItem('userInfos')).enterpriseId
      };
      let url;
      if (type != 'showFlag') {
        para[type] = !!that.myCustomData[type] ? 1 : 0;
        url = '/haoban-app-customer-web/customer/save-online-chat-setting';
        if (type === 'searchFlag') {
          url = '/haoban-app-customer-web/customer/save-customer-setting';
        }
      }

      postRequest(url, para)
        .then(res => {
          let resData = res.data;
          that.loading = false;
          if (resData.errorCode == 1) {
            showMsg.showmsg('保存成功', 'success');
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    },

    /**
     * 改变
     */
    changeAllowGuide(e) {
      const that = this;
      that.myCustomData.allowGuideMobile = e;
      that.myCustomData.allowGuideMessage = e;
      that.myCustomData.allowGuideOnlineChat = e;
    },

    /**
     * 改变联系
     */
    changeContact() {
      const that = this;
      if (!that.myCustomData.allowGuideMobile && !that.myCustomData.allowGuideMessage && !that.myCustomData.allowGuideOnlineChat) {
        that.myCustomData.allowGuideContact = false;
      }
    },
    /**
     * 获取全品牌搜索设置数据
     */
    getCustomerSet(brandId) {
      const that = this;
      let para = {
        enterpriseId: that.brandId,
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId
      };
      postRequest('/haoban-app-customer-web/customer/find-customer-setting', para)
        .then(res => {
          let resData = res.data;
          if (resData.errorCode == 1) {
            if (!!resData.result) {
              that.myCustomData.searchFlag = !!resData.result.searchFlag ? true : false;
            }
            return;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {
    brandId: function(newData, oldData) {
      const that = this;
      that.getCustomerSet(that.brandId);
    }
  },
  mounted() {
    const that = this;
    that.$emit('showTab', '13');
    that.getCustomerSet(that.brandId);
  },
  components: {}
};
</script>
<style lang="less" 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;
    /deep/ .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>
