Anonymous
Получение модального отображения при нажатии кнопки
Сообщение
Anonymous » 28 май 2024, 22:47
Я пытаюсь прикрепить модальное окно к кнопке «Сохранить», когда нажимаю на нее. Мне не повезло, и я пытаюсь добавить операторы отладки, но на мою консоль ничего не выводится. Я создал новый контроллер для этой функции, а также новые методы Vue и API. Когда я переключаю showModal на true и получаю его немедленно, я выбираю «Да», чтобы отправить опрос, и также получаю неопределенное значение. Вот код, указанный ниже.
Код: Выделить всё
{{ modalMessage }}
[url=surveyLink]Send Satisfaction Survey[/url]
Yes
No
import ReadTicketitem from "../TicketItem/ReadTicketitem.vue";
import UpdateTicket from "../Ticket/UpdateTicket.vue";
import SendSurvey from "../Surveys/SendSurvey.vue";
import axios from "axios";
export default {
components: {
ReadTicketitem,
UpdateTicket,
CreateTicketitem,
Layout,
SendSurvey,
},
mounted() {
this.loadTicket();
},
data() {
return {
showModal: false,
modalMessage: "",
surveyLink: "",
};
},
methods: {
closeModal() {
this.edit = false;
},
loadTicket() {
const ticketId = this.$route.params.id;
axios
.get(this.CONSTANTS.api + "GetTicket", {
params: { id: ticketId },
})
.then((response) => {
this.ticket = response.data;
let date1 = this.ticket.created.split("T");
let date2 = this.ticket.duedate.split("T");
this.ticketCreatedDate = date1[0];
this.ticket.duedate = date2[0];
this.readTicketItemLoaded = true;
this.loadTicketImages();
});
},
editTicket() {
this.edit = true;
},
confirmSendSurvey() {
this.showModal = false;
const surveyData = {
id: this.ticket.ticketid,
email: this.ticket.contactemail,
};
axios
.post(this.CONSTANTS.api + "SendSurvey", surveyData)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
},
cancelSendSurvey() {
this.showModal = false;
},
},
};
Save```
public function checkTicketAndAttachSurvey(Request $request)
{
try {
$this->validate($request, [
'id' => 'required|integer',
'survey_type' => 'required|integer'
]);
$id = $request->input('id');
$survey_type = $request->input('survey_type');
$ticketStatus = $this->statusOfTicket($id);
if ($ticketStatus === 'was_sent') {
return response()->json(['status' => 'was_sent', 'message' => 'The survey has already been sent.']);
}
if ($survey_type == 2) {
$ticket = $this->getTicketDetails($id);
return $this->ticketCompleteion($ticket);
}
return response()->json(['status' => 'not_required', 'message' => 'Survey not required.']);
} catch (ValidationException $e) {
return response()->json([
'status' => 'error',
'message' => 'Invalid input parameters',
'errors' => $e->errors()
], 422);
} catch (Exception $e) {
return response()->json([
'status' => 'error',
'message' => 'An error occurred while processing the request',
'error' => $e->getMessage()
], 500);
}
}
private function statusOfTicket($id)
{
return ($id % 2 == 0) ? 'was_sent' : 'was_not_sent';
}
Route::get('check-ticket-and-attach-survey', [SurveyController::class, 'checkTicketAndAttachSurvey'])
->name('check-ticket-and-attach-survey');
Я пробовал добавлять операторы отладки и перемещать код.
Подробнее здесь:
https://stackoverflow.com/questions/785 ... is-clicked
1716925664
Anonymous
Я пытаюсь прикрепить модальное окно к кнопке «Сохранить», когда нажимаю на нее. Мне не повезло, и я пытаюсь добавить операторы отладки, но на мою консоль ничего не выводится. Я создал новый контроллер для этой функции, а также новые методы Vue и API. Когда я переключаю showModal на true и получаю его немедленно, я выбираю «Да», чтобы отправить опрос, и также получаю неопределенное значение. Вот код, указанный ниже. [code] {{ modalMessage }} [url=surveyLink]Send Satisfaction Survey[/url] Yes No import ReadTicketitem from "../TicketItem/ReadTicketitem.vue"; import UpdateTicket from "../Ticket/UpdateTicket.vue"; import SendSurvey from "../Surveys/SendSurvey.vue"; import axios from "axios"; export default { components: { ReadTicketitem, UpdateTicket, CreateTicketitem, Layout, SendSurvey, }, mounted() { this.loadTicket(); }, data() { return { showModal: false, modalMessage: "", surveyLink: "", }; }, methods: { closeModal() { this.edit = false; }, loadTicket() { const ticketId = this.$route.params.id; axios .get(this.CONSTANTS.api + "GetTicket", { params: { id: ticketId }, }) .then((response) => { this.ticket = response.data; let date1 = this.ticket.created.split("T"); let date2 = this.ticket.duedate.split("T"); this.ticketCreatedDate = date1[0]; this.ticket.duedate = date2[0]; this.readTicketItemLoaded = true; this.loadTicketImages(); }); }, editTicket() { this.edit = true; }, confirmSendSurvey() { this.showModal = false; const surveyData = { id: this.ticket.ticketid, email: this.ticket.contactemail, }; axios .post(this.CONSTANTS.api + "SendSurvey", surveyData) .then((response) => { console.log(response); }) .catch((error) => { console.log(error); }); }, cancelSendSurvey() { this.showModal = false; }, }, }; Save``` public function checkTicketAndAttachSurvey(Request $request) { try { $this->validate($request, [ 'id' => 'required|integer', 'survey_type' => 'required|integer' ]); $id = $request->input('id'); $survey_type = $request->input('survey_type'); $ticketStatus = $this->statusOfTicket($id); if ($ticketStatus === 'was_sent') { return response()->json(['status' => 'was_sent', 'message' => 'The survey has already been sent.']); } if ($survey_type == 2) { $ticket = $this->getTicketDetails($id); return $this->ticketCompleteion($ticket); } return response()->json(['status' => 'not_required', 'message' => 'Survey not required.']); } catch (ValidationException $e) { return response()->json([ 'status' => 'error', 'message' => 'Invalid input parameters', 'errors' => $e->errors() ], 422); } catch (Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'An error occurred while processing the request', 'error' => $e->getMessage() ], 500); } } private function statusOfTicket($id) { return ($id % 2 == 0) ? 'was_sent' : 'was_not_sent'; } Route::get('check-ticket-and-attach-survey', [SurveyController::class, 'checkTicketAndAttachSurvey']) ->name('check-ticket-and-attach-survey'); [/code] Я пробовал добавлять операторы отладки и перемещать код. Подробнее здесь: [url]https://stackoverflow.com/questions/78545682/getting-modal-to-appear-when-button-is-clicked[/url]