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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
    <div  class="custom-scroll">
      <v-header title="新增组织成员"></v-header>
      <div class="form-box">
        <el-form  class="demo-form-inline" label-width="100px">
          <div class="item">
            <el-form-item label="姓名">
              <el-input size="small" class="input" v-model="formInline.name" maxlength="10" show-word-limit placeholder="请输入姓名"></el-input>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="职务">
              <el-input size="small" class="input" v-model="formInline.job" maxlength="15" show-word-limit placeholder="请输入职务"></el-input>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="电话">
              <el-input size="small" class="input" v-model="formInline.phone" maxlength="11" show-word-limit placeholder="请输入电话"></el-input>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="身份证号">
              <el-input size="small" class="input" v-model="formInline.idCard" maxlength="18" show-word-limit placeholder="请输入身份证号"></el-input>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="住址">
              <el-input size="small" class="input" v-model="formInline.address" placeholder="请输入住址"></el-input>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="民族">
              <el-select size="small" v-model="formInline.nationCode" placeholder="请选择民族">
                <el-option v-for="item in nationList" :key="item.nationCode" :label="item.nationName" :value="item.nationCode"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="所属组织">
              <el-select size="small" v-model="formInline.clusterId" placeholder="请选择组织">
                <el-option v-for="item in clusterList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="item">
            <el-form-item label="状态">
              <el-radio-group size="small" v-model="formInline.status">
                <el-radio-button label="1">启用</el-radio-button>
                <el-radio-button label="2">停用</el-radio-button>
              </el-radio-group>
            </el-form-item>
          </div>
          <div class="item sec">
            <el-form-item label="上传照片">
              <div class="app_images ">
                <div
                  class="avatar"
                  v-for="(i, j) in formInline.recordPhoto"
                  :key="j + '-ta-img'"
                >
                <span
                  class="close el-icon-close"
                  @click.stop="onDelImage(i)"
                ></span>
                  <img
                    :src="i"
                    alt=""
                    @click.stop="appShowImage(i,formInline.recordPhoto)"
                  >
                </div>
                <v-upload
                  slots
                  class="avatar"
                  @path="onImageSave"
                  v-if="formInline.recordPhoto.length<1"
                >
                  <div class="uopload-text">
                    <i class="el-icon-plus"></i>
                    <b>上传</b>
                  </div>
                </v-upload>
              </div>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <div class="item">
        <el-button @click="sub" size="small" type="primary">保存</el-button>
        <el-button @click="back" size="small">返回</el-button>
      </div>
    </div>
</template>
<script>
  import {isvalidPhone,isIdcard} from '../../../assets/js/fromValidate';
  import vUpload from "com/upload/upload1";
    export default {
        name: "add",
        props: [],
        components: {vUpload},
        data() {
            return {
              formInline:{
                name:'',
                job:'',
                phone:'',
                idCard:'',
                address:'',
                nationCode:'',
                clusterId:'',
                status:'1',
                recordPhoto:[],
                logo:''
              },
              id:'',
              nationList:[],//民族
              clusterList:[],//组织
            }
        },
      inject: ["appShowImage"],
        created() {
          if(this.$route.query.id){
            this.id = this.$route.query.id
            this.init()
          }
          this.setNationList()
          this.setClusterList()
        },
        mounted() {
 
        },
        methods: {
          sub(){
            //提交
            if(!this.formInline.name){
              demo.toast(`请输入姓名`)
              return
            }
            if(!this.formInline.job){
              demo.toast(`请输入职务`)
              return
            }
            if(!isvalidPhone(this.formInline.phone)){
              demo.toast(`请输入正确的电话`)
              return
            }
            // if(!this.formInline.phone){
            //   demo.toast(`请输入电话`)
            //   return
            // }
            if(!isIdcard(this.formInline.idCard)){
              demo.toast(`请输入正确的身份证`)
              return
            }
            if(!this.formInline.address){
              demo.toast(`请输入住址`)
              return
            }
            if(!this.formInline.nationCode){
              demo.toast(`请选择民族`)
              return
            }
            if(!this.formInline.clusterId){
              demo.toast(`请选择所属组织`)
              return
            }
            if(this.formInline.recordPhoto.length===0){
              demo.toast(`请上传照片`)
              return
            }
            let data = {
              name:this.formInline.name,
              job:this.formInline.job,
              phone:this.formInline.phone,
              idCard:this.formInline.idCard,
              address:this.formInline.address,
              nationCode:this.formInline.nationCode,
              clusterId:this.formInline.clusterId,
              status:this.formInline.status,
              imageUrl:this.formInline.recordPhoto.join(),
            }
            if(this.id){//编辑
              this.edit(data)
            }else{//新增
              // this.add(data)
              this.add(data)
            }
          },
          edit(data){
            //编辑
            data.id= this.id
            this.$api.post('cluster/member/edit',data,e=>{
              // console.log(res)
              demo.toast("保存成功")
              this.back()
            })
          },
          add(data){
            //新增
            this.$api.post('cluster/member/add',data,res=>{
              demo.toast("保存成功")
              // console.log(res)
              this.back()
            })
          },
          back(){
            this.$router.back()
          },
          init(){
            this.$api.get('cluster/member/detail?id='+this.id,'',e=>{
              // console.log(e)
              e.recordPhoto = [e.imageUrl]
              this.formInline = e
            })
          },
          onDelImage(v) {
            this.formInline.recordPhoto = this.formInline.recordPhoto.filter((r) => {
              return r !== v;
            });
          },
          onImageSave(v) {
            this.formInline.recordPhoto.push(v);
          },
          setClusterList(){
            //组织
            this.$api.get('cluster/list','',res=>{
              // console.log(res)
              this.clusterList = res||[]
            })
          },
          setNationList(){
            //民族
            this.$api.get('cluster/member/nation/list','',res=>{
              // console.log(res)
              this.nationList = res||[]
            })
          }
        },
        watch: {},
        computed: {}
    }
 
</script>
<style scoped lang="less">
  .el-input {
    width: 200px;
  }
  .upImage {
    width: 100px;
    display: flex;
    box-sizing: border-box;
    flex-wrap: wrap;
  }
  .custom-scroll {
    overflow: auto;
    .form-box{
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      .demo-form-inline{
        display: flex;
        max-width: 700px;
        flex-wrap: wrap;
      }
      /deep/.el-form-item__label::before {
        content: '*';
                color: #e54d42;
 
      }
      .item{
        box-sizing: border-box;
        width: 300px;
 
      }
    }
  }
</style>