<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>
|