<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="100px"
        @submit.prevent="fnResetPagination"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="地点类型" prop="LOCATIONTYPE">
              <el-select v-model="searchForm.LOCATIONTYPE">
                <el-option label="起运地" :value="1" />
                <el-option label="目的地" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="运输企业" prop="TRANSPORTATIONCOMPANY">
              <el-select v-model="searchForm.TRANSPORTATIONCOMPANY">
                <el-option
                  v-for="item in data.unitsList"
                  :key="item.CORPINFO_ID"
                  :label="item.CORP_NAME"
                  :value="item.CORP_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="fnResetPagination">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table
        ref="tableRef"
        v-model:pagination="pagination"
        :data="list"
        @get-data="fnGetData"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column label="序号" width="60">
          <template #default="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="LOCATIONTYPE" label="地点类型" width="200">
          <template #default="{ row }">
            {{
              row.LOCATIONTYPE === "1"
                ? "起运地"
                : row.LOCATIONTYPE === "2"
                ? "目的地"
                : ""
            }}
          </template>
        </el-table-column>
        <el-table-column prop="LOCATIONNAME" label="地点名称" width="300" />
        <el-table-column prop="ADDRESSDETAILS" label="地址详情" width="300" />
        <el-table-column prop="CORP_NAME" label="运输企业" width="250" />
        <el-table-column prop="CREATETIME" label="创建时间" width="250" />
        <el-table-column label="操作" width="200"> </el-table-column>
        <template #button>
          <el-button
            type="primary"
            @click="
              router.push({
                path: '/electronic_waybill_management/location_managemen/add',
              })
            "
          >
            添加
          </el-button>
        </template>
      </layout-table>
    </layout-card>
    <edit
      v-model:visible="data.analysisDialog.visible"
      :info="data.analysisDialog.info"
      @get-data="fnResetPagination"
    />
  </div>
</template>

<script setup>
import { serialNumber } from "@/assets/js/utils";
import useListData from "@/assets/js/useListData.js";
import { onMounted, reactive, ref } from "vue";
import router from "@/router/index.js";
import { getSecurityPerson } from "@/request/waybill_registration.js";
import { getSecurityLocationList } from "@/request/location_management.js";

const tableRef = ref(null);
const { list, pagination, searchForm, fnGetData, fnResetPagination } =
  useListData(getSecurityLocationList);
const data = reactive({
  analysisDialog: {
    visible: false,
    info: {},
    unitsList: [],
  },
});
onMounted(async () => {
  await fnPerson();
});
const fnPerson = async () => {
  const resData = await getSecurityPerson({});
  data.unitsList = [resData.pd];
};
</script>

<style scoped></style>
