250 lines
7.7 KiB
JavaScript
Raw Normal View History

2021-05-21 14:13:09 +03:00
2021-05-20 15:18:43 +03:00
export default {
data: function () {
return {
currentTab: undefined,
newDatas: false,
model: {
name: "",
rate: "",
select: "",
enabled: 1
},
2021-05-21 16:46:58 +03:00
error_field: {}
2021-05-20 15:18:43 +03:00
}
},
methods: {
addItem() {
this.newDatas = true;
this.currentTab = undefined;
2021-05-24 10:48:58 +03:00
this.error_field = {};
2021-05-21 13:56:01 +03:00
2021-05-20 15:18:43 +03:00
if (this.model) {
this.model.name = '';
this.model.rate = '';
this.model.select = '';
}
},
handeClickEdit(item, index) {
this.newDatas = false;
this.currentTab = index;
2021-05-24 10:48:58 +03:00
this.error_field = {};
2021-05-21 13:56:01 +03:00
2021-05-20 15:18:43 +03:00
if (this.model) {
this.model.name = item.name ? item.name : '';
this.model.rate = item.rate ? item.rate : '';
this.model.select = item.code ? item.code : '';
}
},
2021-05-27 19:35:19 +03:00
2021-05-26 18:45:39 +03:00
handleClickCancel() {
this.currentTab = undefined;
},
2021-05-27 19:35:19 +03:00
dataHandleEvent() {
this.newDatas = false;
this.currentTab = undefined;
this.model.name = '';
this.model.rate = '';
this.model.select = '';
this.model.enabled = 1;
},
2021-05-27 19:35:19 +03:00
onSuccessEvent(response) {
let type = response.data.success ? 'success' : 'error';
let timeout = 1000;
2021-05-27 19:35:19 +03:00
if (response.data.important) {
timeout = 0;
}
this.$notify({
message: response.data.message,
timeout: timeout,
icon: "fas fa-bell",
type,
});
this.dataHandleEvent();
},
2021-05-27 19:35:19 +03:00
onSuccessDelete(event) {
let type = event.success ? 'success' : 'error';
let timeout = 1000;
2021-05-27 19:35:19 +03:00
if (event.important) {
timeout = 0;
}
this.$notify({
message: event.message,
timeout: timeout,
icon: "fas fa-bell",
type,
});
this.dataHandleEvent();
},
2021-05-27 19:35:19 +03:00
2021-05-20 15:18:43 +03:00
onEditEvent(form_method, form_url, plus_data, form_list, form_id) {
const formData = new FormData(this.$refs["form"]);
const data = {};
let file = {};
2021-05-20 15:18:43 +03:00
for (let [key, val] of formData.entries()) {
Object.assign(data, {
[key]: val,
});
}
if(plus_data == 'type') {
Object.assign(data, {
['type']: 'normal',
});
2021-05-20 15:18:43 +03:00
}
2021-05-21 13:56:01 +03:00
2021-05-20 15:18:43 +03:00
window.axios({
method: form_method,
url: form_url,
data: data,
})
.then(response => {
2021-05-21 13:56:01 +03:00
if (form_list.length) {
form_list.forEach(item => {
if (item.id == form_id) {
item.name = response.data.data.name;
item.code = response.data.data.code;
item.rate = response.data.data.rate;
item.type = plus_data == undefined ? 'normal' : ''
}
});
}
2021-05-20 15:18:43 +03:00
this.onSuccessEvent(response);
2021-05-21 14:13:09 +03:00
}, this)
2021-05-20 15:18:43 +03:00
.catch(error => {
2021-05-21 14:13:09 +03:00
this.onFailError(error)
}, this);
2021-05-20 15:18:43 +03:00
},
2021-05-27 19:35:19 +03:00
2021-05-20 15:18:43 +03:00
onSubmitEvent(form_method, form_url, plus_data, form_list) {
const formData = new FormData(this.$refs["form"]);
const data = {};
for (let [key, val] of formData.entries()) {
Object.assign(data, {
[key]: val,
});
}
if(plus_data == 'type') {
Object.assign(data, {
['type']: 'normal',
});
2021-05-20 15:18:43 +03:00
}
window.axios({
method: form_method,
url: form_url,
data: data,
})
.then(response => {
form_list.push({
"id": response.data.data.id,
"name": response.data.data.name,
"code": response.data.data.code,
"rate": response.data.data.rate,
"enabled": response.data.data.enabled != undefined ? response.data.data.enabled : 'true'
});
this.onSuccessEvent(response);
2021-05-21 14:13:09 +03:00
}, this)
2021-05-20 15:18:43 +03:00
.catch(error => {
2021-05-21 18:26:46 +03:00
this.onFailError(error);
2021-05-21 14:13:09 +03:00
}, this);
2021-05-20 15:18:43 +03:00
},
2021-05-27 19:35:19 +03:00
onEditCompany() {
FormData.prototype.appendRecursive = function(data, wrapper = null) {
for(var name in data) {
if (name == "previewElement" || name == "previewTemplate") {
continue;
}
if (wrapper) {
if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], wrapper + '[' + name + ']');
} else {
this.append(wrapper + '[' + name + ']', data[name]);
}
} else {
if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
this.appendRecursive(data[name], name);
} else {
this.append(name, data[name]);
}
}
}
}
const formData = new FormData(this.$refs["form"]);
let data_name = {};
for (let [key, val] of formData.entries()) {
Object.assign(data_name, {
[key]: val,
2021-05-28 10:04:51 +03:00
['logo']: this.$refs.dropzoneWizard.files[1] ? this.$refs.dropzoneWizard.files[1] : this.$refs.dropzoneWizard.files[0],
2021-05-27 19:35:19 +03:00
['_prefix']: 'company',
['_token']: window.Laravel.csrfToken,
2021-05-28 10:04:51 +03:00
['_method']: 'POST',
2021-05-27 19:35:19 +03:00
});
}
formData.appendRecursive(data_name);
window.axios({
2021-05-28 10:04:51 +03:00
method: 'POST',
2021-05-27 19:35:19 +03:00
url: url + "/wizard/companies",
data: formData,
headers: {
'X-CSRF-TOKEN': window.Laravel.csrfToken,
'X-Requested-With': 'XMLHttpRequest',
'Content-Type': 'multipart/form-data'
}
})
.then(response => {
this.onSuccessEvent(response);
}, this)
.catch(error => {
this.onFailError(error)
}, this);
},
2021-05-21 14:34:05 +03:00
onDeleteEvent(event, form_list, event_id) {
form_list.forEach(function (item, index) {
if (item.id == event_id) {
form_list.splice(index, 1);
return;
}
}, this);
2021-05-27 19:35:19 +03:00
2021-05-21 14:34:05 +03:00
this.component = "";
2021-05-27 19:35:19 +03:00
2021-05-21 14:34:05 +03:00
this.onSuccessDelete(event);
},
2021-05-27 19:35:19 +03:00
2021-05-24 10:48:58 +03:00
onFailErrorGet(field_name) {
if(this.error_field[field_name]) {
return this.error_field[field_name][0];
}
},
2021-05-27 19:35:19 +03:00
2021-05-21 13:56:01 +03:00
onFailError(error) {
2021-05-21 16:46:58 +03:00
this.error_field = error.response.data.errors;
2021-05-21 13:56:01 +03:00
}
2021-05-24 10:48:58 +03:00
}
2021-05-20 15:18:43 +03:00
}