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
<template>
  <div  class="custom-scroll">
    <v-header title="新增组织"></v-header>
    <div class="fm w_row clearfix">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="addorg-ruleForm">
        <section class="w_col_12 sec">
          <el-form-item label="组织名" prop="name">
            <el-input type="text" v-model="ruleForm.name" maxlength="10" placeholder="请输入组织名" show-word-limit></el-input>
          </el-form-item>
        </section>
        <section class="w_col_12 sec">
      <el-form-item label="状态">
        <el-radio-group v-model="ruleForm.status" size="medium">
          <el-radio-button label="1">启用</el-radio-button>
          <el-radio-button label="2">停用</el-radio-button>
        </el-radio-group>
      </el-form-item>
        </section>
        <section class="w_col_12 sec">
          <el-form-item label="联系电话" prop="phone">
            <el-input type="text" v-model="ruleForm.phone" maxlength="11"  placeholder="请输入电话" show-word-limit></el-input>
          </el-form-item>
        </section>
        <section class="w_col_12 sec">
          <el-form-item label="上传标识" prop="phone">
            <div class="app_images">
              <div
                class="avatar"
                v-for="(i, j) in recordPhoto"
                :key="j + '-ta-img'"
              >
                <span
                  class="close el-icon-close"
                  @click.stop="onDelImage(i)"
                ></span>
                <img
                  :src="i"
                  alt=""
                  @click.stop="appShowImage(i,recordPhoto)"
                >
              </div>
              <v-upload
                slots
                class="avatar"
                @path="onImageSave"
                v-if="recordPhoto.length<1"
              >
                <div class="uopload-text">
                  <i class="el-icon-plus"></i>
                  <b>上传</b>
                </div>
              </v-upload>
            </div>
          </el-form-item>
        </section>
        <section class="w_col_12 sec">
          <el-form-item label="详细地址" prop="address">
             <el-input
              suffix-icon="el-icon-location-outline"
              placeholder="请输入"
              size="small"
              v-model="ruleForm.address"
              maxlength="50"
              @focus="mapCheck"
            ></el-input>
          </el-form-item>
        </section>
        <section class="w_col_24 sec">
          <el-form-item>
            <el-button @click="sub" type="primary">保存</el-button>
            <el-button @click="back">返回</el-button>
          </el-form-item>
        </section>
      </el-form>
      <el-dialog
        title="设置详细地址"
        :visible.sync="dialogVisibleMap"
        :before-close="handleCloseMap"
        append-to-body
      >
        <MapBox ref="mapContent" @setLocation="setLocation" />
        <div style="text-align: center; margin-top: 20px">
          <el-button @click="handleCloseMap">取 消</el-button>
          <el-button type="primary" @click="mapComfirm">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>
 
<script>
import {isvalidPhone,isIdcard} from '../../../assets/js/fromValidate';
import vUpload from "com/upload/upload1";
import MapBox from "../../../components/map/map.vue";
 var validPhone=(rule, value,callback)=>{
    if (!value){
      callback(new Error('请输入电话号码'))
    }else  if (!isvalidPhone(value)){
      callback(new Error('请输入正确的11位手机号码'))
    }else {
      callback()
    }
 }
export default {
  components: { vUpload ,MapBox },
  data(){
    return{
      ruleForm: {
        name:"" ,
        status:'1',
        phone: '',
        // recordPhoto:[],
        address:'',
        lat: 0,
        lng: 0,
      },
      recordPhoto:[],
      id:'',//编辑id
      dialogVisibleMap: false,
      positionData: {},
      rules: {
        // name: [
        //   { required: true, message: '请输入组织名', trigger: 'blur' },
        // ],
        // phone:[
        //   {required: true, validator: validPhone, trigger: 'blur' }
        // ],
        // address:[
        //   {required: true, message: '请输入地址', trigger: 'blur' }
        // ],
      },
    }
  },
  inject: ["appShowImage"],
  created() {
    if(this.$route.query.id){
      this.id = this.$route.query.id
      this.init()
    }
  },
  methods: {
    init(){
      this.$api.get('cluster/detail?id='+this.id,'',res=>{
        this.ruleForm = res
        this.recordPhoto = [res.logo]
       console.log(res)
      })
    },
    back(){
      this.$router.back()
    },
    sub(){
      //提交
      if(!this.ruleForm.name){
        demo.toast(`请输入组织名称`)
        return
      }
      if(!this.ruleForm.phone){
        demo.toast(`请输入联系电话`)
        return
      }
      if(this.recordPhoto.length===0){
        demo.toast(`请上传标识`)
        return
      }
      if(!this.ruleForm.address){
        demo.toast(`请选择地址`)
        return
      }
      let data = {
        name:this.ruleForm.name,
        status:this.ruleForm.status,
        phone:this.ruleForm.phone,
        logo:this.recordPhoto.join(),
        address:this.ruleForm.address,
        lat:this.ruleForm.lat,
        lng:this.ruleForm.lng,
      }
      if(this.id){//编辑
        this.edit(data)
      }else{//新增
        this.add(data)
      }
    },
    edit(data){
      data.id = this.id
      this.$api.post('cluster/edit',data,res=>{
        demo.toast("保存成功")
        this.back()
      })
    },
    add(data){
      this.$api.post('cluster/add',data,res=>{
         demo.toast("保存成功")
        this.back()
      })
    },
    onImageSave(v) {
      this.recordPhoto.push(v);
    },
    onDelImage(v) {
      this.$nextTick(() => {
       this.recordPhoto = this.recordPhoto.filter((r) => {
        return r !== v;
      });
      });
    },
    mapCheck() {
      this.dialogVisibleMap = true;
      this.$nextTick(() => {
        this.$refs.mapContent.getLocation({
          val: this.ruleForm.address,
          l: this.ruleForm.lat,
          r: this.ruleForm.lng,
        });
      });
    },
    mapComfirm() {
      if (this.positionData.addr) {
        this.ruleForm.address = this.positionData.addr;
        this.ruleForm.lat = this.positionData.lat;
        this.ruleForm.lng = this.positionData.lng;
      }
      this.dialogVisibleMap = false;
      this.positionData = {};
    },
    setLocation(data) {
      this.positionData = data;
    },
    handleCloseMap() {
      this.dialogVisibleMap = false;
      this.positionData = {};
    },
  }
}
</script>
 
<style lang="less" scoped>
.custom-scroll {
  overflow: auto;
}
.addorg-ruleForm {
  /deep/.el-form-item {
    width: 100%;
  }
  /deep/.el-form-item__label::before {
    content: '*';
    color: #e54d42;
  }
}
 
</style>