<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="检查人员" prop="inspectUserName">
        <el-input v-model="queryParams.inspectUserName" placeholder="请输入检查人员" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="查获时间" prop="seizureTime">
        <!-- <el-date-picker clearable v-model="queryParams.seizureTime" type="date" value-format="YYYY-MM-DD"
          placeholder="请选择查获时间"> 
        </el-date-picker>-->
        <el-date-picker clearable v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
          start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="安检位置" prop="regionalName">
        <el-input v-model="queryParams.regionalName" placeholder="请输入安检位置" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="查获班组" prop="inspectTeamName">
        <el-input v-model="queryParams.inspectTeamName" placeholder="请输入查获班组" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="流程状态" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="请选择流程状态" clearable style="width: 200px">
          <el-option v-for="dict in process_status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="开机指令" prop="powerOnInstruction">
        <el-select v-model="queryParams.powerOnInstruction" placeholder="请选择开机指令" clearable style="width: 200px">
          <el-option label="指令" :value="0" />
          <el-option label="非指令" :value="1" />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="违禁类型" prop="forbiddenTypeText">
        <el-input v-model="queryParams.forbiddenTypeText" placeholder="请输入违禁品类型" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="查获部位" prop="checkPositionSpecific">
        <el-input v-model="queryParams.checkPositionSpecific" placeholder="请输入查获部位" clearable
          @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="处理方式" prop="handlingMethodDesc">
        <el-input v-model="queryParams.handlingMethodDesc" placeholder="请输入处理方式" clearable @keyup.enter="handleQuery" />
      </el-form-item>

      <el-form-item label="是否有意隐匿" prop="regionalName">
        <el-input v-model="queryParams.inspectTeamName" placeholder="请输入通道名称" clearable @keyup.enter="handleQuery" />
      </el-form-item> -->



      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['item:record:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
          v-hasPermi="['item:record:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['item:record:remove']">删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport"
          v-hasPermi="['item:record:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="安检员" align="center" prop="inspectUserName" />
      <el-table-column label="查获时间" align="center" prop="seizureTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.seizureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="安检位置" align="center" prop="regionalName">
        <template #default="scope">
          <span>{{ `${scope.row.terminlName}/${scope.row.regionalName}/${scope.row.channelName}` }}</span>
        </template>
      </el-table-column>
      <el-table-column label="安检岗位" align="center" prop="checkMethodDesc" />
      <el-table-column label="查获班组" align="center" prop="inspectTeamName" />
      <el-table-column label="上报班组" align="center" prop="attendanceTeamName" />
      <el-table-column label="流程状态" align="center" prop="processStatus">
        <template #default="scope">
          <dict-tag :options="process_status" :value="scope.row.processStatus" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="违禁品类型" align="center" prop="categoryNameTwo" />
      <el-table-column label="数量" align="center" prop="quantity" />
      <el-table-column label="查获部位" align="center" prop="customLocation" />
      <el-table-column label="具体位置" align="center" prop="checkPositionSpecific" />
      <el-table-column label="处理方式" align="center" prop="handlingMethodDesc" />
      <el-table-column label="是否有意隐匿" align="center" prop="isActiveConcealment" />
      <el-table-column label="旅客姓名" align="center" prop="passengerName" />
      <el-table-column label="旅客身份证号" align="center" prop="passengerCard" />
      <el-table-column label="航班号" align="center" prop="passengerFlight" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <!-- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['item:record:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['item:record:remove']">删除</el-button> -->
          <el-button link type="info" icon="View" @click="handleDetail(scope.row)"
            v-hasPermi="['check:checkRecord:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改查获记录对话框 -->
    <el-dialog :title="title" v-model="open" width="800px" append-to-body>
      <el-form ref="recordRef" :model="form" :rules="rules" label-width="9em" disabled>
        <el-form-item label="违禁品类别/类型" prop="channelCode">
          <el-input
            :value="`${form.itemSeizureItemsList[0].categoryNameOne} / ${form.itemSeizureItemsList[0].categoryNameTwo}`"
            placeholder="- -" />
        </el-form-item>
        <!-- <el-form-item label="违禁品名称" prop="channelCode">
          <el-input v-model="form.itemSeizureItemsList[0].itemName" placeholder="" />
        </el-form-item> -->

        <el-form-item label="数量" prop="channelCode">
          <el-input v-model="form.itemSeizureItemsList[0].quantity" placeholder="-" />
        </el-form-item>
        <!-- <el-form-item label="查获部位" prop="channelCode">
          <el-input v-model="form.itemSeizureItemsList[0].checkPositionNameOne" placeholder="" />
        </el-form-item> -->
        <el-form-item label="部位类别/类型" prop="channelCode">
          <el-input
            :value="`${form.itemSeizureItemsList[0].checkPositionNameOne} / ${form.itemSeizureItemsList[0].checkPositionNameTwo}`"
            placeholder="- -" />
        </el-form-item>
        <!-- <el-form-item label="具体位置" prop="channelCode">
          <el-input v-model="form.itemSeizureItemsList[0].checkPositionSpecific" placeholder="" />
        </el-form-item> -->
        <el-form-item label="处理方式" prop="channelCode">
          <el-input v-model="form.itemSeizureItemsList[0].handlingMethodDesc" placeholder="-" />
        </el-form-item>
        <el-form-item label="是否隐匿夹带" prop="channelCode">
          <el-select v-model="form.itemSeizureItemsList[0].isActiveConcealment" placeholder="-">
            <el-option label="否" :value="0" />
            <el-option label="是" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="是否常见违禁品" prop="commonContraband">
          <el-select v-model="form.itemSeizureItemsList[0].commonContraband" placeholder="-">
            <el-option label="否" :value="0" />
            <el-option label="是" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="违禁品描述" prop="contrabandDesc">
          <el-input v-model="form.itemSeizureItemsList[0].contrabandDesc" placeholder="-" />
        </el-form-item>
        <el-form-item label="开机指令" prop="powerOnInstruction">
          <el-select v-model="form.powerOnInstruction" placeholder="-">
            <el-option label="指令" :value="0" />
            <el-option label="非指令" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item label="X光开机员" prop="xrayOperatorName">
          <el-input v-model="form.xrayOperatorName" placeholder="-" />
        </el-form-item>
        <!-- <el-form-item label="旅客姓名" prop="passengerName">
          <el-input v-model="form.passengerName" placeholder="请输入旅客姓名" />
        </el-form-item>
        <el-form-item label="旅客身份证号" prop="passengerCard">
          <el-input v-model="form.passengerCard" placeholder="请输入旅客身份证号" />
        </el-form-item>
        <el-form-item label="航班号" prop="passengerFlight">
          <el-input v-model="form.passengerFlight" placeholder="-" />
        </el-form-item> -->

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <!-- <el-button type="primary" @click="submitForm">确 定</el-button> -->
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Record">
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/item/record"
import { onMounted } from 'vue'
import { useDict } from '@/utils/dict'
const { proxy } = getCurrentInstance()

const recordList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const dateRange = ref([])
const { process_status } = useDict('process_status')
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    channelCode: null,
    seizureTime: null,
    checkMethod: null,
    attendanceId: null,
    attendanceTeamName: null,
    attendanceDepartmentName: null,
    attendanceStationName: null,
    channelName: null,
    regionalName: null,
    terminlName: null,
    passengerName: null,
    passengerGender: null,
    passengerCard: null,
    passengerFlight: null,
    inspectTeamId: null,
    inspectTeamName: null,
    powerOnInstruction: null,
    processStatus: null,
    inspectDepartmentId: null,
    inspectDepartmentName: null,
    inspectStationId: null,
    inspectStationName: null,
    checkMethodDesc: null,
    passengerGenderDesc: null,
    inspectUserName: null
  },
  rules: {
    channelCode: [
      { required: true, message: "通道编码不能为空", trigger: "blur" }
    ],
    seizureTime: [
      { required: true, message: "查获时间不能为空", trigger: "blur" }
    ],
    checkMethod: [
      { required: true, message: "检查岗位不能为空", trigger: "blur" }
    ],
    attendanceId: [
      { required: true, message: "考勤记录ID不能为空", trigger: "blur" }
    ],
    attendanceTeamId: [
      { required: true, message: "考勤班组ID不能为空", trigger: "blur" }
    ],
    attendanceTeamName: [
      { required: true, message: "考勤班组名称不能为空", trigger: "blur" }
    ],
    attendanceDepartmentId: [
      { required: true, message: "考勤主管ID不能为空", trigger: "blur" }
    ],
    attendanceDepartmentName: [
      { required: true, message: "考勤主管名称不能为空", trigger: "blur" }
    ],
    attendanceStationId: [
      { required: true, message: "考勤机构站ID不能为空", trigger: "blur" }
    ],
    attendanceStationName: [
      { required: true, message: "考勤机构站名称不能为空", trigger: "blur" }
    ],
    channelName: [
      { required: true, message: "通道名称不能为空", trigger: "blur" }
    ],
    regionalCode: [
      { required: true, message: "区域编码不能为空", trigger: "blur" }
    ],
    regionalName: [
      { required: true, message: "区域名称不能为空", trigger: "blur" }
    ],
    terminlCode: [
      { required: true, message: "航站楼编码不能为空", trigger: "blur" }
    ],
    terminlName: [
      { required: true, message: "航站楼名称不能为空", trigger: "blur" }
    ],
    inspectTeamId: [
      { required: true, message: "查获人班组ID不能为空", trigger: "blur" }
    ],
    inspectTeamName: [
      { required: true, message: "查获人班组名称不能为空", trigger: "blur" }
    ],
    inspectDepartmentId: [
      { required: true, message: "查获人主管ID不能为空", trigger: "blur" }
    ],
    inspectDepartmentName: [
      { required: true, message: "查获人主管名称不能为空", trigger: "blur" }
    ],
    inspectStationId: [
      { required: true, message: "查获人机构站ID不能为空", trigger: "blur" }
    ],
    inspectStationName: [
      { required: true, message: "查获人机构站名称不能为空", trigger: "blur" }
    ],
    checkMethodDesc: [
      { required: true, message: "检查岗位名称不能为空", trigger: "blur" }
    ],
    passengerGenderDesc: [
      { required: true, message: "旅客性别名称不能为空", trigger: "blur" }
    ],
    inspectUserName: [
      { required: true, message: "检查人员名称不能为空", trigger: "blur" }
    ]
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询查获记录列表 */
function getList() {
  loading.value = true;
  let params = {
    ...queryParams.value,
    beginTime: dateRange.value[0],
    endTime: dateRange.value[1]
  }
  listRecord(params).then(response => {
    recordList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    tenantId: null,
    revision: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    inspectUserId: null,
    channelCode: null,
    seizureTime: null,
    checkMethod: null,
    remark: null,
    attendanceId: null,
    id: null,
    attendanceTeamId: null,
    attendanceTeamName: null,
    attendanceDepartmentId: null,
    attendanceDepartmentName: null,
    attendanceStationId: null,
    attendanceStationName: null,
    channelName: null,
    regionalCode: null,
    regionalName: null,
    terminlCode: null,
    terminlName: null,
    passengerName: null,
    passengerGender: null,
    itemSeizureItemsList: [{}],
    passengerCard: null,
    passengerFlight: null,
    inspectTeamId: null,
    inspectTeamName: null,
    inspectDepartmentId: null,
    inspectDepartmentName: null,
    inspectStationId: null,
    inspectStationName: null,
    checkMethodDesc: null,
    passengerGenderDesc: null,
    inspectUserName: null
  }
  proxy.resetForm("recordRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加查获记录"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getRecord(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改查获记录"
  })
}

/** 查看详情 */
function handleDetail(row) {
  reset()
  const _id = row.id || ids.value
  getRecord(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "详情"
  })
}



/** 提交按钮 */
function submitForm() {
  proxy.$refs["recordRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateRecord(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addRecord(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除数据项？').then(function () {
    return delRecord(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => { })
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('item/record/export', {
    ...queryParams.value
  }, `record_${new Date().getTime()}.xlsx`)
}

onMounted(() => {
  getList()
})
</script>
