<template>
  <div class="form-wrap">
    <el-form
      class="searchBox"
      ref="form"
      :model="form"
      :inline="true"
      label-width="100px"
    >
      <div class="block-title">
        查询条件
      </div>
      <el-form-item
        label="身份证号"
        prop="keyWords1">
        <ReaderInput v-model="form.keyWords1"></ReaderInput>
      </el-form-item>

      <el-form-item
        label="省份"
        prop="keyWords5">
        <el-select
          v-model="form.keyWords5"
          clearable
          filterable>
          <el-option
            value=""
            label="全部"></el-option>
          <el-option
            v-for="item in provinceList"
            :key="item"
            :label="item"
            :value="item">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item
        label="证件地址"
        prop="keyWords6">
        <el-input v-model="form.keyWords6"></el-input>
      </el-form-item>

      <el-form-item
        label="检票开始时间"
        prop="keyWords2"
      >
        <el-date-picker
          v-model="form.keyWords2"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item
        label="检票结束时间"
        prop="keyWords3"
      >
        <el-date-picker
          default-time="23:59:59"
          v-model="form.keyWords3"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <div class="btn-wrap">
        <el-button
          @click="reset"
        >
          重置
        </el-button>
        <el-button
          :disabled="loading"
          type="primary"
          @click="getFreeTicketList(true)"
        >
          搜索
        </el-button>
      </div>
    </el-form>

    <div class="tableBox">
      <div class="block-title">
        统计信息
      </div>
      <el-table
        stripe
        border
        v-loading="loading"
        :data="tableData">
        <el-table-column
          prop="id_card"
          label="身份证"
        >
          <template slot-scope="scope">
            {{ isPapersIdDesensitize ? $options.filters.formatIDCard(scope.row.id_card) : scope.row.id_card }}
          </template>
        </el-table-column>
        <el-table-column
          prop="id_card_address"
          label="证件地址"
        >
        </el-table-column>
        <el-table-column
          label="检票时间"
        >
          <template slot-scope="prop">
            {{ prop.row.check_time | formatTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="check_name"
          label="检票设备"
        >
        </el-table-column>
        <!-- <el-table-column
          label="操作"
          width="120"
        >
          <template slot-scope="scope">
            <el-link
              type="primary"
              @click="$refs.ticketList.show(scope.row)">
              订单详情
            </el-link>
            <el-link
              type="primary"
              v-if="!scope.row.is_invoice_picked"
              @click="pickInvoice(scope.row.id)">
              开票
            </el-link>
          </template>
        </el-table-column> -->
      </el-table>
      <el-pagination
        background
        :current-page.sync="form.pageNum"
        @current-change="getFreeTicketList()"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { apiFreeList } from '@/api/order'
import { orderStatusDic, channelList } from '@/assets/staticData'
import { getPayStatus } from '@/utils/index'
import { getProvinceList } from '@/api/visitor'
import ReaderInput from '@/components/ReaderInput'
import moment from 'moment'

export default {
  name: 'salesQuery',
  computed: {
    isPapersIdDesensitize () {
      const value = this.$store.state.app.systemConfig.find(i => i.config_key === 'papers_id_desensitize')?.config_value
      return value === '1'
    },
    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: {
        keyWords1: '', // 身份证
        keyWords2: new Date(moment().startOf('day').valueOf()),
        keyWords3: new Date(moment().endOf('day').valueOf()),
        keyWords5: '', // 状态
        keyWords6: '', // 1散客 2团体
        keyWords7: '', // 票号
        keyWords8: null,
        keyWords9: '', // 售票员
        keyWords10: '',
        keyWords11: '',
        keyWords12: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      loading: false,
      provinceList: []
    }
  },
  created () {
    const searchParams = JSON.parse(sessionStorage.getItem('统计表-免票记录-の查询条件'))
    if (searchParams) {
    // 如果存在查询条件，则设置到组件的数据中
      this.form = searchParams // 记住上次搜索条件
    }
    this.getFreeTicketList()
    this.getProvinceList()
  },
  methods: {
    getPayStatus,
    reset () {
      this.$refs.form.resetFields()
    },
    getFreeTicketList (goFirst) {
      this.loading = true
      goFirst && (this.form.pageNum = 1)
      apiFreeList(this.form).then(res => {
        this.total = res.total
        this.tableData = res.list
      }).finally(() => {
        this.loading = false
        sessionStorage.setItem('统计表-免票记录-の查询条件', JSON.stringify(this.form)) // 下次记住
      })
    },
    getProvinceList () {
      getProvinceList().then((res) => {
        this.provinceList = res?.data
      })
    }
  }
}
</script>

<style scoped>

</style>
