Код: Выделить всё
{{ 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