<!--
 * @Descripttion: 当前组件信息
 * @version: 1.0.0
 * @Author: 无尘
 * @Date: 2020-04-14 09:50:16
 * @LastEditors: 无尘
 * @LastEditTime: 2020-08-26 09:54:22
 -->
<!--
  <select-group :brandId="brandId"  @closeGroup="closeGroup" @submitGroup="submitGroup"></select-group>
  import selectGroup from '@/components/app/customer/select-group.vue';
 -->
<template>
  <el-dialog class="select-table-dialog" title="选择分组" :visible.sync="dialogVisible" width="833px" :before-close="handleClose">
    <div class="">
      <div class="search-top m-b-20">
        <el-input placeholder="请输入分组名称搜索" maxlength="50" prefix-icon="el-icon-search" v-model="searchInput" class="w-280" @keyup.native="value => toInput(value, searchInput)" clearable @clear="clearInput"> </el-input>
      </div>
      <el-table class="select-table" ref="multipleTable" v-loading="loading" :data="tableData" height="33vh" 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" :total="total" style="margin-bottom: 0"> </dm-pagination>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="toCancel">取消</el-button>
      <el-button type="primary" @click="submitForm('ruleForm')">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import limitInput from '@/components/limit-input.vue';
import { _debounce } from '@/common/js/public';
import { postRequest } from '@/api/api';
// import showMsg from '@/common/js/showmsg';
import errMsg from '@/common/js/error';
export default {
  props: {
    brandId: {
      type: Object,
      default() {
        return '';
      }
    }
  },
  components: {
    limitInput
  },
  data() {
    return {
      wxEnterpriseRelatedId: sessionStorage.getItem('userInfos') ? JSON.parse(sessionStorage.getItem('userInfos')).wxEnterpriseId : '',
      loading: false,
      dialogVisible: true,
      tableData: [],
      searchInput: '',
      multipleSelection: [],
      // 分页参数
      currentPage: 1,
      pageSize: 20,
      total: 0
    };
  },
  methods: {
    /**
     * 多选分组
     */
    handleSelectionChange(val) {
      const that = this;
      that.multipleSelection = val;
    },
    /**
     * 输入
     */
    toInput: _debounce(function(e, value) {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    }, 500),
    // 搜索清除
    clearInput() {
      const that = this;
      that.currentPage = 1;
      that.getTableList();
    },
    toCancel() {
      const that = this;
      that.$emit('closeGroup');
      that.$refs.multipleTable.clearSelection();
    },
    handleClose(done) {
      const that = this;
      that.$emit('closeGroup');
      that.$refs.multipleTable.clearSelection();
    },
    submitForm: _debounce(function(formName) {
      const that = this;
      that.$emit('submitGroup', that.multipleSelection);
    }, 300),

    /**
     * 分页---页码变化
     * @param {Number} val
     */
    handleSizeChange(val) {
      const that = this;
      that.currentPage = 1;
      that.pageSize = val;
      that.getTableList();
    },

    /**
     * 分页---当前页变化
     * @param {Number} val
     */
    handleCurrentChange(val) {
      const that = this;
      that.currentPage = val;
      that.getTableList();
    },

    /**
     * 获取列表数据
     */
    getTableList() {
      const that = this;
      that.loading = true;
      let para = {
        memberGroupName: that.searchInput || '', // 搜索字段
        pageNum: that.currentPage, // 当前页
        pageSize: that.pageSize, // 一页显示个数
        wxEnterpriseRelatedId: that.wxEnterpriseRelatedId,
        enterpriseId: that.brandId
      };
      postRequest('/haoban-app-customer-web/memberGroup/member-tag-group-list', para)
        .then(res => {
          let resData = res.data;
          that.loading = false;
          if (resData.errorCode == 1) {
            that.tableData = resData.result.list || [];
            that.total = resData.result.pageInfo ? resData.result.pageInfo.total : 0;
            return false;
          }
          errMsg.errorMsg(resData);
        })
        .catch(function(error) {
          that.loading = false;
          that.$message.error({
            duration: 1000,
            message: error.message
          });
        });
    }
  },
  watch: {},
  mounted() {
    const that = this;
    that.getTableList();
  }
};
</script>
<style lang="scss" scoped>
.select-table-dialog {
  >>> .el-dialog__body {
    padding-top: 10px;
    padding-bottom: 10px;
  }
}
.m-b-20 {
  margin-bottom: 20px;
}
.p-l-18 {
  padding-left: 18px;
}
.w-280 {
  width: 280px;
}
.material-content {
  position: relative;
  .material-body {
    /*  resize: none;
    width: 440px;
    height: 273px;
    border-radius: 2px;
    border: 1px solid rgba(196, 198, 207, 1); */
    .el-textarea {
      >>> .el-textarea__inner {
        height: 273px;
      }
    }
  }
  .emoji-img {
    position: absolute;
    left: 10px;
    bottom: 10px;
  }
}
.el-textarea {
  >>> .el-textarea__inner {
    height: 273px;
  }
}
</style>
