<template>
       
<div >
    <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"> </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="659"
      >
        <el-table-column
          prop="createTime"
          label="时间"
          min-width="155px"
        >
        <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"></el-table-column>
        <el-table-column
          prop="brandName"
          label="来源品牌"
          min-width="150px"
        >
        <template slot-scope="scope">
            <div class="integral-box text-ellipsis-2 line-20">{{ scope.row.brandName || '--'}}</div>
        </template>
        </el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
          min-width="160px"
        >
        <template slot-scope="scope">
            <div class="integral-box text-ellipsis-2 line-20">{{ scope.row.remark }}</div>
        </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 {
      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: [
        // {createTime:12334494943,intervalInout:1,memberIntegralName:'新增其他',intervalHistory:1333,sourceType:1}
      ],
      form:{
        intervalInOut: -1,
        dictCode: -1,
        sourceType: -1,
        frozenStatus:-1,
      },
    };
  },
  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() {
      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]
      // console.log(para);
      doFetch(url.enterpriseIntegralDetailData, para)
        .then(res => {
          if (res.data.errorCode === 0) {
            this.memberData =
              res.data.result.page.result 
              // &&
              // res.data.result.page.result.map(ele => ({
              //   ...ele,
              //   mainStoreName: !!ele.mainStoreName ? ele.mainStoreName : "--",
              //   openStoreName: !!ele.openStoreName ? ele.openStoreName : "--"
              // }));
            this.page.currentPage = res.data.result.page.currentPage;
            this.page.totalCount = res.data.result.page.totalCount;
          } else {
            checkFalse(res.data.message);
          }
        })
        .catch(err => {
          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="stylus">
.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;
}
</style>
