<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="SCRAP_VEHICLEMODEL">
              <el-select
                v-model="searchForm.SCRAP_VEHICLEMODEL"
                placeholder="请选择移除车型"
              >
                <el-option
                  v-for="item in relatedClassificationList"
                  :key="item.BIANMA"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <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-width="20px">
              <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="18">
            <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="SCRAP_VEHICLEMODEL" label="移除车型" />
        <el-table-column prop="VEHICLEOWNER" label="车主业主" />
        <el-table-column
          prop="CONTACT_NUMBER"
          label="联系电话"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column
          prop="SCRAP_DATE"
          label="移除日期"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column
          prop="REGISTRANT"
          label="登记人"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column
          prop="CREATTIME"
          label="创建时间"
          width="140"
          show-overflow-tooltip
        />
        <el-table-column label="操作" width="150">
          <template #default="{ row }">
            <el-button
              type="primary"
              text
              link
              @click="
                router.push({
                  path: '/mechanical_files/scrap_manage/view',
                  query: { SCRAP_ID: row.SCRAP_ID },
                })
              "
            >
              查看
            </el-button>
            <el-button
              v-if="buttonJurisdiction.del"
              type="danger"
              text
              link
              @click="fnDelete(row.SCRAP_ID)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
        <template #button>
          <el-button
            v-if="buttonJurisdiction.add"
            type="primary"
            @click="router.push({ path: '/mechanical_files/scrap_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 {
  getScrapManageList,
  layoutFnGetScrapType,
  setScrapManageDelete,
} from "@/request/scrap_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 { onMounted, ref } from "vue";
const router = useRouter();

const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getScrapManageList, {});

const relatedClassificationList = ref(null);
onMounted(async () => {
  const data = await layoutFnGetScrapType();
  relatedClassificationList.value = JSON.parse(data.value.zTreeNodes);
});
const fnGetDataTransfer = () => {
  fnGetData({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnResetPaginationTransfer = () => {
  searchForm.value = {};
  fnResetPagination({
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnDelete = debounce(
  1000,
  async (SCRAP_ID) => {
    await ElMessageBox.confirm("确定要删除吗？", { type: "warning" });
    await setScrapManageDelete({ SCRAP_ID });
    ElMessage.success("删除成功");
    fnGetDataTransfer();
  },
  { atBegin: true }
);

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