Joywork/js/deals_client_vue.js
2026-06-29 11:16:51 +03:00

67 lines
2.4 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Vue.config.devtools = true;
var deals_client = new Vue({
el: '#deals_list_client',
name: 'deals_list_client',
data() {
return {
dealsList: [],
isDealsClient: 0,
clientId: 0,
}
},
methods: {
getList() {
if (this.clientId > 0) {
this.dealsList = [];
this.isDealsClient = 0;
axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_deal_by_client',
client_id: this.clientId,
})
.then((response) => {
var res = response.data;
if (res.deals && res.deals.length > 0) {
var promises = res.deals.map(dealId => {
return axios.post('/ajax/ajax_vue_requisitions.php', {
request: 'get_deal_data',
deal_id: dealId,
}).then(r => r.data.deal || null).catch(() => null);
});
Promise.all(promises).then(results => {
deals_client.dealsList = results.filter(d => d !== null);
deals_client.isDealsClient = deals_client.dealsList.length > 0 ? 1 : 2;
});
} else {
this.isDealsClient = 2;
}
})
.catch(function(error) {
console.log(error);
deals_client.isDealsClient = 2;
});
}
},
openDealFromClient(dealId) {
// Закрываем модал клиента перед открытием модала сделки
// Используем .closer.click() как в заявках — полный сброс состояния
$('#send_bg_new .closer').click();
if (typeof window.editDeal === 'function') {
window.editDeal(0, dealId);
} else {
console.error('editDeal not available');
}
},
isEmpty(obj) {
for (var key in obj) {
if (obj.hasOwnProperty(key)) return false;
}
return true;
}
},
mounted() {
// Автоматически загружаем список при монтировании
}
});