Commit 86ea9230 authored by Babin Egor's avatar Babin Egor

update reg-form

parent 77513f67
......@@ -2,7 +2,7 @@
import { ValidationProvider, extend } from 'vee-validate';
import { required, email } from 'vee-validate/dist/rules';
import $ from 'jquery';
import axios from 'axios';
extend('required', required);
extend('email', email);
......@@ -10,16 +10,53 @@ Vue.component('ValidationProvider', ValidationProvider);
Vue.component('app-registration-form', {
props: {
personRegTypeProp: {
type: String
},
personType: {
type: String
}
},
},
data: function () {
return {
stages: {
juridical: ['Информация о компании','Контактное лицо','Авторизационные данные'],
natural: ['Информация о физическом лице','Авторизационные данные'],
wGroupSelect: {
title: 'Вид транспорта',
attrs: {
name: 'trans-types',
id: 'trans-types',
required: true
},
options: [],
settings: {
searchEnabled: true,
shouldSort: false,
noChoicesText: 'Пусто',
noResultsText: 'Ничего не найдено',
},
helptext: ''
},
wUnitsSelect: {
title: 'Ед. Изм.',
attrs: {
name: 'units',
id: 'units',
required: true
},
options: [],
settings: {
searchEnabled: false,
shouldSort: false,
noChoicesText: 'Пусто',
noResultsText: 'Ничего не найдено',
},
helptext: ''
},
wUnitAmounts: [{}],
personRegType: this.personRegTypeProp,
buttonRegTxt: this.txtForRegButton(),
stages: this.typeOfStages(),
fieldsVal: {
juridical: {
companyName: '',
......@@ -80,7 +117,21 @@ Vue.component('app-registration-form', {
currentStage: 0,
}
},
created() {
this.localRecord = {
wGroup: {},
wAddress: {
region: {
id: null,
name: ''
}
},
};
this.transportGroupLoad();
},
computed: {
firstStage() {
return this.currentStage === 0
},
......@@ -95,6 +146,14 @@ Vue.component('app-registration-form', {
return this.currentStage >= this.stages[this.currentPT].length - 1
},
is_executor(){
if (this.personRegType == "executor") {
return true;
} else {
return false;
}
},
nextpage() {
if (this.currentPT == "juridical") {
......@@ -144,57 +203,68 @@ Vue.component('app-registration-form', {
) {
return false;
}
} else if (this.currentStage == 1) {
if (
(this.valdateLogin(this.fieldsVal.natural.personAuthLogin)) &&
(this.valdatePass(this.fieldsVal.natural.personAuthPass, this.fieldsVal.natural.personAuthPassRepeat))
) {
return false;
}
}
}
}
return true;
},
formFilledRight() {
if (((this.fieldsVal.juridical.companyInn !== "") &&
(this.fieldsVal.juridical.companyKpp !== "") &&
(this.fieldsVal.juridical.companyJurAddress !== "") &&
(this.fieldsVal.juridical.companyChiefFullname !== "") &&
(this.fieldsVal.juridical.companyChiefActingUnder !== "") &&
(this.fieldsVal.juridical.companyContactFullname !== "") &&
(this.fieldsVal.juridical.companyContactEmail !== "") &&
(this.fieldsVal.juridical.companyContactPhone !== "") &&
(this.fieldsVal.juridical.companyAuthLogin !== "") &&
(this.fieldsVal.juridical.companyAuthPass !== "") &&
(this.fieldsVal.juridical.companyAuthPassRepeat !== "")) ||
((this.fieldsVal.natural.personInfoFirstname !== "") &&
(this.fieldsVal.natural.personInfoPatronymic !== "") &&
(this.fieldsVal.natural.personInfoEmail !== "") &&
(this.fieldsVal.natural.personInfoPhone !== "") &&
(this.fieldsVal.natural.personPassportNumber !== "") &&
(this.fieldsVal.natural.personPassportIssuedBy !== "") &&
(this.fieldsVal.natural.personPassportIssuedDate !== "") &&
(this.fieldsVal.natural.personPassportDepartmentCode !== "") &&
(this.fieldsVal.natural.personAuthLogin !== "") &&
(this.fieldsVal.natural.personAuthPass !== "") &&
(this.fieldsVal.natural.personAuthPassRepeat !== ""))) {
if (this.fieldsVal.juridical.companyInn.length == 10) {
return true
} else {
return false
}
} else {
return false;
if (this.currentPT == "juridical") {
if (
(this.validateInn(this.fieldsVal.juridical.companyInn)) &&
(this.validateKpp(this.fieldsVal.juridical.companyKpp)) &&
(this.fieldsVal.juridical.companyJurAddress !== "") &&
(this.valdateName(this.fieldsVal.juridical.companyChiefFullname)) &&
(this.valdateName(this.fieldsVal.juridical.companyChiefActingUnder)) &&
(this.valdateName(this.fieldsVal.juridical.companyContactSecondName)) &&
(this.valdateName(this.fieldsVal.juridical.companyContactFirstName)) &&
(this.valdateName(this.fieldsVal.juridical.companyContactLastName)) &&
(this.valdateMail(this.fieldsVal.juridical.companyContactEmail)) &&
(this.valdatePhone(this.fieldsVal.juridical.companyContactPhone)) &&
(this.valdateLogin(this.fieldsVal.juridical.companyAuthLogin)) &&
(this.valdatePass(this.fieldsVal.juridical.companyAuthPass, this.fieldsVal.juridical.companyAuthPassRepeat))
) {
return true;
}
} else if (this.currentPT == "natural") {
if (
(this.valdateName(this.fieldsVal.natural.personInfoLastname)) &&
(this.valdateName(this.fieldsVal.natural.personInfoFirstname)) &&
(this.valdateName(this.fieldsVal.natural.personInfoPatronymic)) &&
(this.valdateMail(this.fieldsVal.natural.personInfoEmail)) &&
(this.valdatePhone(this.fieldsVal.natural.personInfoPhone)) &&
(this.valdatePassSer(this.fieldsVal.natural.personPassportSeries)) &&
(this.valdatePassNum(this.fieldsVal.natural.personPassportNumber)) &&
(this.valdateName(this.fieldsVal.natural.personPassportIssuedBy)) &&
(this.valdatePassDate(this.fieldsVal.natural.personPassportIssuedDate)) &&
(this.valdateName(this.fieldsVal.natural.personPassportDepartmentCode)) &&
(this.valdateLogin(this.fieldsVal.natural.personAuthLogin)) &&
(this.valdatePass(this.fieldsVal.natural.personAuthPass, this.fieldsVal.natural.personAuthPassRepeat))
) {
return true;
}
}
return false;
},
},
watch: {
personType() {
this.currentPT = this.personType;
this.currentStage = 0
},
......@@ -206,26 +276,157 @@ Vue.component('app-registration-form', {
}
},
methods: {
selectTrans(e){
this.localRecord.wGroup = e;
this.transportUnitsLoad();
},
addUnit(index){
alert(this.wUnitsSelect.options.length);
this.wUnitAmounts.push({});
},
test3(index,e){
this.wUnitAmounts[index].value = e.value;
this.wUnitAmounts[index].label = e.caption;
//alert(JSON.stringify(e));
},
transportGroupUrl(){
return 'https://r52.ru/api/transport/getTypes/';
},
transportUnitsUrl(id){
return 'https://r52.ru/api/transport/getUnits/' + id;
},
transportGroupLoad(){
axios
.get(this.transportGroupUrl())
.then(response => response.data)
.then(options => {
this.wGroupSelect.options = options;
//this.$set(this.wGroupSelect, 'options', options);
//this.localRecord.wGroup = options[0];
//this.transportUnitsLoad();
})
},
transportUnitsLoad(){
axios
.get(this.transportUnitsUrl())
.then(response => response.data)
.then(options => {
this.$set(this.wUnitsSelect, 'options', options);
this.wUnitAmounts = [{}];
//this.wUnitAmounts[0] = options[0];
})
},
fiasInit() {
let $this = this;
$.fias.token = 'tiyhha6YHyNi6EfeyfrRrdrDQkyehf59';
$.fias.url = 'https://kladr-api.com/api.php';
let $container = $(this.$refs.address);
let $region = $container.find('[name="region"]');
$.fias.setDefault({
parentInput: $container,
verify: true,
select: function (obj) {},
checkBefore: function () {
let $input = $(this);
if (!$.trim($input.val())) {
$input.parents('label').removeClass('field-text_error');
return false;
}
},
check: function (obj) {
let $input = $(this);
if (obj) {
$input.parents('label').removeClass('field-text_error');
}
else {
$input.parents('label').addClass('field-text_error');
}
},
change: function (obj) {
let $input = $(this);
if (obj) {
if (obj.parents) {
$.fias.setValues(obj.parents, $container);
}
$this.localRecord.wAddress[obj.contentType].id = obj.id;
$this.localRecord.wAddress[obj.contentType].name = obj.name;
$input.parents('label').removeClass('field-text_error');
} else {
$this.localRecord.wAddress[$input.attr('name')].id = null;
$this.localRecord.wAddress[$input.attr('name')].name = '';
if ($.trim($input.val())) {
$input.parents('label').addClass('field-text_error');
}
}
}
});
$region.fias('type', $.fias.type.region);
},
txtForRegButton() {
if (this.personRegTypeProp == "new") {
return "Зарегистрироваться"
} else if (this.personRegTypeProp == "customer") {
return "Добавить заказчика"
} else if (this.personRegTypeProp == "executor") {
return "Добавить исполнителя"
}
},
typeOfStages() {
if (this.personRegTypeProp == "executor") {
return {
juridical: ['Информация о компании','Контактное лицо','Информация о транспорте'],
natural: ['Информация о физическом лице','Информация о транспорте'],
}
} else {
return {
juridical: ['Информация о компании','Контактное лицо','Авторизационные данные'],
natural: ['Информация о физическом лице','Авторизационные данные'],
}
}
},
prevStage() {
this.currentStage --
},
nextStage() {
this.currentStage ++
},
orderProcessing() {
$.ajax({
url: "addNewCustomer.php",
data: {
"date": this.fieldsVal[this.currentPT],
},
dataType: "html",
type: "post",
success: function (data) {
$('.results').html(data);
//window.location.href = "/customers/";
}
})
sendform() {
if (this.formFilledRight) {
$.ajax({
url: "form.php",
data: {
"date": this.fieldsVal[this.currentPT],
},
dataType: "html",
type: "post",
success: function (data) {
data = JSON.parse(data);
if (data.success) {
window.location.href = "/customers/" + data.ID + '/';
} else {
alert = '<div class=\'row wrap_alert_error\' >' +
'<div class=\'offset-lg-1 col-lg-10 offset-xl-2 col-xl-8\'>' +
'<div class=\'block block_red block_p-40 error__alert\'>' +
data.error +
'</div>' +
'</div>' +
'</div>';
$('.wrap_alert_error').remove();
$('.title').after(alert);
}
}
})
}
},
validateBik(bik, error) {
......@@ -575,17 +776,7 @@ Vue.component('app-registration-form', {
<!-- Debug --->
<div style="display: block; position: fixed; right: 0;top: 0%; background-color:#fff; z-index:1000; width: 300px; padding: 10px; border: 1px solid #999;">
{{ fieldsVal[currentPT] }}
</div>
<div style="display: block; position: fixed; left: 0;top: 0%; background-color:#fff; z-index:1000; width: 300px; padding: 10px; border: 1px solid #999;">
<pre>
{{ localRecord }}<br><br>
{{ wUnitAmounts }}
{{currentStage}}
</pre>
{{ buttonRegTxt }}
</div>
<!-- end Debug --->
......@@ -611,6 +802,7 @@ Vue.component('app-registration-form', {
</div>
<div class="order-registration__stages-wrap">
<a href=""
:class="['order-registration__stages-item', (index === currentStage) ? 'active' : '']"
......@@ -628,7 +820,7 @@ Vue.component('app-registration-form', {
</div>
<!-- Form content -->
<form onsubmit="orderProcessing('submit!');return false" class="block_yellow block_bg-color-white block_p-40">
<div class="block_yellow block_bg-color-white block_p-40">
<!-- Yuridicheskoe litso -->
<template v-if="currentPT === 'juridical'">
......@@ -915,10 +1107,183 @@ Vue.component('app-registration-form', {
</div>
</div>
<div class="order-registration__stage-block"
v-else-if="(currentStage === 2) && (is_executor)"
>
<!-- Информация о транспорте -->
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset">
<legend class="form__legend">Информация о транспорте</legend>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__input-wrap">
<field-select
v-bind="wGroupSelect"
:init="localRecord.wGroup"
@change="selectTrans($event)"
>
</field-select>
</span>
</label>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Транспорт <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Транспорт"
class="field-text__input"
v-model="fieldsVal.juridical.companyContactPhone"
>
</span>
</label>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Гос. номер <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Гос. номер"
class="field-text__input"
v-model="fieldsVal.juridical.companyContactPhone"
>
</span>
</label>
</div>
<label class="field-text">
<span class="field-text__name">Комментарий</span>
<span class="field-text__input-wrap">
<textarea class="field-text__input"
name="comment"
placeholder="Комментарий"
v-model="fieldsVal.juridical.companyExtraComment"
></textarea>
</span>
</label>
</fieldset>
</div>
</div>
<div class="hr"></div>
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset">
<legend class="form__legend">Транспортировка</legend>
<div class="block_orange-b">
<fieldset class="form__fieldset form__fieldset_address" ref="address">
<label class="field-text">
<span class="field-text__name">
Область транспортировки<span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input
name="region"
type="text"
placeholder="Область"
class="field-text__input"
@click="fiasInit()"
v-model="localRecord.wAddress.region.name"
/>
</span>
</label>
</fieldset>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Стоимость транспортировки за 1 км <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Стоимость транспортировки"
class="field-text__input"
v-model="fieldsVal.juridical.companyTransportCostPerKm"
>
</span>
</label>
</div>
</fieldset>
</div>
</div>
<div class="hr"></div>
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset form__fieldset_address">
<legend class="form__legend">Характеристики</legend>
<div class="block_purple-b" v-for="(unitItem, index) in wUnitAmounts">
<div class="row">
<div class="col-8 col-sm-8">
<label class="field-text">
<span class="field-text__name">Вместимость<span style="color: red;">*</span></span>
<span class="field-text__input-wrap">
<input
name="street"
type="text"
placeholder="Количество"
class="field-text__input"
v-model="unitItem.amount"
>
</span>
</label>
</div>
<div class="col-4 col-sm-4">
<label class="field-text">
<span class="field-text__input-wrap">
<field-select
v-bind="wUnitsSelect"
:init="unitItem"
@change="test3(index,$event)"
>
</field-select>
</span>
</label>
</div>
<div class="add-btn"
v-if="((index === wUnitAmounts.length-1) && (index < (wUnitsSelect.options.length - 1)))">
<a class="btn btn_secondary btn_icon"
href="javascript:void(0);"
@click="addUnit(index)">
<span class="btn__icon i-plus"></span>
</a>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div class="order-registration__stage-block"
v-else-if="currentStage === 2"
v-else-if="(currentStage === 2) && (!is_executor)"
>
<!-- Авторизационные данные -->
<div class="row">
......@@ -943,9 +1308,9 @@ Vue.component('app-registration-form', {
<label class="field-text">
<span class="field-text__name">Пароль <span style="color: red;">*</span></span>
<span class="field-text__input-wrap">
<input type="newpassword"
<input type="password"
placeholder="Пароль"
name="newpassword"
name="password"
class="field-text__input"
v-model="fieldsVal.juridical.companyAuthPass"
>
......@@ -956,7 +1321,7 @@ Vue.component('app-registration-form', {
<label class="field-text">
<span class="field-text__name">Повторите пароль <span style="color: red;">*</span></span>
<span class="field-text__input-wrap">
<input type="newpassword"
<input type="password"
placeholder="Повторите пароль"
name="passrepeat"
class="field-text__input"
......@@ -986,7 +1351,7 @@ Vue.component('app-registration-form', {
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">Фамилия</span>
<span class="field-text__name">Фамилия <span style="color: red;">*</span></span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Фамилия"
......@@ -1192,7 +1557,183 @@ Vue.component('app-registration-form', {
<div class="order-registration__stage-block"
v-else-if="currentStage === 1"
v-else-if="(currentStage === 1) && (is_executor)"
>
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset">
<legend class="form__legend">Информация о транспорте</legend>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__input-wrap">
<field-select
v-bind="wGroupSelect"
:init="localRecord.wGroup"
@change="selectTrans($event)"
>
</field-select>
</span>
</label>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Транспорт <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Транспорт"
class="field-text__input"
v-model="fieldsVal.juridical.companyContactPhone"
>
</span>
</label>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Гос. номер <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Гос. номер"
class="field-text__input"
v-model="fieldsVal.juridical.companyContactPhone"
>
</span>
</label>
</div>
<label class="field-text">
<span class="field-text__name">Комментарий</span>
<span class="field-text__input-wrap">
<textarea class="field-text__input"
name="comment"
placeholder="Комментарий"
v-model="fieldsVal.juridical.companyExtraComment"
></textarea>
</span>
</label>
</fieldset>
</div>
</div>
<div class="hr"></div>
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset">
<legend class="form__legend">Транспортировка</legend>
<div class="block_orange-b">
<fieldset class="form__fieldset form__fieldset_address" ref="address">
<label class="field-text">
<span class="field-text__name">
Область транспортировки<span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input
name="region"
type="text"
placeholder="Область"
class="field-text__input"
@click="fiasInit()"
v-model="localRecord.wAddress.region.name"
/>
</span>
</label>
</fieldset>
</div>
<div class="block_orange-b">
<label class="field-text">
<span class="field-text__name">
Стоимость транспортировки за 1 км <span style="color: red;">*</span>
</span>
<span class="field-text__input-wrap">
<input type="text"
placeholder="Стоимость транспортировки"
class="field-text__input"
v-model="fieldsVal.juridical.companyContactPhone"
>
</span>
</label>
</div>
</fieldset>
</div>
</div>
<div class="hr"></div>
<div class="row">
<div class="offset-sm-2 col-sm-8 offset-md-3 col-md-6">
<fieldset class="form__fieldset form__fieldset_address">
<legend class="form__legend">Характеристики</legend>
<div class="block_purple-b" v-for="(unitItem, index) in wUnitAmounts">
<div class="row">
<div class="col-8 col-sm-8">
<label class="field-text">
<span class="field-text__name">Вместимость<span style="color: red;">*</span></span>
<span class="field-text__input-wrap">
<input
name="street"
type="text"
placeholder="Количество"
class="field-text__input"
v-model="unitItem.amount"
>
</span>
</label>
</div>
<div class="col-4 col-sm-4">
<label class="field-text">
<span class="field-text__input-wrap">
<field-select
v-bind="wUnitsSelect"
:init="unitItem"
@change="test3(index,$event)"
>
</field-select>
</span>
</label>
</div>
<div class="add-btn"
v-if="(index < (wUnitsSelect.options.length - 2))">
<a class="btn btn_secondary btn_icon"
href="javascript:void(0);"
@click="addUnit(index)">
<span class="btn__icon i-plus"></span>
</a>
</div>
</div>
</div>
</fieldset>
</div>
</div>
</div>
<div class="order-registration__stage-block"
v-else-if="(currentStage === 1) && (!is_executor)"
>
<!-- Авторизационные данные -->
<div class="row">
......@@ -1269,12 +1810,15 @@ Vue.component('app-registration-form', {
v-if="lastStage"
type="submit"
:disabled="!formFilledRight"
>Зарегистрироваться</button>
@click="sendform"
>{{ buttonRegTxt }}</button>
<div>
<div
v-if="!lastestStage">
<button type="button"
class="btn btn_primary"
@click="nextStage"
v-if="(!lastStage)"
:disabled="nextpage"
>Далее</button>
</div>
......@@ -1283,7 +1827,7 @@ Vue.component('app-registration-form', {
</div>
</form>
</div>
</div>
`
......
Vue.component('app-registration', {
props: {
reg_info_from: {
type: String
}
},
data: function () {
return {
persons: {
juridical: 'Юридическое лицо',
natural: 'Физическое лицо',
},
activeType: 'juridical'
activeType: 'juridical',
reg_info_to: this.reg_info_from,
}
},
template: `
<div class="row">
<div class="offset-lg-1 col-lg-10 offset-xl-2 col-xl-8">
<div class="order-registration__user-types">
<a href=""
......@@ -27,6 +33,7 @@ Vue.component('app-registration', {
<app-registration-form
:personType="activeType"
:personRegTypeProp="reg_info_to"
></app-registration-form>
</div>
......
......@@ -20,7 +20,7 @@ block page
h1.title!=title
app-registration
app-registration(:reg_info_from="'executor'")
br
br
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment