Module.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <v-form max-width="400px" class="form-module">
  3. <h4>Список новостей</h4>
  4. <v-row class="mt-1 mb-5">
  5. <v-col cols="3" v-for="news in module.news" :key="news.id">
  6. <SectionNews
  7. @update="$emit('update')"
  8. :news="news"
  9. :news_container_id="module.id"
  10. />
  11. </v-col>
  12. </v-row>
  13. <v-text-field v-model="module.name" label="Название модуля"> </v-text-field>
  14. <v-text-field v-model="module.sorting" label="Сортировка модуля"> </v-text-field>
  15. <v-checkbox
  16. max-width="400"
  17. v-model="module.activity"
  18. label="Показывать модуль"
  19. ></v-checkbox>
  20. <v-img
  21. :src="
  22. img.relative_path
  23. ? 'https://api.amic.ru/' + img.relative_path
  24. : module.background_image_for_site
  25. ? 'https://api.amic.ru/uploads/news/images/' +
  26. module.background_image_for_site.file_name
  27. : ''
  28. "
  29. ></v-img>
  30. <v-file-input
  31. @change="handleFile('img', 1200, 800)"
  32. label="Картинка:"
  33. type="file"
  34. accept="image/*"
  35. ref="input"
  36. ></v-file-input>
  37. <v-row>
  38. <v-col>
  39. <h4>Начало активности</h4>
  40. <v-date-picker v-model="date" no-title scrollable>
  41. <v-spacer></v-spacer>
  42. <v-btn text color="primary" @click="menu = false"> Cancel </v-btn>
  43. <v-btn text color="primary" @click="$refs.menu.save(date)">
  44. OK
  45. </v-btn>
  46. </v-date-picker>
  47. <vue-timepicker v-model="time" format="HH:mm:ss"></vue-timepicker>
  48. </v-col>
  49. <v-col>
  50. <h4>Конец активности</h4>
  51. <v-date-picker v-model="endDate" no-title scrollable>
  52. <v-spacer></v-spacer>
  53. <v-btn text color="primary" @click="menu = false"> Cancel </v-btn>
  54. <v-btn text color="primary" @click="$refs.menu.save(date)">
  55. OK
  56. </v-btn>
  57. </v-date-picker>
  58. <vue-timepicker v-model="endTime" format="HH:mm:ss"></vue-timepicker>
  59. </v-col>
  60. </v-row>
  61. <v-btn @click="createModule">Обновить модуль</v-btn>
  62. <v-btn @click="deleteModule">Удалить модуль</v-btn>
  63. </v-form>
  64. </template>
  65. <script>
  66. import VueTimepicker from "vue2-timepicker";
  67. import "vue2-timepicker/dist/VueTimepicker.css";
  68. export default {
  69. layout: "admin",
  70. components: {
  71. VueTimepicker,
  72. },
  73. props: {
  74. module: {
  75. type: Object,
  76. },
  77. },
  78. data() {
  79. return {
  80. img: {},
  81. endTime: "",
  82. endDate: "",
  83. date: "",
  84. time: "",
  85. };
  86. },
  87. mounted() {
  88. this.date = this.module.start_activity.split(" ")[0];
  89. this.time = this.module.start_activity.split(" ")[1];
  90. this.endTime = this.module.end_activity.split(" ")[1];
  91. this.endDate = this.module.end_activity.split(" ")[0];
  92. },
  93. methods: {
  94. handleFile(type, width, height) {
  95. let formData = new FormData();
  96. console.log(this.$refs.input.$refs.input.files[0]);
  97. formData.append("file", this.$refs.input.$refs.input.files[0]);
  98. formData.append("destination_width", width);
  99. formData.append("destination_height", height);
  100. formData.append("title", "example img");
  101. this.$axios
  102. .$post("authorized/admin/files/upload/image/news/raw", formData, {
  103. headers: {
  104. "Content-Type": `multipart/form-data;`,
  105. },
  106. })
  107. .then((res) => {
  108. this.img = res.data;
  109. return res;
  110. })
  111. .catch((err) => console.log(err));
  112. },
  113. createModule() {
  114. this.$axios.post("admin/containers/update", {
  115. type: "module",
  116. id: this.module.id,
  117. name: this.module.name,
  118. start_activity: this.start_activity,
  119. end_activity: this.end_activity,
  120. background_image_id: this.img.image_id,
  121. activity: this.module.activity,
  122. sorting: this.module.sorting
  123. });
  124. },
  125. deleteModule() {
  126. this.$axios.post("admin/containers/remove", {
  127. id: this.module.id,
  128. });
  129. },
  130. },
  131. computed: {
  132. start_activity() {
  133. return this.date + " " + this.time;
  134. },
  135. end_activity() {
  136. return this.endDate + " " + this.endTime;
  137. },
  138. },
  139. };
  140. </script>
  141. <style lang="less">
  142. .form-module {
  143. margin: 0 auto;
  144. max-width: 800px;
  145. width: 100%;
  146. }
  147. </style>