<template>
  <div class="form-wrap">
    <el-form
      class="search-box"
      ref="form"
      :model="form"
      :inline="true"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="身份证号"
        prop="idcard">
        <ReaderInput v-model="form.idcard"></ReaderInput>
      </el-form-item>
      <el-form-item
        label="姓名">
        <el-input v-model="form.name"></el-input>
      </el-form-item>
      <el-form-item
        label="手机号">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getVisitorList(true)"
        >
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="table-box">
      <!-- <div class="block-title">
        统计信息
      </div> -->
      <el-table
        stripe
        border
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="name"
          label="姓名"
          width="120">
        </el-table-column>
        <el-table-column
          prop="idcard"
          label="身份证"
        >
        </el-table-column>
        <el-table-column
          prop="province"
          label="省份"
        ></el-table-column>
        <el-table-column
          prop="cityCode"
          label="市级编码"
        ></el-table-column>
        <el-table-column
          prop="birthDate"
          label="出生日期"
        ></el-table-column>
        <el-table-column
          prop="gender"
          label="性别"
        >
          <template slot-scope="scope">
            {{ scope.row.gender === 1 ? '男' : scope.row.gender === 0 ? '女' : '-' }}
          </template>
        </el-table-column>
        <el-table-column
          prop="age"
          label="年龄"
        ></el-table-column>
        <el-table-column
          prop="phone"
          label="手机号"
        ></el-table-column>
        <el-table-column
          prop="imageUrl"
          label="图片地址"
          width="120">
        </el-table-column>
        <el-table-column
          label="操作"
          width="120"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="deleteRecord(scope.row.id)">
              删除
            </el-link>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="form.pageSize"
        @size-change="handleSizeChange"
        @current-change="getVisitorList()"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { apiVisitorList, deleteVisitorRecord } from '@/api/order'
import { orderStatusDic, channelList } from '@/assets/staticData'
import { getPayStatus } from '@/utils/index'
import ReaderInput from '@/components/ReaderInput'

export default {
  name: 'freeQuery',
  computed: {
    salesList () {
      return this.$store.state.user.salesList
    },
    saleChannel () {
      return this.$store.state.app.saleChannel
    },
    payChannelOptions () {
      return this.$store.getters.payChannelOptions
    },
    ticketTypeList () {
      return this.$store.state.app.ticketTypeList
    },
    scenicList () {
      return this.$store.state.app.scenicList
    }
  },
  components: {
    ReaderInput
  },
  data () {
    return {
      channelList,
      orderStatusDic,
      form: {
        idcard: '', // 身份证
        name: '', // 姓名
        phone: '', // 手机号
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      deviceList: []
    }
  },
  created () {
    this.getVisitorList()
  },
  methods: {
    getPayStatus,
    reset () {
      this.$refs.form.resetFields()
    },
    handleSizeChange (size) {
      this.form.pageSize = size
      this.getVisitorList()
    },
    getVisitorList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)

      apiVisitorList(this.form).then(res => {
        this.total = res.data.total
        this.tableData = res.data.records
      }).finally(() => {
        this.loading = false
      })
    },
    deleteRecord (id) {
      this.$confirm('是否删除该记录？', '提示', {
        type: 'warning'
      }).then(() => {
        deleteVisitorRecord(id).then(() => {
          this.$message.success('删除成功')
          this.getVisitorList()
        })
      }).catch(() => {
        // 取消删除
      })
    }
  }
}
</script>

<style scoped>

</style>
