hejianhao
2025-04-16 dab2d210ca06c1faa514c6388fbd5de1ab355360
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
  <div>
    <el-row
      v-for="(item, i) in FromCar"
      :key="i"
      >
      <el-col :span="22">
        <el-form ref="FromCar" :rules="rules"  :inline="true" :model="FromCar[i]" label-width="100px">
          <div class="add-lie">
            <div>
              <el-form-item label="所属小区">
                <el-select :disabled="true"   placeholder="" v-model="FromCar[i].villageId">
                  <el-option v-for="item in villageList" :key="item.value"
                  :label="item.label" :value="item.value"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="品牌型号">
                <el-input :disabled="true"   placeholder="" v-model="FromCar[i].brand"  maxlength="20" show-word-limit></el-input>
              </el-form-item>
              <el-form-item label="车牌号" prop="plateNum">
                <el-input :disabled="true"   placeholder="" v-model="FromCar[i].plateNum"  maxlength="20" show-word-limit></el-input>
              </el-form-item>
                <el-form-item label="车辆颜色">
                <el-input :disabled="true"   placeholder="" v-model="FromCar[i].color"  maxlength="20" show-word-limit></el-input>
              </el-form-item>
            </div>
            <!-- <el-form-item>
              <el-button type="primary" @click="onSubmitcar(i)">保存</el-button>
            </el-form-item> -->
          </div>
        </el-form>
      </el-col>
      <!-- <el-col :span="2">
        <i
          class="el-icon-circle-plus-outline"
          type="danger"
          v-if="i == 0"
          style="font-size: 30px; color: #67c23a; margin-right: 5px"
          @click="addItem"
          ></i>
        <i
          class="el-icon-remove-outline"
          type="danger"
          v-if="i != 0"
          style="font-size: 30px; color: #f56c6c"
          @click="del(i)"
          ></i>
    </el-col> -->
    </el-row>
  </div>
</template>
 
<script>
export default {
  props:['editId'],
  data() {
    return{
      FromCar:[{
        populationId:0,
        plateNum:'',
        color:'',
        brand:'',
        villageId:'',
        communityId:''
      }],
      rules: {
        plateNum: [
          { required: true, message: '请输入车牌号', trigger: 'blur' },
        ],
      },
      villageList:[],
      communityId:''
    }
  },
 
  watch:{
    editId(val) {
      if(val) {
        this.FromCar.populationId  =val;
      }
    }
  },
 
  mounted() {
    /** populationId:获取人口ID  */
    if(this.$route.query.id) {
      this.FromCar.populationId = this.$route.query.id;
      this.communityId =  this.$route.query.com;
      this.getDetails();
    } else {
      this.communityId =  this.$route.query.vi;
    }
 
    this.getvillage();
  },
  methods: {
    /** 获取吸毒信息 populationId:人口id
     *  id:主键id  有id编辑 无id新增 */
    getDetails() {
      this.$api.get("population/car/list",{populationId:this.FromCar.populationId},e=> {
        if(e.length) {
        this.FromCar = e;
        }
      })
    },
    addItem() {
      this.FromCar.push({
      populationId:'',
      plateNum:'',
      color:'',
      brand:'',
      villageId:'',
      communityId:''
      });
    },
    // 删除
    del(index) {
      if(this.$route.query.id) {
        this.$api.get("population/car/delete",{id:this.FromCar[index].id},e=> {
          demo.toast("删除成功");
          this.FromCar.splice(index, 1);
        })
      }else {
        this.FromCar.splice(index, 1);
      }
    },
 
    getvillage() {
      this.$api.get("building/village/list",'',d=> {
        this.villageList = d.map(e=> {
          return {
            label:e.name,
            value:e.villageId.toString(),
          }
        })
      })
 
    },
 
    onSubmitcar(i) {
      if(!this.FromCar.populationId) {
        return  this.$message({
            message: '请先填写完基础信息',
            type: 'warning'
          });
      }
 
 
      if(this.FromCar[i].id) {
        //编辑
         this.FromCar[i].communityId =   this.communityId;
        this.$api.post("population/car/edit",this.FromCar[i],e=> {
          demo.toast("编辑成功")
        })
      } else {
        //新增
        this.FromCar[i].populationId =   this.FromCar.populationId;
         this.FromCar[i].communityId =   this.communityId;
        this.$api.post("population/car/add",this.FromCar[i],d=> {
          this.$message({
            message: '保存成功',
            type: 'success'
          });
      });
      }
 
    },
  }
}
</script>
 
<style>
 
</style>