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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<template>
  <div>
    <el-row
      v-for="(item, i) in Fromfamily"
      :key="i"
      >
      <el-col :span="22">
        <el-form
          :rules="rules"
          :inline="true"
          :model="Fromfamily[i]"
          ref="Fromfamily"
          label-width="110px"
        >
            <el-form-item label="姓名" prop="name">
              <el-input  placeholder="请输入-不超过10字" v-model="Fromfamily[i].name"  maxlength="10" show-word-limit></el-input>
            </el-form-item>
            <el-form-item label="公民身份号码" prop="cardNo">
              <el-input  placeholder="请输入有效身份证号码" v-model="Fromfamily[i].cardNo" ></el-input>
            </el-form-item>
            <el-form-item label="与人员关系">
              <el-select  placeholder="请选择" v-model="Fromfamily[i].relationId">
                <el-option v-for="li in relation" :key="li.value" :label="li.name" :value="li.value"></el-option>
              </el-select>
            </el-form-item>
               <el-button type="primary" @click="onSubmitfamily(i)">保存</el-button>
          </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>
import {isvalidPhone,isIdcard} from '../../../../assets/js/fromValidate';
 
 var validIdcrad=(rule, value,callback)=>{
    if (!value){
        callback(new Error('请输入身份证号码'))
    }else  if (!isIdcard(value)){
      callback(new Error('请输入正确的身份证号码'))
    }else {
        callback()
    }
 };
 
export default {
  props:['editId'],
  data() {
    return{
      Fromfamily:[
        {
        cardNo:'',
        name:'',
        relationId:'',
        populationId:0,
      }
      ],
      rules: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' },
        ],
        cardNo:[
          {required: true, validator: validIdcrad, trigger: 'change' }
        ],
      },
      relation:[],
    }
  },
 
  watch:{
    editId(val) {
      this.Fromfamily.populationId  =val;
    }
  },
 
  mounted() {
    /** populationId:获取人口ID  */
    if(this.$route.query.id) {
      this.Fromfamily.populationId = this.$route.query.id;
      this.getDetails();
    }
    this.householder();
  },
  methods: {
    /** 获取吸毒信息 populationId:人口id
     *  id:主键id  有id编辑 无id新增 */
    getDetails() {
      this.$api.get("population/relation/list",{populationId:this.Fromfamily.populationId},e=> {
        if(e.length) {
        this.Fromfamily = e;
        }
      })
    },
    addItem() {
      this.Fromfamily.push({
        cardNo:'',
        name:'',
        relationId:'',
        populationId:0,
      });
    },
    // 删除
    del(index) {
        if(this.$route.query.id) {
          this.$api.get("population/relation/delete",{id:this.Fromfamily[index].id},e=> {
            demo.toast("删除成功");
            this.Fromfamily.splice(index, 1);
          })
        }else {
          this.Fromfamily.splice(index, 1);
        }
    },
 
    //与户主关系
    householder() {
      let params = {
        key:'GB/T4761'
      }
      this.$api.get('dictionary/listDictionaryByKey',params,e=>{
        this.relation = e.map(d=> {
          return {
            value:d.dictValue,
            name:d.dictName
          }
        })
      })
    },
 
    onSubmitfamily(i) {
      if(this.Fromfamily.populationId == '') {
        return  this.$message({
            message: '请先填写完基础信息',
            type: 'warning'
          });
      }
      if(this.Fromfamily[i].name == '') {
        return  this.$message({
                message: '请输入姓名',
                type: 'warning'
              });
      }
 
      if(this.Fromfamily[i].cardNo == '') {
        return  this.$message({
                message: '请输入身份证号',
                type: 'warning'
              });
      }
        if(this.Fromfamily[i].id) {
          //编辑
          this.$api.post("population/relation/edit",this.Fromfamily[i],e=> {
            demo.toast("编辑成功")
          })
        } else {
          //新增
        this.Fromfamily[i].populationId=this.Fromfamily.populationId;
        this.$api.post("population/relation/add",this.Fromfamily[i],d=> {
            this.$message({
              message: '保存成功',
              type: 'success'
            });
        });
        }
 
    },
  }
}
</script>
 
<style>
 
</style>