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
<template>
  <el-dialog
    :title="title"
    :visible="value"
    width="30%"
    :modal="false"
    :show-close="false"
    :before-close="onCancel"
  >
 
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="团队类型">
        <el-select v-model="ruleForm.teamType" placeholder="请选择">
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="团队名称" prop="name">
        <el-input v-model="ruleForm.name" placeholder="请输入团队名称" maxlength="20" show-word-limit></el-input>
      </el-form-item>
      <el-form-item label="服务电话" prop="phone">
        <el-input v-model="ruleForm.phone" placeholder="请输入服务电话" maxlength="11" show-word-limit></el-input>
      </el-form-item>
      <el-form-item label="上传图片" required="">
        <article class="flex image">
          <div
            class="avatar"
            v-for="(i, j) in image"
            :key="j + '-ta-img'"
          >
            <span
              class="close el-icon-close"
              @click.stop="onCloseImage(i)"
            ></span>
            <img
              :src="i"
              alt=""
              @click.stop="onScaleImage(i)"
            />
          </div>
          <div
            class="avatar"
            v-if="image.length < 1"
          >
            <v-upload
              @path="onPath"
              slots
            >
              <div class="avatar"><i class="el-icon-plus"></i><b>上传</b></div>
            </v-upload>
          </div>
        </article>
      </el-form-item>
    </el-form>
    <!-- 底部按钮 -->
    <span slot="footer" class="dialog-footer">
      <el-button @click="onCancel">取 消</el-button>
      <el-button type="primary" @click="onOk('ruleForm')">确 定</el-button>
    </span>
  </el-dialog>
</template>
 
<script>
import {isvalidPhone,isIdcard} from '../../../assets/js/fromValidate';
import vUpload from "com/upload/upload1";
 var validPhone=(rule, value,callback)=>{
    if (!value){
      callback(new Error('请输入服务电话'))
    }else  if (!isvalidPhone(value)){
      callback(new Error('请输入正确的11位手机号码'))
    }else {
      callback()
    }
 }
export default {
  props: {
    value: { type: Boolean },
    editteamData: { }
  },
  components: { vUpload },
  data() {
    return {
      ruleForm: {
        teamType: '1',
        name: '',
        id: '',
        phone:'',
        image:''
      },
      image:[],
      rules: {
        name: [
          { required: true, message: '请输入团队名称', trigger: 'blur' }
        ],
        phone: [
          {
              required: true,
              trigger: "blur",
              validator: validPhone,
          },
        ],
      },
      title: '',
      typeList:[]
    }
  },
  watch: {
    editteamData (val) {
      this.getTeam()
      if (val.id) {
        this.getdetails(val.id);
        this.ruleForm.id = val.id;
        this.image = val.image.split(",");
        console.log(this.ruleForm.image)
        this.title = '编辑团队'
      } else {
        this.ruleForm = {
          status: '1',
          name: ''
        }
 
        this.image = [];
        this.title = '添加团队'
      }
    }
  },
 
  mounted() {
    this.getTeam()
  },
 
  methods: {
  onCloseImage(i) {
      this.image = this.image.filter((r) => {
        return r !== i;
      });
    },
    onScaleImage(v) {
      this.$store.dispatch("setImage", {
        time: Date.now(),
        title: "[大图]",
        foot: 1,
        tool: 1,
        pic: v,
        list: this.image,
      });
    },
    clear(item) {
      item.url = "";
    },
    onPath(v) {
      this.image.push(v);
    },
    getdetails(id) {
      this.$api.get("fms/team/detail", {teamId:id}, d => {
        this.ruleForm = d;
      });
    },
    getTeam() {
      this.$api.get("fms/teamType/list", {}, d => {
        this.typeList = d.map(e=>{
          return {
            label:e.name,
            value:e.id
          }
        });
      });
    },
 
    /** 取消 */
    onCancel () {
      this.$emit('change', false);
    },
 
    /** 确认 */
    onOk(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if(!this.ruleForm.teamType) {
            return demo.toast("请添加团队类型")
          }
          if(!this.image[0]) {
            return demo.toast("请上传图片")
          }
          this.ruleForm.image = this.image[0];
          if (this.ruleForm.id) {
            this.edit()
          } else {
            this.save()
          }
        } else {
          return false;
        }
      });
    },
 
    save() {
      this.$api.post("fms/team/add", this.ruleForm, e => {
        this.$message('保存成功');
        this.$emit('success',this.ruleForm);
      });
    },
    edit() {
      this.$api.post("fms/team/edit", this.ruleForm, e => {
        this.$message('编辑成功');
        this.$emit('success',this.ruleForm);
      });
    }
 
  }
 
}
</script>
 
<style lang="less" scoped>
.flex {
  display: flex;
  flex-wrap: wrap;
  .avatar {
    margin: 0 10px 10px 0;
    position: relative;
    width: 104px;
    height: 104px;
    border: 1px dashed #eee;
    text-align: center;
    color: #ccc;
    cursor: pointer;
    i {
      font-size: 25px;
      margin: 30px auto 10px;
      display: block;
    }
    img {
      display: block;
      width: 100%;
      height: 100%;
    }
    .close {
      position: absolute;
      right: -8px;
      top: -8px;
      width: 16px;
      height: 16px;
      border-radius: 50%;
      background-color: tomato;
      color: #fff;
      cursor: pointer;
    }
  }
}
</style>