|
|
|
@ -288,23 +288,22 @@ |
|
|
|
|
|
|
|
|
|
|
|
//Получить заказы |
|
|
|
//Получить заказы |
|
|
|
function getStages(orderId, senderId, recipentId, secureOrder) { |
|
|
|
function getStages(orderId, senderId, recipentId, secureOrder) { |
|
|
|
|
|
|
|
|
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
url: '/api/stages/', |
|
|
|
url:'/api/orders/' + orderId + '/', |
|
|
|
type: 'GET', |
|
|
|
type: 'GET', |
|
|
|
data: {csrfmiddlewaretoken: csrftoken, 'order': orderId}, |
|
|
|
data:{csrfmiddlewaretoken: csrftoken}, |
|
|
|
dataType: 'json', |
|
|
|
dataType: 'json', |
|
|
|
success: function (json) { |
|
|
|
|
|
|
|
var stageCount = json.results.length; |
|
|
|
}).then(function(data){ |
|
|
|
|
|
|
|
var stagesResults = data.stages; |
|
|
|
|
|
|
|
var stageCount = stagesResults.length; |
|
|
|
if (stageCount == 0) { |
|
|
|
if (stageCount == 0) { |
|
|
|
$("#reserveSpace").hide(); |
|
|
|
$("#reserveSpace").hide(); |
|
|
|
stageCountVal = 1; |
|
|
|
stageCountVal = 1; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
stageCountVal = stageCount; |
|
|
|
stageCountVal = stageCount; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var htmlInbox = ""; |
|
|
|
var htmlInbox = ""; |
|
|
|
|
|
|
|
|
|
|
|
var htmlInboxStage = '<p class="textStepss">Какое кол-во этапов подразумевает работа? ' + |
|
|
|
var htmlInboxStage = '<p class="textStepss">Какое кол-во этапов подразумевает работа? ' + |
|
|
|
'<input type="text" id="countStage" value="' + stageCountVal + '"size="3"/></p>'; |
|
|
|
'<input type="text" id="countStage" value="' + stageCountVal + '"size="3"/></p>'; |
|
|
|
|
|
|
|
|
|
|
|
@ -320,13 +319,19 @@ |
|
|
|
'</form></div>'; |
|
|
|
'</form></div>'; |
|
|
|
} |
|
|
|
} |
|
|
|
var statusNotAgreed = true; |
|
|
|
var statusNotAgreed = true; |
|
|
|
|
|
|
|
var stagesInWork = []; |
|
|
|
var stagesPaidProcess = []; |
|
|
|
var stagesPaidProcess = []; |
|
|
|
|
|
|
|
|
|
|
|
$.each(json.results, function (i, v) { |
|
|
|
$.each(stagesResults, function (i, v) { |
|
|
|
|
|
|
|
if(!data.secure){ |
|
|
|
if ((v.status == "in_process") && (v.is_paid)){ |
|
|
|
if(v.status == "in_process") { |
|
|
|
|
|
|
|
stagesInWork.push(v); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}else if ((v.status == "in_process") && (v.is_paid)){ |
|
|
|
|
|
|
|
stagesInWork.push(v); |
|
|
|
stagesPaidProcess.push(v); |
|
|
|
stagesPaidProcess.push(v); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (v.status == "not_agreed") { |
|
|
|
if (v.status == "not_agreed") { |
|
|
|
htmlInbox += '<div class="numberStepp box-sizing">' + |
|
|
|
htmlInbox += '<div class="numberStepp box-sizing">' + |
|
|
|
'<p>Этап</p><form class="update-stages-form" data-stage-id="' + v.id + '" id="stage-form-' + v.pos + '">' + |
|
|
|
'<p>Этап</p><form class="update-stages-form" data-stage-id="' + v.id + '" id="stage-form-' + v.pos + '">' + |
|
|
|
@ -349,8 +354,8 @@ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (statusNotAgreed) { |
|
|
|
if (statusNotAgreed) { |
|
|
|
if(secureOrder) { |
|
|
|
if(!data.secure) { |
|
|
|
var orderSecureCheckbox = 'checked="checked"'; |
|
|
|
var orderSecureCheckbox = ''; |
|
|
|
htmlInbox += '<div class="box-sizing disTab">' + |
|
|
|
htmlInbox += '<div class="box-sizing disTab">' + |
|
|
|
'<div class="checkbox"><input name="secure" id="secureOrder"'+ orderSecureCheckbox +'type="checkbox" style="opacity:1">' + |
|
|
|
'<div class="checkbox"><input name="secure" id="secureOrder"'+ orderSecureCheckbox +'type="checkbox" style="opacity:1">' + |
|
|
|
'Перейти в режим безопасной сделки</div></div>'; |
|
|
|
'Перейти в режим безопасной сделки</div></div>'; |
|
|
|
@ -360,28 +365,26 @@ |
|
|
|
'<a href="#" data-sender-id="' + senderId +'" ' + |
|
|
|
'<a href="#" data-sender-id="' + senderId +'" ' + |
|
|
|
'data-recipent-id="' + recipentId +'" data-order-id="' + orderId + '" ' + |
|
|
|
'data-recipent-id="' + recipentId +'" data-order-id="' + orderId + '" ' + |
|
|
|
'id="addStagesForm">отправить на согласование</a> </div>'; |
|
|
|
'id="addStagesForm">отправить на согласование</a> </div>'; |
|
|
|
}else if(json.results.length>0){ |
|
|
|
}else if((stagesResults.length>0) && (data.secure)){ |
|
|
|
$("#reserveSpace").show(); |
|
|
|
$("#reserveSpace").show(); |
|
|
|
} |
|
|
|
} |
|
|
|
htmlInbox = htmlInboxStage + htmlInbox; |
|
|
|
htmlInbox = htmlInboxStage + htmlInbox; |
|
|
|
$("#order-stages").html(htmlInbox); |
|
|
|
$("#order-stages").html(htmlInbox); |
|
|
|
|
|
|
|
$("#completeWork").hide(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(stagesInWork.length > 0){ |
|
|
|
if (stagesPaidProcess.length > 0){ |
|
|
|
|
|
|
|
$("#completeWork").show(); |
|
|
|
$("#completeWork").show(); |
|
|
|
var stage = stagesPaidProcess[0]; |
|
|
|
var stage = stagesInWork[0]; |
|
|
|
var stageWork = '<p>В работе '+ stage.name +'</p> ' + |
|
|
|
var stageWork = '<p>В работе '+ stage.name +'</p> ' + |
|
|
|
'<p>Результат этапа : '+ stage.result +'</p>' + |
|
|
|
'<p>Результат этапа : '+ stage.result +'</p>' + |
|
|
|
'<p>Срок сдачи 25.08.2016 <b>' + stage.cost + 'р.</b></p>'; |
|
|
|
'<p>Срок сдачи 25.08.2016 <b>' + stage.cost + 'р.</b></p>'; |
|
|
|
|
|
|
|
|
|
|
|
if (stage.close_contractor){ |
|
|
|
if (stage.close_contractor){ |
|
|
|
stageWork += '<a href="#" class="closeStage" data-stage-id="'+ stage.id+'">Закрыть этап '+ stage.pos +'</a>'; |
|
|
|
stageWork += '<a href="#" class="closeStage" data-order-id="'+ orderId + '" data-sender-id="{{ request.user.pk }}"' + |
|
|
|
|
|
|
|
' data-recipent-id="'+ recipentId + '" data-stage-id="'+ stage.id+'">Закрыть этап '+ stage.pos +'</a>'; |
|
|
|
} |
|
|
|
} |
|
|
|
$("#stagesWork").html(stageWork); |
|
|
|
$("#stagesWork").html(stageWork); |
|
|
|
}else{ |
|
|
|
|
|
|
|
$("#completeWork").hide(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -389,6 +392,7 @@ |
|
|
|
$('#tab2').on('click','.closeStage', function(e){ |
|
|
|
$('#tab2').on('click','.closeStage', function(e){ |
|
|
|
e.preventDefault(); |
|
|
|
e.preventDefault(); |
|
|
|
var stageId = $(this).attr('data-stage-id'); |
|
|
|
var stageId = $(this).attr('data-stage-id'); |
|
|
|
|
|
|
|
var _this = $(this); |
|
|
|
$.ajax({ |
|
|
|
$.ajax({ |
|
|
|
url: '/api/stages/' + stageId + '/', |
|
|
|
url: '/api/stages/' + stageId + '/', |
|
|
|
type: 'PATCH', |
|
|
|
type: 'PATCH', |
|
|
|
@ -398,6 +402,15 @@ |
|
|
|
data: {close_customer: true, status: 'completed'}, |
|
|
|
data: {close_customer: true, status: 'completed'}, |
|
|
|
dataType: 'json', |
|
|
|
dataType: 'json', |
|
|
|
success: function (json) { |
|
|
|
success: function (json) { |
|
|
|
|
|
|
|
socket.send_stages_approve({ |
|
|
|
|
|
|
|
"format_type": "approve_stages", |
|
|
|
|
|
|
|
"data": { |
|
|
|
|
|
|
|
"sender_id": _this.attr('data-sender-id'), |
|
|
|
|
|
|
|
"recipent_id": _this.attr('data-recipent-id'), |
|
|
|
|
|
|
|
"order_id": _this.attr('data-order-id'), |
|
|
|
|
|
|
|
"msg": "Заказчик закрыл этап " + json.name, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
console.log(json); |
|
|
|
console.log(json); |
|
|
|
}, |
|
|
|
}, |
|
|
|
error: function (e) { |
|
|
|
error: function (e) { |
|
|
|
@ -462,11 +475,14 @@ |
|
|
|
"sender_id": userId, |
|
|
|
"sender_id": userId, |
|
|
|
"recipent_id": currentRecipentId, |
|
|
|
"recipent_id": currentRecipentId, |
|
|
|
"order_id": currentOrderId, |
|
|
|
"order_id": currentOrderId, |
|
|
|
|
|
|
|
"msg": "Этапы для заказа "+ currentOrderId +"изменены", |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
setTimeout(function () { |
|
|
|
|
|
|
|
getStages(currentOrderId,userId,currentRecipentId,secureOrder); |
|
|
|
{# setTimeout(function () {#} |
|
|
|
}, 1000); |
|
|
|
{# getStages(currentOrderId,userId,currentRecipentId,secureOrder);#} |
|
|
|
|
|
|
|
{##} |
|
|
|
|
|
|
|
{# }, 1000);#} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
@ -474,33 +490,38 @@ |
|
|
|
$('#order-stages-tab').on('change', '#countStage', function () { |
|
|
|
$('#order-stages-tab').on('change', '#countStage', function () { |
|
|
|
var countStage = parseInt($(this).val()); |
|
|
|
var countStage = parseInt($(this).val()); |
|
|
|
var currentCountStage = $(".numberStepp").length; |
|
|
|
var currentCountStage = $(".numberStepp").length; |
|
|
|
|
|
|
|
if ((countStage<1) || isNaN(countStage)) { |
|
|
|
if (countStage > currentCountStage){ |
|
|
|
countStage = 1; |
|
|
|
for(var jj=currentCountStage; jj<countStage;jj++){ |
|
|
|
$('#order-stages-tab #countStage').val(currentCountStage); |
|
|
|
var pos = jj + 1; |
|
|
|
}else { |
|
|
|
var lastFormStage = $(".numberStepp").last(); |
|
|
|
if (countStage > currentCountStage) { |
|
|
|
var orderId = lastFormStage.find('.orderStagesInput').val(); |
|
|
|
for (var jj = currentCountStage; jj < countStage; jj++) { |
|
|
|
var addFormTemplate = '<div class="numberStepp box-sizing" id="stage1">' + |
|
|
|
var pos = jj + 1; |
|
|
|
'<p>Этап <span class="stage-span-id">'+ pos +'</span></p><form class="new-stages-form" id="stage-form">' + |
|
|
|
var lastFormStage = $(".numberStepp").last(); |
|
|
|
|
|
|
|
var orderId = lastFormStage.find('.orderStagesInput').val(); |
|
|
|
|
|
|
|
var addFormTemplate = '<div class="numberStepp box-sizing" id="stage1">' + |
|
|
|
|
|
|
|
'<p>Этап <span class="stage-span-id">' + pos + '</span></p><form class="new-stages-form" id="stage-form">' + |
|
|
|
'<label for="">Название</label><input class="form-control" name="name" type="text" />' + |
|
|
|
'<label for="">Название</label><input class="form-control" name="name" type="text" />' + |
|
|
|
'<label for="">Цена</label><input class="form-control" name="cost" type="text" />' + |
|
|
|
'<label for="">Цена</label><input class="form-control" name="cost" type="text" />' + |
|
|
|
'<input class="form-control orderStagesInput" name="order" type="hidden" value="' + orderId + '" />' + |
|
|
|
'<input class="form-control orderStagesInput" name="order" type="hidden" value="' + orderId + '" />' + |
|
|
|
'<label for="">Срок</label><input class="form-control" name="term" type="text" />' + |
|
|
|
'<label for="">Срок</label><input class="form-control" name="term" type="text" />' + |
|
|
|
'<label for="">Результат</label><input class="form-control" name="result" type="text" />' + |
|
|
|
'<label for="">Результат</label><input class="form-control" name="result" type="text" />' + |
|
|
|
'<input class="form-control" name="pos" value="'+ pos +'" type="hidden" />' |
|
|
|
'<input class="form-control" name="pos" value="' + pos + '" type="hidden" />' |
|
|
|
'</form></div>'; |
|
|
|
'</form></div>'; |
|
|
|
lastFormStage.after(addFormTemplate); |
|
|
|
lastFormStage.after(addFormTemplate); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if (countStage < currentCountStage) { |
|
|
|
|
|
|
|
var ii = currentCountStage; |
|
|
|
|
|
|
|
$($(".numberStepp").get().reverse()).each(function(){ |
|
|
|
|
|
|
|
var currenFormName = ($(this).find('form').attr('class')); |
|
|
|
|
|
|
|
if(ii>countStage) { |
|
|
|
|
|
|
|
$(this).remove(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
ii--; |
|
|
|
|
|
|
|
}); |
|
|
|
} else if (countStage < currentCountStage) { |
|
|
|
|
|
|
|
var ii = currentCountStage; |
|
|
|
|
|
|
|
$($(".numberStepp").get().reverse()).each(function () { |
|
|
|
|
|
|
|
var currenFormName = ($(this).find('form').attr('class')); |
|
|
|
|
|
|
|
if (ii > countStage) { |
|
|
|
|
|
|
|
$(this).remove(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ii--; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|