Blame view

src/components/car/addCarModal.vue 4.34 KB
6d21390a   wuxw   开发车辆详情页面
1
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  <template>
    <el-dialog :title="$t('addCarModal.addCar')" :visible.sync="visible" width="50%">
      <el-form :model="addCarModelInfo" :rules="rules" ref="addCarForm">
        <el-form-item :label="$t('addCarModal.licensePlate')" prop="carNum">
          <el-input v-model="addCarModelInfo.carNum" :placeholder="$t('addCarModal.licensePlateRequired')"></el-input>
        </el-form-item>
        <el-form-item :label="$t('addCarModal.carBrand')" prop="carBrand">
          <el-input v-model="addCarModelInfo.carBrand" :placeholder="$t('addCarModal.carBrandRequired')"></el-input>
        </el-form-item>
        <el-form-item :label="$t('addCarModal.carType')" prop="carType">
          <el-select v-model="addCarModelInfo.carType" :placeholder="$t('addCarModal.carTypeRequired')"
            style="width:100%">
            <el-option v-for="carType in carTypes" :key="carType.statusCd" :label="carType.name"
              :value="carType.statusCd"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="$t('addCarModal.color')" prop="carColor">
          <el-input v-model="addCarModelInfo.carColor" :placeholder="$t('addCarModal.colorRequired')"></el-input>
        </el-form-item>
        <el-form-item :label="$t('addCarModal.remark')">
          <el-input type="textarea" v-model="addCarModelInfo.remark" :placeholder="$t('addCarModal.remarkPlaceholder')"
            rows="3"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="visible = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="saveAddCarInfo">{{ $t('common.save') }}</el-button>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { saveOwnerCarMember } from '@/api/car/addCarModalApi'
  import { getDict } from '@/api/community/communityApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'AddCarModal',
    data() {
      return {
        visible: false,
        addCarModelInfo: {
          flowComponent: 'addCar',
          carNum: '',
          carBrand: '',
          carType: '',
          carColor: '',
          remark: "",
          carId: ''
        },
        carTypes: [],
        rules: {
          carNum: [
            { required: true, message: this.$t('addCarModal.licensePlateRequired'), trigger: 'blur' },
            { min: 2, max: 12, message: this.$t('addCarModal.licensePlateInvalid'), trigger: 'blur' }
          ],
          carBrand: [
            { required: true, message: this.$t('addCarModal.carBrandRequired'), trigger: 'blur' },
            { max: 50, message: this.$t('addCarModal.carBrandTooLong'), trigger: 'blur' }
          ],
          carType: [
            { required: true, message: this.$t('addCarModal.carTypeRequired'), trigger: 'change' }
          ],
          carColor: [
            { required: true, message: this.$t('addCarModal.colorRequired'), trigger: 'blur' },
            { max: 12, message: this.$t('addCarModal.colorTooLong'), trigger: 'blur' }
          ]
        }
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.loadCarTypes()
    },
    methods: {
      async loadCarTypes() {
        try {
          const data = await getDict('owner_car', 'car_type')
          this.carTypes = data
        } catch (error) {
          console.error('获取字典数据失败:', error)
        }
      },
      open(data) {
        this.addCarModelInfo.carId = data.carId
        this.visible = true
        this.$nextTick(() => {
          this.$refs.addCarForm.resetFields()
        })
      },
      saveAddCarInfo() {
        this.$refs.addCarForm.validate(valid => {
          if (valid) {
            this.addCarModelInfo.communityId = this.communityId
            saveOwnerCarMember(this.addCarModelInfo).then(response => {
              if (response.code === 0) {
                this.visible = false
                this.clearAddCarModalInfo()
                this.$emit('notify')
                this.$message.success(this.$t('common.addSuccess'))
              } else {
                this.$message.error(response.msg)
              }
            }).catch(error => {
              console.error('请求失败处理', error)
              this.$message.error(error)
            })
          }
        })
      },
      clearAddCarModalInfo() {
        this.addCarModelInfo = {
          flowComponent: 'addCar',
          carNum: '',
          carBrand: '',
          carType: '',
          carColor: '',
          remark: "",
          carNumType: '',
          carId: ''
        }
      }
    }
  }
  </script>