dispatchModal.vue 5.06 KB
<template>
	<!-- 派单弹框 -->
	<el-dialog  title="派单" :visible="dispatchModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="600px" :close-on-click-modal="false">

	  	<el-form ref="form" :model="form" :rules="rules" :inline="false" size="mini" v-show="!showResult" >
	  		<el-row>
	  			<el-col :span="24">
					安装地址:<br>
					<template v-for="(address,$index) in fixAreas">
						{{$index+1}}.{{address?address:'无'}}<br>
					</template>
	  			</el-col>
	  			<el-col :span="24">
					<el-form-item label="服务商账号登录名:" prop="serviceAccount">
						<el-input type="text" v-model.trim="form.serviceAccount" maxlength="500"></el-input>
					</el-form-item>
				</el-col>
	  			<el-col :span="24">
					<el-form-item label="服务商邮箱:" prop="serviceEmail">
						<el-input type="text" v-model.trim="form.serviceEmail"  maxlength="500"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
	  	</el-form>
		
		<el-row v-show="showResult" class="result-row">
			<el-col :span="12" class="text-center">
				<p><i class="el-icon-success el-alert--success"></i></p>
				<p><strong>{{successNum}}</strong><br>成功记录</p>
			</el-col>
			<el-col :span="12" class="text-center">
				<p><i class="el-icon-error el-alert--error"></i></p>
				<p><strong>{{errorNum}}</strong><br>失败记录</p>
			</el-col>
		</el-row>

		<div slot="footer" class="dialog-footer">
			<div v-show="!showResult" class="success">
	  			<el-button type="primary" @click="submit" size="small" :loading="submitting">确认</el-button>
	    		<el-button @click="$emit('onDispatchModalChange', false)" size="small">关闭</el-button>
			</div>
			
			<div v-show="showResult">
				<el-button type="primary" @click="exportErrorResult" size="small" class="pull-left" v-show="errorNum">导出失败记录</el-button>
	    		<el-button @click="doneResult" size="small" type="primary">完成</el-button>
			</div>
	  	</div>
	</el-dialog>

</template>
<script>
	import {exportExcel} from 'utils'
	import {services} from '../../api'

	const BUSSINESS_SERVICE = services.business;
	

	export default{
		props: ['dispatchModalVisible', 'ids', 'fixAreas'],
		data(){
			let checkAccountGroup = (rule, vaule, cb)=>{
				if(this.form.serviceAccount.length){
					const accountRegex = /([^;;]+)/g;
					const matchArr = this.form.serviceAccount.match(accountRegex);

					if(matchArr.length>10){
						cb(new Error('最多只能输入10个账号登录名'))
					}
					this.form.serviceAccount = matchArr.join(';')
				}
				cb()
			}

			let checkEmailGroup = (rule, vaule, cb)=>{
				//const regex = /^([\w-]+@[\w-]+(?:\.[\w-]+)+)(?:[;;]([\w-]+@[\w-]+(?:\.[\w-]+)+[;;]?))*$/;
				const emailGroupRegex = /^(?:([\w-]+@[\w-]+(?:\.[\w-]+)+[;;]?))(?:[;;]?([\w-]+@[\w-]+(?:\.[\w-]+)+[;;]?))*$/;
				const emailRegex = /[\w-]+@[\w-]+(?:\.[\w-]+)+/g;

				if(!emailGroupRegex.test(this.form.serviceEmail)){
					cb(new Error('请输入正确的邮箱格式,多个邮箱用分号隔开'))
				}

				const matchArr = this.form.serviceEmail.match(emailRegex);
				if(matchArr.length>30){
					cb(new Error('最多只能输入30个邮箱'))
				}
				this.form.serviceEmail = matchArr.join(';')
				cb()
			}

			return {
				form: {
					serviceEmail: 'operation@didihu.com.cn;',
					serviceAccount: ''
				},
				rules: {
					serviceAccount: [
						{validator: checkAccountGroup, trigger: 'blur'}
					],
					serviceEmail: [
						{required: true, message: '请输入服务商邮箱'},
						{validator: checkEmailGroup, trigger: 'blur'}
					]
				},
				showResult: false,
				successNum: '',
				errorNum: '',
				seqNo: '',
				submitting: false,
			}
		},
		methods: {
			doneResult(){
				this.$emit('onDispatchModalChange', false);
				this.$emit('onRefreshList');
				
			},
			exportErrorResult(){
				exportExcel('workOrder/exportFailRecord', {seqNo: this.seqNo})
			},
			
			openDialog(){
				this.$emit('onDispatchModalChange', true)
				
				
			},
			closeDialog(){
				this.$emit('onDispatchModalChange', false);
				this.$refs.form.resetFields();

				this.showResult = false;
				this.successNum = '';
				this.errorNum = '';
				this.seqNo = '';
				this.submitting = false;
			},
			submit(){
				this.$refs.form.validate((valid)=>{
					if(valid){
						this.submitting = true;
						
						const params = {
							ids: this.ids,
							emails: this.form.serviceEmail
						}
						if(this.form.serviceAccount){
							params.distributors = this.form.serviceAccount
						}
						BUSSINESS_SERVICE.dispatchWorkOrder(params).then((res)=>{
							if(res.returnCode == 0){
								const data = res.data;
								this.successNum = data.success;
								this.errorNum = parseInt(data.fail);
								this.seqNo = data.seqNo;

								this.showResult = true;
							}
							this.submitting = false;
						});
					}else{
						return;
					}
				});
				
			}
		}
	}
</script>

<style scoped>
	.import-dialog .upload-wrap .el-upload{
		width: 100%;
	}
	.import-dialog .el-icon-success, .import-dialog .el-icon-error{
		font-size: 30px;
	}
	.import-dialog .result-row .el-col+.el-col{
		border-left: 1px solid #eee;
	}
</style>