Joywork/js/deals_client_vue.js
2026-06-21 09:11:22 +03:00

61 lines
2.0 KiB
JavaScript

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.get('/api/deals/' + dealId).then(r => r.data.data).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) {
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() {
// Автоматически загружаем список при монтировании
}
});