<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :span="6">
              <a-form-item label="操作类型" prop="operType">
                <a-select placeholder="请选择操作类型" v-model="queryParam.operType" style="width: 100%" allow-clear :filterOption="filterOption4" showSearch>
                  <a-select-option v-for="(d1, index1) in dict.type.key_box_oper_type" :key="index1" :value="d1.value">{{
                    d1.label
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="操作的钥匙柜" prop="boxId">
                <a-select placeholder="请选择操作的钥匙柜" v-model="queryParam.boxId" style="width: 100%" allow-clear :filterOption="filterOption1" showSearch>
                  <a-select-option v-for="(d, index) in boxList" :key="index+ '-only'" :value="d.value">{{
                    d.label
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="车牌号码" prop="carId">
                <a-select placeholder="请选择车牌号码" v-model="queryParam.carId" style="width: 100%" allow-clear :filterOption="filterOption2" showSearch>
                  <a-select-option v-for="(d2, index2) in carList" :key="index2+ '-only2'" :value="d2.value">{{
                    d2.label
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <template>
              <a-col :span="6">
                <a-form-item label="操作时间">
                  <a-range-picker
                    style="width: 100%"
                    v-model="daterangeOperTime"
                    valueFormat="YYYY-MM-DD"
                    format="YYYY-MM-DD"
                    allow-clear
                  />
                </a-form-item>
              </a-col>
              <a-col :span="5">
                <a-form-item label="操作人" prop="operUserId">
                  <a-select :filterOption="filterOption" placeholder="请选择操作人" v-model="queryParam.operUserId" style="width: 100%" allow-clear showSearch >
                  <a-select-option v-for="(d3, index3) in popList" :key="index3+ '-only3'" :value="d3.value">{{
                    d3.label
                  }}</a-select-option>
                </a-select>
                </a-form-item>
              </a-col>
            </template>
            <a-col :md="(!advanced && 8) || 24" :sm="24">
              <span
                class="table-page-search-submitButtons"
                :style="(advanced && { float: 'right', overflow: 'hidden' }) || {}"
              >
                <a-button type="primary" @click="handleQuery"><a-icon type="search" />查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQuery"><a-icon type="redo" />重置</a-button>
                <!-- <a @click="toggleAdvanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a> -->
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 操作 -->
      <div class="table-operations">
        <!-- <a-button type="danger" :disabled="multiple" @click="handleDelete" v-hasPermi="['clw:keyCaseOperLog:remove']">
          <a-icon type="delete" />删除
        </a-button> -->
        <!-- <a-button type="primary" @click="handleExport" v-hasPermi="['clw:keyCaseOperLog:export']">
          <a-icon type="download" />导出
        </a-button> -->
        <!-- <table-setting
          :style="{ float: 'right' }"
          :table-size.sync="tableSize"
          v-model="columns"
          :refresh-loading="loading"
          @refresh="getList"
        /> -->
      </div>
      <CreateForm
        ref="createForm"
        @ok="getList"
      />
      <!-- 数据展示 -->
      <a-table
        :loading="loading"
        :size="tableSize"
        rowKey="id"
        :columns="columns"
        :data-source="list"
        :pagination="false"
        :bordered="tableBordered"
      >
        <span slot="num" slot-scope="text, records, index">
          {{ (queryParam.pageNum - 1) * queryParam.pageSize + Number(index) + 1 }}
        </span>
        <span slot="operType" slot-scope="text, record">
          <dict-tag :options="dict.type['key_box_oper_type']" :value="record.operType" />
        </span>
        <span slot="operTime" slot-scope="text, record">
          {{ parseTime(record.operTime) }}
        </span>
        <!-- <a @click="$refs.createForm.handleInfo(record, undefined)" v-hasPermi="['clw:oilSkimmingLog:edit']">
            <a-icon type="eye" />详情
          </a> -->
      </a-table>
      <!-- 分页 -->
      <a-pagination
        class="ant-table-pagination"
        show-size-changer
        show-quick-jumper
        :current="queryParam.pageNum"
        :total="total"
        :page-size="queryParam.pageSize"
        :showTotal="(total) => `共 ${total} 条`"
        @showSizeChange="onShowSizeChange"
        @change="changeSize"
      />
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { listKeyCaseOperLog, delKeyCaseOperLog,getKeyCaseBoxInfo ,getKeyCaseCarInfo,getKeyCaseUserInfo} from '@/api/clw/keyCaseOperLog'
import CreateForm from './modules/CreateForm'
import { tableMixin } from '@/store/table-mixin'

export default {
  name: 'KeyCaseOperLog',
  components: {CreateForm},
  mixins: [tableMixin],
  dicts: ['key_box_oper_type'],
  data() {
    return {
      list: [],
      selectedRowKeys: [],
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      ids: [],
      loading: false,
      total: 0,
      // 钥匙柜名称时间范围
      daterangeOperTime: [],
      // 查询参数
      queryParam: {
        boxId: null,
        operType: null,
        operTime: null,
        operUserId: null,
        carId: null,
        pageNum: 1,
        pageSize: 10,
      },
      columns: [
      { title: '序号', scopedSlots: { customRender: 'num' },width:'50px',   align: 'center', },
        {
          title: '钥匙柜名称',
          dataIndex: 'boxName',
          ellipsis: true,
          align: 'center',
          width: '100px',
        },
        {
          title: '操作用户',
          dataIndex: 'operUserName',
          ellipsis: true,
          align: 'center',
          width: '100px',
     
        },
        {
          title: '操作类型',
          dataIndex: 'operType',
          scopedSlots: { customRender: 'operType' },
          ellipsis: true,
          align: 'center',
          width: '100px',

        },
        {
          title: '操作时间',
          dataIndex: 'operTime',
          scopedSlots: { customRender: 'operTime' },
          ellipsis: true,
          align: 'center',
          width: '150px',
         
        },

        {
          title: '车牌号',
          dataIndex: 'plateNumber',
          ellipsis: true,
          align: 'center',
          width: '100px',
        },

        {
          title: '备注',
          dataIndex: 'remark',
          ellipsis: true,
          align: 'center',
          width: '220px',
        },
        // {
        //   title: '操作',
        //   dataIndex: 'operation',
        //   width: '10%',
        //   scopedSlots: { customRender: 'operation' },
        //   align: 'center',
        // },
      ],
      boxList: [],
      carList: [],
      popList:[],
      operName:''
    }
  },
  filters: {},
  created() {  
    this.getList()
  },
  mounted(){
    this.getBoxList()
    this.getPlapentNum()
    this.getUserList()
  },
  computed: {},
  watch: {},
  methods: {
    /** 查询钥匙柜操作记录列表 */
    getList() {
      this.loading = true
      this.queryParam.params = {}
      if (this.daterangeOperTime !== null && this.daterangeOperTime !== '' && this.daterangeOperTime.length !== 0) {
        this.queryParam.params['beginOperTime'] = `${this.daterangeOperTime[0]} 00:00:00`
        this.queryParam.params['endOperTime'] = `${this.daterangeOperTime[1]} 23:59:59`
      }
      listKeyCaseOperLog(this.queryParam).then((response) => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParam.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeOperTime = []
      this.queryParam = {
        boxId: null,
        operType: null,
        operUserId: null,
        pageNum: 1,
        pageSize: 10,
      }
      this.getList()
    },
    onShowSizeChange(current, pageSize) {
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    changeSize(current, pageSize) {
      this.queryParam.pageNum = current
      this.queryParam.pageSize = pageSize
      this.getList()
    },
    // onSelectChange(selectedRowKeys, selectedRows) {
    //   this.selectedRowKeys = selectedRowKeys
    //   this.selectedRows = selectedRows
    //   this.ids = this.selectedRows.map((item) => item.boxId)
    //   this.single = selectedRowKeys.length !== 1
    //   this.multiple = !selectedRowKeys.length
    // },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   var that = this
    //   const boxIds = row.boxId || this.ids
    //   this.$confirm({
    //     title: '确认删除所选中数据?',
    //     content: '当前选中编号为' + boxIds + '的数据',
    //     onOk() {
    //       return delKeyCaseOperLog(boxIds).then(() => {
    //         that.onSelectChange([], [])
    //         that.getList()
    //         that.$message.success('删除成功', 3)
    //       })
    //     },
    //     onCancel() {},
    //   })
    // },
    /** 导出按钮操作 */
    handleExport() {
      var that = this
      this.$confirm({
        title: '是否确认导出?',
        content: '此操作将导出当前条件下所有数据而非选中数据',
        onOk() {
          that.download(
            'clw/keyCaseOperLog/export',
            {
              ...that.queryParam,
            },
            `keyCaseOperLog_${new Date().getTime()}.xlsx`
          )
        },
        onCancel() {},
      })
    },
    // 钥匙柜下拉
    getBoxList(){
      getKeyCaseBoxInfo().then(res=>{
        this.boxList=res.data
      })
    },
    getPlapentNum(){
      getKeyCaseCarInfo().then(res=>{
        this.carList=res.data

      })
    },
    getUserList(){
      getKeyCaseUserInfo().then(res=>{
        this.popList=res.data
     
      })
    },
 
    filterOption (value, option) {
      return option.componentOptions.children[0].text.indexOf(value) >= 0
    },
    filterOption1(value1, option1) {
      return option1.componentOptions.children[0].text.indexOf(value1) >= 0
    },
    filterOption2(value2, option2) {
      return option2.componentOptions.children[0].text.indexOf(value2) >= 0
    },
    filterOption4(value3, option3) {
      return option3.componentOptions.children[0].text.indexOf(value3) >= 0
    },
  },
}
</script>
