<template>
       
<div v-loading="loading">
    <div class="search-top mBottom20">
      <div class="left-search-wrap">
        <el-select
          v-model="form.intervalInOut"
          class="width160"
          placeholder="所有日志"
          @change="handleSearch"
        >
          <el-option
            :key=-1
            label="所有日志"
            :value=-1
          ></el-option>
          <el-option
            :key=1
            label="积分获取"
            :value=1
          ></el-option>
          <el-option
            :key=2
            label="积分扣除"
            :value=2
          ></el-option>
        </el-select>
        <el-select
          v-model="form.dictCode"
          class="width160"
          placeholder="所有事由"
          @change="handleSearch"
        >
          <el-option
            :key=-1
            label="所有事由"
            :value=-1
          ></el-option>
          <el-option
            v-for="item in dictList"
            :key="item.dictCode"
            :label="item.dictName"
            :value="item.dictCode"
          ></el-option>
        </el-select>
        <el-select class="width160" v-model="form.sourceType" placeholder="所有来源渠道" @change="handleSearch">
          <el-option label="所有来源渠道" :value=-1></el-option>
          <el-option v-for="item in sourceTypeList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-select class="width160" v-model="form.frozenStatus" placeholder="所有积分状态" @change="handleSearch">
          <el-option label="所有积分状态" :value=-1></el-option>
          <el-option v-for="item in frozenStatusList" :key="item.value" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-date-picker style="width: 256px;" v-model="dateDefault" type="daterange" range-separator="~" start-placeholder="创建开始日期" end-placeholder="创建结束日期" :default-time="['00:00:00', '23:59:59']" :picker-options="pickerOptions()" value-format="yyyy-MM-dd" @change="handleSearch" :clearable="false"> </el-date-picker>
      </div>
      <el-button
        type="primary"
        @click="linkRoute('/integralDataPage')"
      >查看品牌积分</el-button>
    </div>
    <div class="table-content">
      <el-table
        :data="memberData"
        tooltip-effect="dark"
        ref="multipleTable"
        :max-height="height"
      >
        <el-table-column
          prop="createTime"
          label="时间"
          min-width="130px"
        >
        <template slot-scope="scope">
            <div class="line-20">{{ scope.row.createTime | formatYMD }}</div>
            <div class="line-20">{{ scope.row.createTime | formatHMS }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="intervalInout"
          label="日志类型"
          min-width="90px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.intervalInout == 1">积分获取</span>
            <span v-if="scope.row.intervalInout == 0">积分扣除</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="memberIntegralName"
          label="事由"
          min-width="90px"
        ></el-table-column>
        <el-table-column
          prop="intervalHistory"
          label="日志详情"
          min-width="90px"
        ></el-table-column>
        <el-table-column prop="sourceType" label="来源渠道" min-width="90px" :formatter="formatSourceType" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="brandName"
          label="来源品牌"
          min-width="150px"
        >
        <template slot-scope="scope">
          <el-tooltip placement="top">
              <div slot="content">
                <p>{{scope.row.brandName}}</p>
              </div>
              <div class="integral-box text-ellipsis-2 line-20">{{ scope.row.brandName }}</div>
          </el-tooltip>
        </template>
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
          min-width="160px"
        >
        <template slot-scope="scope">
          <el-tooltip placement="top">
              <div slot="content">
                <p>{{scope.row.remark}}</p>
              </div>
              <div class="integral-box text-ellipsis-2 line-20">{{ scope.row.remark }}</div>
          </el-tooltip>
        </template>
        </el-table-column>
      </el-table>
      <div
        class="page mTop20"
      >
        <dm-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="page.currentPage"
          :page-sizes="[20, 40, 60, 80]"
          :page-size="page.pageSize"
          layout="total, sizes, prev, pager, next"
          :total="page.totalCount"
        >
        </dm-pagination>
      </div>
    </div>
</div>

</template>

<script>
import mixin from './integralMixin';
import nav from "../../common/navbar/navbar.vue";
import { doFetch } from "../../components/axios/api";
import url from "../../components/axios/url";
import {
  checkFalse,
  checkStatus
} from "../../../static/js/checkStatus";
// import searchinput from "common/searchinput";
// import authMethods from '@/mixins/auth';
export default {
  name: "enterpriseIntegralDetial",
  props:{
    memberId:{
      type: String,
      default() {
        return '';
      }
    }
  },
  components: {
    "v-nav": nav,
    // searchinput
  },
  data() {
    return {
      height: document.body.clientHeight - 262,
      page: {
        currentPage: 1,
        pageSize: 20,
        totalCount: 0
      },
      dictList: [],
      sourceTypeList: [
        { label: 'GIC计算', value: 1 },
        { label: 'ERP同步', value: 2 },
        { label: 'API同步', value: 3 },
        { label: '批处理导入', value: 4 },
        { label: '天猫会员通', value: 5 },
        { label: '抖音', value: 7 }
      ],
      frozenStatusList:[
        {label:'冻结积分',value:1},
        {label:'可用积分',value:0}
      ],
      memberData: [],
      form:{
        intervalInOut: -1,
        dictCode: -1,
        sourceType: -1,
        frozenStatus:-1,
      },
      loading: false
    };
  },
  mixins: [mixin],
  methods: {
    formatSourceType(row, col, val) {
      const type = this.sourceTypeList.find(el => el.value == val) || {};
      return type.label || '--';
    },
    linkRoute(route) {
      this.$router.push({ path: route, query: { memberId: this.memberId } });
    },
    handleSearch() {
      this.page.currentPage = 1;
      this.getIntegralDataPage();
    },
    handleCurrentChange(val) {
      this.page.currentPage = val;
      this.getIntegralDataPage();
    },
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getIntegralDataPage();
    },
    getIntegralDataPage() {
      this.loading = true;
      console.log(this.dateDefault);
      if(!this.dateDefault) this.dateDefault = ['', ''];
      let para = this.form
      para['memberId'] = this.memberId
      para['pageSize'] = this.page.pageSize
      para['currentPage'] = this.page.currentPage
      para['beginTime'] = this.dateDefault[0]
      para['endTime'] = this.dateDefault[1]
      doFetch(url.enterpriseIntegralDetailData, para)
        .then(res => {
          if (res.data.errorCode === 0) {
            this.memberData = res.data.result.page.result;
            this.page.currentPage = res.data.result.page.currentPage;
            this.page.totalCount = res.data.result.page.totalCount;
          } else {
            checkFalse(res.data.message);
          }
          this.loading = false;
        })
        .catch(err => {
          this.loading = false;
          checkStatus(err);
        });
    },
    getIntegralOperateType() {
      doFetch(url.integralOperateType, {
        businessType: "member_integral",
        dictStatus: 0
      })
        .then(res => {
          if (res.data.errorCode === 0) {
            res.data.result.dictList.forEach(ele => {
              if (ele.dictCode == "1113") {
                // 占位
              }
            });
            this.dictList = res.data.result.dictList;
          } else {
            checkFalse();
          }
        })
        .catch(err => {
          checkStatus(err);
        });
    },
  },
  created() {
    this.setDefalutTime()
    if (this.memberId) {
      this.getIntegralDataPage();
      this.getIntegralOperateType();
    }
  },
};
</script>

<style lang="scss">
.search-top{
  display: flex;
  justify-content:space-between;
  align-items:center;
  .left-search-wrap{
    display: flex;
    align-items:center;
    gap:10px;
  }
}
.width160{
    width: 160px;
}
.w256{
    width: 256px;
}
.wechat-point-details {
  overflow: auto;
}
.line-20{
    line-height: 20px;
}
.integral-box{
    display: flex;
    align-items: center;
}
.text-ellipsis-2 {
    overflow: hidden;
    -webkit-line-clamp: 2;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
}
</style>
