<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">
                <el-option
                  v-for="item in DUE_STATUS_LIST"
                  :key="item.ID"
                  :label="item.NAME"
                  :value="item.ID"
                />
              </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="请选择提醒状态"
                clearable
              >
                <el-option
                  v-for="item in REMINDER_STATUS"
                  :key="item.ID"
                  :label="item.NAME"
                  :value="item.ID"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <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-form-item>
          </el-col>
          <el-col :span="25">
            <el-form-item label-width="10px" class="end">
              <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'" type="success"
            >开启
            </el-tag>
            <el-tag v-else-if="row.REMINDER_STATUS === '1'" type="info"
            >关闭
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="EXPIRE_STATUS" label="到期状态">
          <template #default="{ row }">
            <el-tag v-if="row.EXPIRE_STATUS === '1'" type="success"
            >未到期
            </el-tag>
            <el-tag v-else-if="row.EXPIRE_STATUS === '0'" type="error"
            >已到期
            </el-tag>
            <el-tag v-else-if="row.EXPIRE_STATUS === '2'" type="info"
            >即将到期
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="ARCHIVES_TYPE" label="车辆状态" width="150">
          <template #default="{ row }">
            <el-tag v-if="row.ARCHIVES_TYPE === '1'" type = "error">报废</el-tag>
            <el-tag v-else-if="row.ARCHIVES_TYPE === '0'" type = "success">正常</el-tag>
            <el-tag v-else-if="row.ARCHIVES_TYPE === '2'" type = "warning">过户</el-tag>
          </template>
        </el-table-column>
        <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
              v-if="row.ASSIGNEDSTATUS !== '1'"
              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="danger"
              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 {
  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";
import { DUE_STATUS_LIST, REMINDER_STATUS } from "@/assets/js/constant.js";
const router = useRouter();
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getTaxationManageList, {});
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("删除成功");
    fnGetDataTransfer();
  },
  { atBegin: true }
);
const buttonJurisdiction = await useButtonJurisdiction("operation");
</script>
<style scoped></style>
