Blame view

src/components/car/addParkingSpace.vue 4.47 KB
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
1
  <template>
e18d1bbb   wuxw   开发完成停车场 和停车位功能
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    <el-dialog :title="$t('addParkingSpace.title')" :visible.sync="visible" width="50%" @close="closeDialog">
      <el-form :model="form" ref="form" label-width="120px">
        <el-form-item :label="$t('addParkingSpace.parkingSpaceNum')" prop="num"
          :rules="[{ required: true, message: $t('addParkingSpace.parkingSpaceNumPlaceholder'), trigger: 'blur' }]">
          <el-input v-model="form.num" :placeholder="$t('addParkingSpace.parkingSpaceNumPlaceholder')"></el-input>
        </el-form-item>
  
        <el-form-item :label="$t('addParkingSpace.parkingLot')" prop="paId"
          :rules="[{ required: true, message: $t('addParkingSpace.parkingLotPlaceholder'), trigger: 'change' }]">
          <el-select v-model="form.paId" :placeholder="$t('addParkingSpace.parkingLotPlaceholder')" style="width:100%">
            <el-option v-for="item in parkingAreas" :key="item.paId" :label="item.num" :value="item.paId"></el-option>
          </el-select>
        </el-form-item>
  
        <el-form-item :label="$t('addParkingSpace.parkingSpaceType')" prop="parkingType"
          :rules="[{ required: true, message: $t('addParkingSpace.parkingSpaceTypePlaceholder'), trigger: 'change' }]">
          <el-select v-model="form.parkingType" :placeholder="$t('addParkingSpace.parkingSpaceTypePlaceholder')"
            style="width:100%">
            <el-option v-for="item in parkingTypes" :key="item.statusCd" :label="item.name"
              :value="item.statusCd"></el-option>
          </el-select>
        </el-form-item>
  
        <el-form-item :label="$t('addParkingSpace.area')" prop="area" :rules="[
          { required: true, message: $t('addParkingSpace.areaPlaceholder'), trigger: 'blur' },
          { pattern: /^\d+(\.\d{1,2})?$/, message: $t('addParkingSpace.areaPlaceholder'), trigger: 'blur' }
        ]">
          <el-input v-model="form.area" type="number" :placeholder="$t('addParkingSpace.areaPlaceholder')"></el-input>
        </el-form-item>
  
        <el-form-item :label="$t('addParkingSpace.remark')" prop="remark">
          <el-input v-model="form.remark" type="textarea" :placeholder="$t('addParkingSpace.remarkPlaceholder')"></el-input>
        </el-form-item>
      </el-form>
  
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('addParkingSpace.cancel') }}</el-button>
        <el-button type="primary" @click="saveParkingSpace" :loading="saving">
          {{ $t('addParkingSpace.save') }}
        </el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { saveParkingSpace } from '@/api/car/listParkingSpaceApi'
  import { listParkingAreas } from '@/api/car/listParkingSpaceApi'
  import { getDict } from '@/api/community/communityApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddParkingSpace',
    data() {
      return {
        visible: false,
        saving: false,
        form: {
          num: '',
          paId: '',
          parkingType: '1',
          area: '1',
          remark: '',
          communityId: getCommunityId()
        },
        parkingTypes: [],
        parkingAreas: []
      }
    },
    methods: {
      open() {
        this.visible = true
        this.loadParkingTypes()
        this.loadParkingAreas()
      },
  
      async loadParkingTypes() {
        try {
          const data = await getDict('parking_space', 'parking_type')
          this.parkingTypes = data
        } catch (error) {
          this.$message.error(this.$t('common.loadDictError'))
        }
      },
  
      async loadParkingAreas() {
        try {
          const params = {
            page: 1,
            row: 50,
            communityId: getCommunityId()
          }
          const res = await listParkingAreas(params)
          this.parkingAreas = res.parkingAreas
        } catch (error) {
          this.$message.error(this.$t('common.loadError'))
        }
      },
  
      async saveParkingSpace() {
        try {
          this.saving = true
          await this.$refs.form.validate()
  
          const res = await saveParkingSpace(this.form)
          if (res.code === 0) {
6ec243d6   wuxw   v1.9 点击提交后,成功提示没有...
107
            this.$message.success(this.$t('common.operationSuccess'))
e18d1bbb   wuxw   开发完成停车场 和停车位功能
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
            this.$emit('success')
            this.visible = false
          } else {
            this.$message.error(res.msg || this.$t('common.saveError'))
          }
        } catch (error) {
          console.error('Validation failed:', error)
        } finally {
          this.saving = false
        }
      },
  
      closeDialog() {
        this.$refs.form.resetFields()
        this.form = {
          num: '',
          paId: '',
          parkingType: '1',
          area: '1',
          remark: '',
          communityId: getCommunityId()
        }
      }
    }
  }
  </script>