<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="90px"
        @submit.prevent="fnGetDataTransfer"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="车牌号" prop="PLATE_NUMBER">
              <el-input
                v-model="searchForm.PLATE_NUMBER"
                placeholder="请填写车牌号"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="车主业主" prop="VEHICLEOWNER">
              <el-input
                v-model="searchForm.VEHICLEOWNER"
                placeholder="请填写车主业主"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="登记人" prop="REGISTRANT">
              <el-input
                v-model="searchForm.REGISTRANT"
                placeholder="请填写登记人"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="到期日期" prop="CERTIFICATE_DATE">
              <el-date-picker
                v-model="searchForm.EXPIRE_DATE"
                value-format="YYYY-MM-DD"
                format="YYYY-MM-DD"
                type="date"
                placeholder="请选择到期日期"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="到期状态" prop="EXPIRE_STATUS">
              <el-select
                v-model="searchForm.EXPIRE_STATUS"
                placeholder="请选择到期状态"
              >
                <el-option
                  v-for="item in expireStatusList"
                  :key="item.BIANMA"
                  :label="item.NAME"
                  :value="item.BIANMA"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="提醒状态" prop="REMINDER_STATUS">
              <el-select
                v-model="searchForm.REMINDER_STATUS"
                placeholder="请选择提醒状态"
              >
                <el-option
                  v-for="item in remindStatusList"
                  :key="item.BIANMA"
                  :label="item.NAME"
                  :value="item.NAME"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPaginationTransfer">
                重置
              </el-button>
              <el-button>导出</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetDataTransfer"
      >
        <el-table-column label="序号" width="70">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="RECORD_NUMBER" label="档案号" />
        <el-table-column prop="PLATE_NUMBER" label="车牌号" />
        <el-table-column prop="VEHICLEOWNER" label="车主业主" />
        <el-table-column prop="CONTACT_NUMBER" label="联系电话" />
        <el-table-column prop="TRANSACTION_DATA" label="办理日期" />
        <el-table-column prop="TAXESDUES_PERIOD" label="税费周期" />
        <el-table-column prop="EXPIRE_DATE" label="到期日期" />
        <el-table-column prop="REGISTRANT" label="登记人" />
        <el-table-column prop="CREATTIME" label="创建时间" />
        <el-table-column prop="OPERATTIME" label="更改时间" />
        <el-table-column prop="REMINDER_STATUS" label="提醒状态" >
          <template #default="{ row }">
            <el-tag v-if="row.REMINDER_STATUS === '0'">开启</el-tag>
            <el-tag v-else-if="row.REMINDER_STATUS === '1'">关闭</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="EXPIRE_STATUS" label="到期状态">
          <template #default="{ row }">
            <el-tag v-if="row.EXPIRE_STATUS === '已到期'">已到期</el-tag>
            <el-tag v-else-if="row.EXPIRE_STATUS === '未到期'">未到期</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="RECORD_STATUS" label="档案状态" />
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/mechanical_files/taxation_manage/view',
                  query: { TAXATION_ID: row.TAXATION_ID },
                })
              "
            >
              查看
            </el-button>
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/mechanical_files/taxation_manage/edit',
                  query: { TAXATION_ID: row.TAXATION_ID },
                })
              "
            >
              修改
            </el-button>
            <el-button
              v-if="buttonJurisdiction.del"
              type="primary"
              text
              link
              @click="fnDelete(row.TAXATION_ID)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button
            v-if="buttonJurisdiction.add"
            type="primary"
            @click="
              router.push({ path: '/mechanical_files/taxation_manage/add' })
            "
          >
            新增
          </el-button>
        </template>
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import {
  layoutFnGetExpireStatus,
  layoutFnGetRemindStatus,
} from "@/assets/js/taxation_manage.js";
import {
  getTaxationManageList,
  setTaxatonManageDelete,
} from "@/request/taxation_manage.js";
import { useRouter } from "vue-router";
import useButtonJurisdiction from "@/assets/js/useButtonJurisdiction.js";
import { debounce } from "throttle-debounce";
import { ElMessage, ElMessageBox } from "element-plus";
const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getTaxationManageList, {});
const expireStatusList = await layoutFnGetExpireStatus();
const remindStatusList = await layoutFnGetRemindStatus();
const fnGetDataTransfer = () => {
  fnGetData({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnResetPaginationTransfer = () => {
  searchForm.value = {};
  fnResetPagination({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnDelete = debounce(
  1000,
  async (TAXATION_ID) => {
    await ElMessageBox.confirm("确定要删除吗？", { type: "warning" });
    await setTaxatonManageDelete({ TAXATION_ID });
    ElMessage.success("删除成功");
  },
  { atBegin: true }
);

const buttonJurisdiction = await useButtonJurisdiction("operation");
</script>
<style scoped></style>
