vueSpecialty.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. const requestFunc = async(url, method = "GET", data = null, token = null) => {
  2. apihost = 'http://schedule.tomtit.tomsk.ru/api'
  3. method = method.toLocaleUpperCase()
  4. let fullurl = `${apihost}${url}`;
  5. let options = {
  6. method: method,
  7. headers: {
  8. "Content-Type": "application/json",
  9. "Authorization": `Bearer ${token}`,
  10. },
  11. };
  12. switch(method) {
  13. case "PUT":
  14. delete options.headers["Content-Type"];
  15. options.body = data;
  16. break;
  17. case "POST": case "PATCH": case "DELETE":
  18. options.body = JSON.stringify(data);
  19. break;
  20. }
  21. const res = await fetch(fullurl, options);
  22. return await res.json();
  23. };
  24. <<<<<<< HEAD
  25. <<<<<<< HEAD
  26. var app = new Vue({
  27. =======
  28. var vueApp = new Vue({
  29. >>>>>>> master
  30. =======
  31. var app = new Vue({
  32. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  33. el: '#app',
  34. delimiters: ['${', '}'],
  35. data: {
  36. specialties:[],
  37. <<<<<<< HEAD
  38. <<<<<<< HEAD
  39. },
  40. methods: {
  41. showSpecialties() {
  42. console.log(this.specialty)
  43. },
  44. async getSpecialties(){
  45. this.specialties = await requestFunc("/specialty", "GET")
  46. },
  47. =======
  48. selectedRow: {
  49. "Code": "",
  50. "Name": "",
  51. "IDDuration": 0,
  52. "ID": ""
  53. },
  54. requestType: null
  55. =======
  56. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  57. },
  58. methods: {
  59. showSpecialties() {
  60. console.log(this.specialty)
  61. },
  62. async getSpecialties(){
  63. this.specialties = await requestFunc("/specialty", "GET")
  64. },
  65. <<<<<<< HEAD
  66. selectRow(row, index){
  67. let rows = document.querySelectorAll('.clickHover')
  68. this.selectedRow = row;
  69. // empty string
  70. if(rows[index].style.backgroundColor != 'red'){
  71. rows[index].style.backgroundColor = 'red'
  72. }
  73. else{
  74. rows[index].style.backgroundColor = 'white'
  75. this.clearSelectedRow()
  76. }
  77. },
  78. clearSelectedRow(){
  79. this.selectedRow = {
  80. "Code": "",
  81. "Name": "",
  82. "IDDuration": 0
  83. }
  84. },
  85. changeRequestType(requestType){
  86. this.requestType = requestType
  87. },
  88. modalClick(add, requestType) {
  89. if(add==='yes') {
  90. this.clearSelectedRow();
  91. }
  92. this.changeRequestType(requestType);
  93. }
  94. >>>>>>> master
  95. =======
  96. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12
  97. },
  98. mounted() {
  99. this.getSpecialties()
  100. }
  101. <<<<<<< HEAD
  102. <<<<<<< HEAD
  103. });
  104. =======
  105. });
  106. addSpecialty = (requestType)=>{
  107. let code = document.querySelector('.code').value
  108. let name = document.querySelector('.name').value
  109. let duration = document.querySelectorAll('.duration-radio');
  110. let radioValue
  111. for(let i=0; i<duration.length; i++ ){
  112. if (duration[i].checked) {
  113. radioValue = duration[i].value
  114. }
  115. }
  116. var myHeaders = new Headers();
  117. myHeaders.append("Content-Type", "application/json");
  118. var raw = {"Code":code,"Name":name,"IDDuration":Number(radioValue)};
  119. if (vueApp.requestType=== 'PATCH') {
  120. let ID = document.querySelector('.ID').value
  121. console.log(ID)
  122. raw.ID= Number(ID)
  123. }
  124. requestFunc(url="/specialty/", method=vueApp.requestType, data=raw)
  125. alert("Добавлено")
  126. }
  127. >>>>>>> master
  128. =======
  129. });
  130. >>>>>>> b5fe990a18b258e28401117b0be0a70e1a10db12