<template>
  <section class="dm-wrap" v-loading="loading">
    <div class="pb22 clearfix">
      <el-date-picker class="w400" v-model="dateTime" type="daterange" range-separator="至" start-placeholder="扫码开始时间" end-placeholder="扫码结束时间" @change="search"></el-date-picker>
      <el-input v-model="listParams.search" class="w200" placeholder="输入会员信息" clearable @change="search"><i slot="prefix" class="el-input__icon el-icon-search"></i></el-input>
    </div>
    <el-table tooltipEffect="light" :data="tableList" style="width: 100%" element-loading-text="拼命加载中">
      <el-table-column label="扫码时间" align="left" min-width="130">
        <template slot-scope="scope">
          <p class="cell-time">
            {{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).y }}<br />
            <span>{{ formatDateTimeByType(scope.row.createTime, 'yyyy-MM-dd-HH-mm-ss', true).h }}</span>
          </p>
        </template>
      </el-table-column>
      <el-table-column min-width="120" align="left" prop="memberName" label="用户">
        <template slot-scope="scope">
          <a :href="'/member/#/wechatmemberDetail?memberId=' + scope.row.memberId" target="_blank">
            <img class="vertical-middle table__avatar--40" :src="scope.row.imageUrl || defaultAvatar" width="60" height="60" />
            <div class="inline-block vertical-middle">
              <p class="table-name--ellipsis">{{ scope.row.memberName || '--' }}</p>
              <p class="fz13 gray">{{ scope.row.phoneNumber || '--' }}</p>
            </div>
          </a>
        </template>
      </el-table-column>
      <el-table-column label="二维码信息" align="left" min-width="150">
        <template slot-scope="scope">
          <div>门店：{{ scope.row.scanStoreName || '--' }}</div>
          <div>导购：{{ scope.row.scanClerkName || '--' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="匹配扫码营销计划" align="left" min-width="140">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="
              () => {
                if (scope.row.ecmPlanId) {
                  $router.push({ name: 'scanInfo', query: { new: 1 }, params: { id: scope.row.ecmPlanId, path: '/scan/list' } });
                }
              }
            "
            >{{ scope.row.ecmPlanName || '--' }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <dm-pagination v-show="tableList.length" background class="dm-pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listParams.currentPage" :page-sizes="[20, 40, 60, 80]" :page-size="listParams.pageSize" layout="total, sizes, prev, pager, next" :total="total"></dm-pagination>
  </section>
</template>
<script>
import { formatDateTimeByType } from '@/utils/index.js';
import { listEcmScanLogPage } from '@/service/api/ecmApi.js';
export default {
  name: 'scan-list',
  data() {
    return {
      dateTime: [],
      listParams: {
        search: '',
        currentPage: 1,
        pageSize: 20,
        beginTime: '',
        endTime: ''
      },
      total: 0,
      loading: false,
      tableList: []
    };
  },
  created() {
    this.getTableList();
  },
  methods: {
    formatDateTimeByType,
    search() {
      this.listParams.currentPage = 1;
      this.getTableList();
    },
    handleSizeChange(val) {
      this.listParams.pageSize = val;
      this.getTableList();
    },
    handleCurrentChange(val) {
      this.listParams.currentPage = val;
      this.getTableList();
    },
    async getTableList() {
      if (this.dateTime) {
        this.listParams.beginTime = formatDateTimeByType(this.dateTime[0], 'yyyy-MM-dd');
        this.listParams.endTime = formatDateTimeByType(this.dateTime[1], 'yyyy-MM-dd');
      } else {
        this.listParams.beginTime = '';
        this.listParams.endTime = '';
      }
      this.loading = true;
      try {
        let res = await listEcmScanLogPage(this.listParams);
        this.tableList = res.result.result || [];
        this.total = res.result.totalCount;
        this.loading = false;
      } catch (error) {
        this.loading = false;
      }
    }
  }
};
</script>
