<template>
  <div class="edit-add-detail">
    <div class="form-content">
      <el-form ref="addEditForm" :model="addEditForm" :rules="addEditRules" class="edit-add-form" label-position="left"
               label-width="120px">
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">车辆基本信息</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="所属路段" prop="roadName">
              <el-input v-model="addEditForm.roadName" :disabled="true" clearable
                        readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车牌号" prop="carNumber">
              <el-input v-model="addEditForm.carNumber" clearable placeholder="请输入车牌号"
                        @blur="blurCheckout"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆类别" prop="carClass">
              <el-radio-group v-model="addEditForm.carClass">
                <el-radio v-for="(item, index) in getDictionaryByCode(
                  'jycl-cllx'
                )" :key="index" :label="Number(item.value)" :value="Number(item.value)">
                  {{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.carClass" clearable placeholder="车辆类别" style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in getDictionaryByCode(-->
              <!--                  'jycl-cllx'-->
              <!--                )" :key="index" :label="item.name" :value="Number(item.value)" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left:80px">
          <el-col :span="8">
            <el-form-item label="车辆用途" prop="useType">
              <el-radio-group v-model="addEditForm.useType" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode(
                  'jycl-clyt'
                )" :key="index" :label="Number(item.value)" :value="Number(item.value)" border>{{ item.name }}
                </el-radio>
                <!--                <el-radio border label="线下场地免费"></el-radio>-->
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.useType" clearable placeholder="车辆用途" style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in getDictionaryByCode(-->
              <!--                  'jycl-clyt'-->
              <!--                )" :key="index" :label="item.name" :value="Number(item.value)" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆别名 " prop="name">
              <el-input v-model="addEditForm.name" clearable placeholder="请输入别名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆颜色" prop="carColour">
              <el-radio-group v-model="addEditForm.carColour">
                <el-radio v-for="item in carColourList" :key="item.value"
                          :label="item.value"
                          :value="item.value"
                          border
                >{{ item.name }}
                </el-radio>
                <!--                <el-radio label="黑色"></el-radio>-->
                <!--                <el-radio label="白色"></el-radio>-->
                <!--                <el-radio label="黄色"></el-radio>-->
              </el-radio-group>
              <!--              <el-input v-model="addEditForm.carColour" clearable placeholder="请输入车辆颜色"></el-input>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆品牌" prop="carBrand">
              <el-input v-model="addEditForm.carBrand" clearable placeholder="请输入车辆品牌"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="座位数" prop="seatsNumber">
              <el-radio-group v-model="addEditForm.seatsNumber">
                <el-radio v-for="item in seatsNumberList" :key="item.value"
                          :label="item.value"
                          :value="item.value"
                >{{ item.name }}
                </el-radio>
                <!--                <el-radio label="2"></el-radio>-->
                <!--                <el-radio label="4"></el-radio>-->
                <!--                <el-radio label="5"></el-radio>-->
              </el-radio-group>
              <!--              <el-input v-model="addEditForm.seatsNumber" clearable placeholder="请输入座位数" type="number"></el-input>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆自有公司" prop="company">
              <el-input v-model="addEditForm.company" clearable placeholder="请输入车辆自有公司"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">车辆技术参数</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车辆油/气耗" prop="fuelConsumption">
              <el-input v-model="addEditForm.fuelConsumption" clearable placeholder="请输入车辆油/气耗"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="载重(吨)" prop="carLoad">
              <el-input v-model="addEditForm.carLoad" clearable placeholder="请输入载重(吨)" type="number"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="发动机编号" prop="engineNumber">
              <el-input v-model="addEditForm.engineNumber" clearable placeholder="请输入发动机编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="车架号" prop="frameNumber">
              <el-input v-model="addEditForm.frameNumber" clearable placeholder="请输入车架号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">车辆身份标识</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="ICCID" prop="iccid">
              <el-input v-model="addEditForm.iccid" clearable placeholder="请输入ICCID"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="IMSI" prop="imsi">
              <el-input v-model="addEditForm.imsi" clearable placeholder="请输入IMSI"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="SIM卡号" prop="simNumber">
              <el-input v-model="addEditForm.simNumber" clearable placeholder="请输入SIM卡号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">车辆使用及状态</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="12">
            <el-form-item label="网络运营商" prop="operators">
              <el-radio-group v-model="addEditForm.operators" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode(
                  'jycl-wlyys'
                )" :key="index" :label="item.value" :value="item.value" border>{{ item.name }}
                </el-radio>
                <!--                <el-radio border label="线下场地免费"></el-radio>-->
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.operators" clearable placeholder="网络运营商" style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in getDictionaryByCode(-->
              <!--                  'jycl-wlyys'-->
              <!--                )" :key="index" :label="item.name" :value="Number(item.value)" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left:80px">
          <el-col :span="6">
            <el-form-item label="是否有报警灯" prop="isAlarm">
              <el-radio-group v-model="addEditForm.isAlarm">
                <el-radio v-for="item in isAlarmList" :key="item.value"
                          :label="item.value"
                          :value="item.value"
                >{{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.isAlarm" clearable placeholder="请选择是否有报警灯" style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in ifOptions" :key="index" :label="item.label" :value="item.value" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>


          <el-col :span="6">
            <el-form-item label="报警灯是否备案" prop="isFiling">
              <el-radio-group v-model="addEditForm.isFiling">
                <el-radio v-for="item in isFilingList" :key="item.value"
                          :label="item.value"
                          :value="item.value"
                >{{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.isFiling" clearable placeholder="请选择报警灯是否备案"-->
              <!--                         style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in ifOptions" :key="index" :label="item.label" :value="item.value" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="是否自有车辆 " prop="isOwned">
              <el-radio-group v-model="addEditForm.isOwned">
                <el-radio v-for="item in isOwnedList" :key="item.value"
                          :label="item.value"
                          :value="item.value"
                >{{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.isOwned" clearable placeholder="请选择是否自有车辆" style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in ifOptions" :key="index" :label="item.label" :value="item.value" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="购买时间" prop="buyDate">
              <el-date-picker v-model="addEditForm.buyDate" clearable placeholder="选择购买时间" style="width: 100%"
                              type="date" value-format="yyyy-MM-dd ">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="检验有效期" prop="expirationDate">
              <el-date-picker v-model="addEditForm.expirationDate" clearable placeholder="选择检验有效期"
                              style="width: 100%"
                              type="date" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="注册日期" prop="registrationDate">
              <el-date-picker v-model="addEditForm.registrationDate" clearable placeholder="请选择注册日期"
                              style="width: 100%"
                              type="date" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="8">
            <el-form-item label="发证日期" prop="addDate">
              <el-date-picker v-model="addEditForm.addDate" clearable placeholder="请选择发证日期" style="width: 100%"
                              type="date" value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">车辆拖挂信息</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="12">
            <el-form-item label="适拖车型(客车)" prop="suitabilityCar">
              <el-radio-group v-model="addEditForm.suitabilityCar" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode(
                  'kc-stcx'
                )" :key="index" :label="item.value" :value="item.value" border>{{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.suitabilityCar" clearable placeholder="适拖车型(客车)"-->
              <!--                         style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in getDictionaryByCode(-->
              <!--                  'kc-stcx'-->
              <!--                )" :key="index" :label="item.name" :value="Number(item.value)" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>

        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="14">
            <el-form-item label="适拖车型(货车) " prop="suitabilityTruck">
              <el-radio-group v-model="addEditForm.suitabilityTruck" size="medium">
                <el-radio v-for="(item, index) in getDictionaryByCode(
                  'hc-stcx'
                )" :key="index" :label="item.value" :value="item.value" border>{{ item.name }}
                </el-radio>
              </el-radio-group>
              <!--              <el-select v-model="addEditForm.suitabilityTruck" clearable placeholder="适拖车型(货车) "-->
              <!--                         style="width: 100%">-->
              <!--                <el-option v-for="(item, index) in getDictionaryByCode(-->
              <!--                  'hc-stcx'-->
              <!--                )" :key="index" :label="item.name" :value="Number(item.value)" />-->
              <!--              </el-select>-->
            </el-form-item>
          </el-col>
        </el-row>
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">其他信息</div>
          </div>
        </div>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input v-model="addEditForm.remarks" :autosize="{ minRows: 2, maxRows: 4 }" clearable
                        placeholder="请输入备注"
                        type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px">
          <el-col :span="6">
            <el-form-item class="file-form-item" label="行驶证正面照片" prop="drivingLicenseF">
              <img-dialog :imgId="addEditForm.drivingLicenseF" :imgType="'drivingLicenseF'"
                          @updateFile="updateFile"></img-dialog>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="file-form-item" label="行驶证背面照片" prop="drivingLicenseB">
              <img-dialog :imgId="addEditForm.drivingLicenseB" :imgType="'drivingLicenseB'"
                          @updateFile="updateFile"></img-dialog>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24" style="margin-left: 80px;margin-top: 12px">
          <el-col :span="6">
            <el-form-item class="file-form-item" label="车辆正面照片" prop="carFrontUrl">
              <img-dialog :imgId="addEditForm.carFrontUrl" :imgType="'carFrontUrl'"
                          @updateFile="updateFile"></img-dialog>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="file-form-item" label="车辆侧面照片" prop="carSideUrl">
              <img-dialog :imgId="addEditForm.carSideUrl" :imgType="'carSideUrl'" @updateFile="updateFile"></img-dialog>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="file-form-item" label="车辆背面照片" prop="carBehindUrl">
              <img-dialog :imgId="addEditForm.carBehindUrl" :imgType="'carBehindUrl'"
                          @updateFile="updateFile"></img-dialog>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button :loading="saveLoading" type="primary" @click="handleSave">
        {{ $t('domestic.save') }}
      </el-button>
      <el-button @click="changePage('TablePage')">
        {{ $t('domestic.cancel') }}
      </el-button>
    </div>
  </div>
</template>

<script>
import PubSub from 'pubsub-js'

import {refineRequestBody} from '@/utils/requestWrappers'
import {
  tableAdd,
  tableDetail,
  tableEdit,
  verifyCarNumber
} from '@/api/patrolAndRescue/infoMgmtPatrolsRescues/patrolAndRescueVehicleMgmt'

import {getDictionaryByCode} from '@/utils/dictionary'

import {orgTree} from '@/api/systemInterface'

// 图片上传
import imgDialog from './components/imgDialog'

import {tableData as roadSectionInfoInter} from '@/api/patrolAndRescue/infoMgmtPatrolsRescues/roadSectionInfo'
import {tableData as teamData} from '@/api/patrolAndRescue/infoMgmtPatrolsRescues/patrolAndRescueTeamsMgmt'
// import {tableData as rescuePointData} from '@/api/patrolAndRescue/infoMgmtPatrolsRescues/rescueSiteMgmt'

export default {
  name: 'EditAddPage',
  components: {
    imgDialog
  },
  props: {
    componentName: {
      default: 'TablePage',
      type: String
    }
  },
  data() {
    return {
      carColourList: [
        {value: '1', name: '黑色'},
        {value: '2', name: '白色'},
        {value: '3', name: '黄色'}
      ],
      isAlarmList: [
        {value: 1, name: '是'},
        {value: 0, name: '否'}
      ],
      isFilingList: [
        {value: 1, name: '是'},
        {value: 0, name: '否'}
      ],
      isOwnedList: [
        {value: 1, name: '是'},
        {value: 0, name: '否'}
      ],
// 2/4.5
      seatsNumberList: [
        {value: 0, name: '2'},
        {value: 1, name: '4'},
        {value: 2, name: '5'}
      ],
      addEditForm: {
        carColour: '1',
        seatsNumber: 0,
        operators: '1',
        isAlarm: 1,
        isFiling: 1,
        isOwned: 1,
        useType: 1,
        carClass: 1,
        suitabilityCar: '1',
        suitabilityTruck: '1',
        road: {},
        rescue: {},
        roadName: ''
      },
      addEditRules: {
        carNumber: [
          {required: true, message: '请输入车牌号', trigger: 'blur'}
        ],
        carClass: [
          {required: true, message: '请选择车辆类别', trigger: 'change'}
        ],
        useType: [
          {required: true, message: '请选择车辆用途', trigger: 'change'}
        ]
      },
      saveLoading: false, // 上传loading
      id: '', // id标识符
      pubSub: null,
      roadOptions: [],
      rescuePointOptions: [],
      // 车牌号是否存在
      isCarNamber: false,
      roadChoiceDialog: false, // 是否展示选择路段弹层
      rescuePointChoiceDialog: false,
      accept: '.png, .jpg, .jpeg',
      ifOptions: [
        {label: '是', value: 1},
        {label: '否', value: 0}
      ],
      treeData: [],
      teamOptions: []
      // rescuePointOptions: []
    }
  },
  watch: {
    componentName: {
      handler(newVal) {
        if (newVal === this.$options.name) {
          this.openPage()
        } else {
          this.closePage()
        }
      }
    }
  },
  created() {
    this.getOrgTreeData()
  },
  mounted() {
    // this.pubSub = PubSub.subscribe('TreeItemSelected', (_, nodeItem) => {
    //   this.addEditForm.roadName = nodeItem?.name || ''
    //   this.addEditForm.roadId = nodeItem?.id || ''
    //   this.addEditForm.roadFullId = nodeItem?.path || ''
    // })
    this.pubSub = PubSub.subscribe('EditAddPage', (_, data) => {
      console.log(data, '55555555555555')
      console.log(data.roadName, '/////////////////////')
      if (data.roadName !== '') {
        this.addEditForm.roadName = data?.roadName || ''
        this.addEditForm.roadId = data?.catalogId || ''
        this.addEditForm.roadFullId = data?.path || ''
      }
      console.log(this.addEditForm.roadName, 'cascascasc')
      console.log(this.addEditForm.roadId, 'cascascasc111')
      if (data.id) {
        this.id = data.id
        this.getDetail(data.id)
      } else {
        // this.addEditForm = {
        //   operators: 1,
        //   isAlarm: 1,
        //   isFiling: 1,
        //   isOwned: 1,
        //   useType: 1,
        //   carClass: 1,
        //   suitabilityCar: 1,
        //   suitabilityTruck: 1,
        //   road: {},
        //   rescue: {}
        // }
        this.getRoadData()
      }
    })
  },
  methods: {
    //获取所在路段列表数据
    async getRoadData(value) {
      const {rows = []} = await roadSectionInfoInter({pageBean: {pageSize: -1}})
      this.roadOptions = rows.map(item => {
        item.roadName = item.name + ' ' + item.code
        return item
      })
      if (!this.id) {
        // this.$set(this.addEditForm, 'roadId', this.roadOptions[0].id)
        this.roadChange(this.roadOptions[0].id)
      } else {
        this.roadChange(value)
      }
    },
    roadChange(value) {
      this.getTeamData(value)
      this.getRescuePointData(value)
    },
    // 通过路段信息获取巡查救援队伍信息
    async getTeamData(value) {
      this.addEditForm.teamId = ''
      const {rows = []} = await teamData(refineRequestBody({
        querys: [{operation: 'IN', property: 'r.id_', value}]
      }), 'addEdit')
      this.teamOptions = rows
    },
    // 根据路段查询救援点
    async getRescuePointData(value) {
      const {rows = []} = await rescuePointData(refineRequestBody({
        querys: [{operation: 'IN', property: 'road_id_', value}]
      }), 'addEdit')
      this.rescuePointOptions = rows
    },
    teamIdChange() {
      this.addEditForm.teamFullId = this.$refs.cascader?.getCheckedNodes()[0]?.data?.path || ''
      this.addEditForm.teamId = this.$refs.cascader?.getCheckedNodes()[0]?.value || ''
    },
    // 获取公司树
    async getOrgTreeData() {
      this.treeData = await orgTree()
    },
    async blurCheckout(e) {
      let id = this.addEditForm.id || ''
      const {state} = await verifyCarNumber({id, carNumber: e.target.value})
      this.isCarNamber = !state
    },
    updateFile(url, type) {
      this.$set(this.addEditForm, type, url)
    },
    getDictionaryByCode,
    // 打开页面执行
    openPage() {
    },
    // 关闭页面执行
    closePage() {
      const {roadOptions} = this
      // 重置组件数据
      Object.assign(this.$data, this.$options.data.call(this), {pubSub: this.pubSub, roadOptions})
      this.$nextTick(_ => {
        this.$refs.addEditForm.$el.scrollTop = 0
        this.$refs.addEditForm.clearValidate()
        this.$refs.upload?.clearFiles()
      })
    },

    // 获取详情
    async getDetail(id) {
      const {policyFiles = [], roadId = '', ...addEditForm} = await tableDetail(id)
      this.addEditForm = {
        ...addEditForm,
        roadId,
        policyFiles,
        roadName: addEditForm.roadName || this.addEditForm.roadName,// 如果接口返回的 orgName 为空，使用当前表单的 orgName，
        policyFilesArr: policyFiles.map(i => ({
          ...i, name: i.fileName
        }))
      }
      if (this.roadOptions.length) {
        this.roadChange(roadId)
      } else {
        this.getRoadData(roadId)
      }
    },


    // 保存
    handleSave() {
      this.$refs.addEditForm.validate(async (valid, object) => {
        if (!valid) {
          this.$message.warning(`有${Object.keys(object).length}个字段未通过校验，请正确填写表单内容。`)
        } else {
          if (!this.isCarNamber) {
            this.saveLoading = true
            const myInterFace = this.id ? tableEdit : tableAdd

            try {
              const response = await myInterFace({
                ...this.addEditForm,
                roadId: this.addEditForm.roadId, // 传递 orgId
                roadName: this.addEditForm.roadName, // 传递 orgName
                roadFullId: this.addEditForm.roadFullId,// 传递 roadFullId
                type: this.addEditForm.type, // 传递队伍类型的 value
                useType: Number(this.addEditForm.useType),
                carClass: Number(this.addEditForm.carClass)
              })
              console.log(this.addEditForm.roadId, '1111222221111')
              const {state, message} = response
              if (state) {
                const action = this.id ? '编辑' : '新增'
                this.$message.success(`${action}成功`)
                PubSub.publish('TablePage', {type: this.id ? 'edit' : 'add'})
                // 调用 changePage 方法，传递正确的参数
                this.changePage('TablePage', this.id ? 'edit' : 'add')
              }
            } finally {
              this.saveLoading = false
            }
          } else {
            this.$message.error('车牌号已存在，请重新录入')
          }
        }
      })

    },

    // 展示弹层
    showDialog(dialogName) {
      if (!dialogName) return
      this[dialogName + 'Dialog'] = true
    },
    // 改变页面
    changePage(pageName = '', type = '') {
      if (!pageName) return
      this.$emit('changePage', pageName, _ => {
        PubSub.publish(pageName, {type})
      })
    }
  },
  beforeDestroy() {
    // 在组件销毁之前 清除订阅消息
    PubSub.unsubscribe(this.pubSub)
  }
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/element-variables";

.form-content {
  height: 0;
}

</style>
