<template>
  <section class="dm-wrap" v-loading="loading">
    <div class="pb20 clearfix">
      <el-input v-model="pageParams.memberInfo" class="w300" placeholder="请输入会员姓名/手机号" clearable @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
      <el-date-picker class="w250" v-model="pageParams.time" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="refresh"></el-date-picker>
      <el-input v-model="pageParams.storeName" class="w300" placeholder="请输入门店" clearable @change="refresh"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
    </div>
    <el-table tooltipEffect="light" :data="tableList" style="width: 100%">
      <el-table-column :show-overflow-tooltip="true" align="left" prop="createTime" label="签到时间">
        <template slot-scope="scope">
          <p class="cell-time">
            {{ formatDateTimeByType(scope.row.signTime, 'yyyy-MM-dd-HH-mm', true).y }}<br />
            <span>{{ formatDateTimeByType(scope.row.signTime, 'yyyy-MM-dd-HH-mm', true).h }}</span>
          </p>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" align="left" label="签到用户">
        <template slot-scope="scope">
          <div class="memberInfo">
            <img :src="scope.row.memberImage || ''" alt="" />
            <div>
              <p class="cell-memberInfo">{{ scope.row.memberName || ' - ' }}</p>
              <p class="cell-memberInfo">{{ scope.row.memberPhone || ' - ' }}</p>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" align="left" label="福利类型">
        <template slot-scope="scope"> {{ scope.prizeType === '1' ? '积分' : '卡券' }}</template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" align="left" prop="prizeTxt" label="签到福利"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" align="left" prop="storeName" label="签到门店"></el-table-column>
    </el-table>
    <dm-pagination v-show="tableList.length" background class="dm-pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageParams.currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="pageParams.pageSize" layout="total, sizes, prev, pager, next" :total="total"></dm-pagination>
  </section>
</template>

<script>
import { getPageSignLog } from '@/service/api/storeSign.js';
import { formatDateTimeByType } from '@/utils/index.js';
export default {
  name: 'sign-record',
  data() {
    return {
      loading: false,
      projectName: 'gic-web',
      pageParams: {
        currentPage: 1,
        pageSize: 20
      },
      total: 0,
      tableList: [],
      // 门店单选
      storeName: '',
      storeDialog: false
    };
  },
  created() {
    this.$store.commit('mutations_breadcrumb', [{ name: '门店签到' }, { name: '门店签到记录', path: '' }]);
    this.fetch();
  },
  methods: {
    async fetch() {
      try {
        this.loading = true;
        const params = { ...this.pageParams };
        if (this.pageParams.time) {
          params.startTime = formatDateTimeByType(params.time[0], 'yyyy-MM-dd');
          params.endTime = formatDateTimeByType(params.time[1], 'yyyy-MM-dd');
          delete params.time;
        }
        let res = await getPageSignLog(params);
        if (res.errorCode === 0 && res.result) {
          this.tableList = res.result.result || [];
          this.total = res.result.totalCount;
        } else {
          this.tableList = [];
          this.total = 0;
        }
        this.loading = false;
      } catch (err) {
        this.loading = false;
      }
    },
    refresh() {
      this.pageParams.currentPage = '1';
      this.fetch();
    },
    // 显示门店弹窗
    showStoreDialog() {
      this.storeDialog = true;
    },
    clearStoreInfo() {
      delete this.pageParams.storeId;
      this.storeName = '';
      this.refresh();
    },
    // 门店回显
    selectStore(val) {
      // 模拟检查数据
      this.pageParams.storeId = val.storeId;
      this.storeName = val.storeName || `(门店代码：${val.storeCode}）`;
      this.storeDialog = false;
      this.refresh();
    },
    formatDateTimeByType
  },
  handleSizeChange(val) {
    this.pageParams.pageSize = val;
    this.fetch();
  },
  handleCurrentChange(val) {
    this.pageParams.currentPage = val;
    this.fetch();
  }
};
</script>
<style lang="scss" scoped>
.memberInfo {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  img {
    display: block;
    width: 40px;
    height: 40px;
    margin-right: 10px;
    border-radius: 5px;
  }
  .cell-memberInfo {
    color: #606266;
    line-height: 20px;
    font-size: 14px;
  }
}
</style>
