<template>
 <div class="integral-tab m20" >
  <el-tabs v-model="activeName">
    <el-tab-pane label="积分明细" name="first" >
      <p class="font14 tip-p">展示近两年的积分明细</p>
       <div class="wechat-point-details">
    <div class="search-top mBottom20">
      <div class="left-search-wrap">
        <el-select
          v-model="intervalInOut"
          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="dictCode"
          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 v-model="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 v-model="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
        v-if="getCodeAuth('memberAdjustIntegral')"
        type="primary"
        :limit-code="getCode('memberAdjustIntegral')"
        @click="linkRoute('/modifyintegral')"
      >调整积分</el-button>
    </div>
    <div class="table-content">
      <el-table
        :data="memberData"
        tooltip-effect="dark"
        ref="multipleTable"
      >
        <el-table-column
          prop="callBeginTime"
          label="时间"
          min-width="155px"
        >
          <template slot-scope="scope">
            {{ scope.row.createTime | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="intervalInout"
          label="日志类型"
          min-width="80px"
        >
          <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="intervalHistory"
          label="日志详情"
          min-width="80px"
        >
          <template slot-scope="scope">
            <span :style="{color: scope.row.intervalHistory > 0 ? 'green' : 'red'}">{{ scope.row.intervalHistory }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="frozenStatus"
          label="积分状态"
          min-width="80px"
        >
         <template slot-scope="{row}">
            <span>{{  row.frozenStatus==1?'冻结':'可用' }}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="memberIntegralName"
          label="事由"
          min-width="80px"
        ></el-table-column>
        <el-table-column prop="sourceType" label="来源渠道" min-width="80px" :formatter="formatSourceType"></el-table-column>
        <el-table-column
          prop="remark"
          label="备注"
          min-width="160px"
        ></el-table-column>
        <el-table-column
          prop="mainStoreName"
          label="服务门店"
          min-width="160px"
        ></el-table-column>
        <el-table-column
          prop="openStoreName"
          label="开卡门店"
          min-width="160px"
        ></el-table-column>
        <el-table-column
          prop="intervalEffect"
          label="积分成本主体"
          min-width="110px"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.intervalInout == 0">--</span>
            <span v-if="scope.row.intervalInout == 1">{{scope.row.mainPartStoreName ? scope.row.mainPartStoreName : '--'}}</span>
          </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>
    <el-dialog
      title="积分扣除来源"
      :visible.sync="loseVisible"
      width="60%"
      :close-on-click-modal="false"
    >
      <div class="lose-dilog">
        <el-table
          :data="loseData"
          tooltip-effect="dark"
          ref="multipleTable"
        >
          <el-table-column
            prop="createTime"
            label="日期"
            width="200"
          >
            <template slot-scope="scope">
              {{ scope.row.createTime}}
            </template>
          </el-table-column>
          <el-table-column
            prop="intervalHistory"
            label="日志详情"
          >
            <template slot-scope="scope">
              <span :style="{color: scope.row.intervalHistory > 0 ? 'green' : 'red'}">{{ scope.row.intervalHistory }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="memberIntegralName"
            label="事由"
          ></el-table-column>
          <el-table-column
            prop="mainPartStoreName"
            label="积分成本主体"
          >
            <template slot-scope="scope">
              <span>{{scope.row.mainPartStoreName ? scope.row.mainPartStoreName : '--'}}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="sourceIntegralChange"
            label="扣除积分值"
          >
            <template slot-scope="scope">
              <span style="color: red">{{ scope.row.sourceIntegralChange }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="intervalEffect"
            label="积分剩余值"
          ></el-table-column>
        </el-table>
      </div>
      <span
        slot="footer"
        class="dilog-footer"
      >
        <el-button @click="loseVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="loseVisible = false"
        >确 定</el-button>
      </span>
    </el-dialog>

    <!-- <div class="footer-box">
      <vue-gic-footer></vue-gic-footer>
    </div> -->
  </div>
    </el-tab-pane>
    <el-tab-pane label="预扣明细" name="second">
        <p class="font14 tip-p">展示近两年的预扣明细</p>
        <enterprise-intergral-withhold :member-id="memberId"></enterprise-intergral-withhold>
      </el-tab-pane>
  </el-tabs>
 </div>
</template>

<script>
import mixin from './integralMixin';
import enterpriseIntergralWithhold from './enterpriseIntergralWithhold.vue';
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 { formatLongTime } from "@/utils/utils";
import authMethods from '@/mixins/auth';
export default {
  name: "talkLogPage",
  data() {
    return {
      activeName: 'first',
      loseVisible: false,
      loseData: [],
      memberId: this.$route.query.memberId || "",
      page: {
        currentPage: 1,
        pageSize: 20,
        totalCount: 0
      },
      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: [],
      intervalInOut: -1,
      dictCode: -1,
      searchType: 1,
      sourceType: -1,
      frozenStatus:-1,
      beginTime: "",
      endTime: "",
      storeName: "",
      dilogPlayVisible: false,
      curRecordUrl: "",
      dictList: [],
      dilogIntegralVisible: false,
      integralFlag: ""
    };
  },
  mixins: [authMethods, 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();
    },
    goback() {
      this.$router.push({
        path: "wechatmemberDetail",
        query: { memberId: this.memberId }
      });
    },
    // 扣除积分详情
    detaliInfo(id) {
      doFetch("/api-member/member-integral-source", {
        intervalLogId: id
      }).then(res => {
        if (res.data.errorCode === 0) {
          this.loseData = res.data.result.intervalDetailList.map(ele => ({
            ...ele,
            createTime:
              ele.createTime != -1 ? formatLongTime(ele.createTime, 1) : "--"
          }));
          this.loseVisible = true;
        }
      });
    },
    getIntegralDataPage() {
      doFetch(url.integralDataPage, {
        memberId: this.memberId,
        pageSize: this.page.pageSize,
        currentPage: this.page.currentPage,
        intervalInOut: this.intervalInOut,
        dictCode: this.dictCode,
        searchType: this.searchType,
        sourceType: this.sourceType,
        beginTime: this.dateDefault[0],
        endTime: this.dateDefault[1],
        storeName: this.storeName,
        frozenStatus:this.frozenStatus
      })
        .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);
        });
    },
    getEnterpriseInfo() {
      doFetch(url.enterpriseInfo)
        .then(res => {
          if (res.data.errorCode == 0) {
            this.integralFlag = res.data.result.enterpriseInfo.integralFlag;
          } else {
            checkFalse();
          }
        })
        .catch(err => {
          checkStatus(err);
        });
    }
  },
  created() {
    this.setDefalutTime()
    if (this.memberId) {
      this.getIntegralDataPage();
      this.getIntegralOperateType();
    }
    this.$store.commit("mutations-slide", false);
  },
  components: {
    "v-nav": nav,
    searchinput,
    enterpriseIntergralWithhold
  }
};
</script>

<style lang="stylus">
.m20 {
  margin: 20px;
  margin-top: 0px;
}
.tip-p{
    color: #6B6D71;
    padding-bottom: 16px;
}
.clerk {
  display: flex;
  align-items: center;
  justify-content: center;
}

.clerkimg {
  flex: 0 0 60px;
  width: 60px;
}

.clerkname {
  flex: 1;
  margin-left: 5px;
}

.wechat-point-details {
  overflow: auto;
}

.footer-box {
  margin-top: -112px;
}
.search-top{
  display: flex;
  justify-content:space-between;
  align-items:center;
  .left-search-wrap{
    display: flex;
    align-items:center;
    gap:10px;
  }
}
.integral-tab {
  height: 100%;
  // position: fixed;
  /deep/ .el-tabs__header {
    margin-bottom: 16px;
    .el-tabs__nav-wrap {
      padding: 0 20px;
    }
  }
  /deep/ .el-tabs__content {
    padding: 0 20px 20px;
    height: calc(100% - 60px);
    overflow-y: auto;
    box-sizing: border-box;
  }
}
</style>
