detail.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div id="detail">
  3. <van-row>
  4. <van-col span="24" class="main animate__animated animate__backInRight">
  5. <van-col span="24" class="one">
  6. <van-form @submit="toSave" label-width="auto">
  7. <van-cell-group>
  8. <van-field
  9. v-model="form.name"
  10. name="name"
  11. type="textarea"
  12. rows="1"
  13. autosize
  14. label="标题"
  15. placeholder="请输入标题"
  16. :rules="[{ required: true, message: '请输入标题' }]"
  17. />
  18. <van-field v-model="form.year" is-link readonly name="year" label="年份" placeholder="点击选择年份" @click="toPopup({ type: 'year' })" />
  19. <van-field
  20. v-model="form.start_time"
  21. is-link
  22. readonly
  23. name="start_time"
  24. label="开始时间"
  25. placeholder="点击选择年份"
  26. @click="toPopup({ type: 'start_time' })"
  27. />
  28. <van-field
  29. v-model="form.end_time"
  30. is-link
  31. readonly
  32. name="end_time"
  33. label="结束时间"
  34. placeholder="点击选择时间"
  35. @click="toPopup({ type: 'end_time' })"
  36. />
  37. <van-field
  38. v-model="form.type"
  39. is-link
  40. readonly
  41. name="type"
  42. label="开放的实验室类型"
  43. placeholder="点击选择类型"
  44. @click="toPopup({ type: 'type' })"
  45. />
  46. <van-field v-model="form.is_use" is-link readonly name="is_use" label="是否启用" placeholder="点击选择" @click="toPopup({ type: 'is_use' })" />
  47. </van-cell-group>
  48. <div class="btn">
  49. <van-button type="primary" size="small" native-type="submit"> 提交保存 </van-button>
  50. </div>
  51. </van-form>
  52. </van-col>
  53. </van-col>
  54. </van-row>
  55. <van-popup v-model:show="popup.show" position="bottom">
  56. <template v-if="popup.type == 'year'">
  57. <van-date-picker :columns-type="['year']" @confirm="popChange" @cancel="toCancel" />
  58. </template>
  59. <template v-else-if="popup.type == 'start_time'">
  60. <van-date-picker :columns-type="['year', 'month', 'day']" @confirm="popChange" @cancel="toCancel" />
  61. </template>
  62. <template v-else-if="popup.type == 'end_time'">
  63. <van-date-picker :columns-type="['year', 'month', 'day']" @confirm="popChange" @cancel="toCancel" />
  64. </template>
  65. <template v-else-if="popup.type == 'type'">
  66. <van-picker :columns="typeList" :columns-field-names="{ text: 'dict_label', value: 'dict_value' }" @confirm="popChange" @cancel="toCancel" />
  67. </template>
  68. <template v-else-if="popup.type == 'is_use'">
  69. <van-picker :columns="showList" :columns-field-names="{ text: 'dict_label', value: 'dict_value' }" @confirm="popChange" @cancel="toCancel" />
  70. </template>
  71. </van-popup>
  72. </div>
  73. </template>
  74. <script setup lang="ts">
  75. // 基础
  76. import type { Ref } from 'vue';
  77. import { onMounted, ref } from 'vue';
  78. import { useRoute } from 'vue-router';
  79. import { showToast } from 'vant';
  80. // 接口
  81. import { ActivitysStore } from '@common/src/stores/basic/activitys';
  82. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  83. import type { IQueryResult } from '@/util/types.util';
  84. const actAxios = ActivitysStore();
  85. const dictAxios = DictDataStore();
  86. // 路由
  87. const route = useRoute();
  88. const id: Ref<any> = ref('');
  89. // 表单
  90. const form: Ref<any> = ref({ file: [], files: [] });
  91. // 弹框
  92. const popup: Ref<any> = ref({ show: false, type: '' });
  93. // 日期
  94. const minDate: Ref<any> = ref(new Date(2020, 1, 1));
  95. const maxDate: Ref<any> = ref(new Date(2030, 1, 1));
  96. // 字典表
  97. const showList: Ref<any> = ref([]);
  98. const typeList: Ref<any> = ref([]);
  99. // 请求
  100. onMounted(async () => {
  101. id.value = route.query.id;
  102. await searchOther();
  103. await search();
  104. });
  105. const search = async () => {
  106. if (id.value) {
  107. let res: IQueryResult = await actAxios.fetch(id.value);
  108. if (res.errcode == '0') {
  109. form.value = res.data;
  110. }
  111. }
  112. };
  113. // 选择
  114. const toPopup = (e) => {
  115. popup.value = { show: true, type: e.type };
  116. };
  117. const popChange = (e) => {
  118. let value = e.selectedValues;
  119. if (popup.value.type == 'year') {
  120. form.value.year = value[0];
  121. } else if (popup.value.type == 'start_time') {
  122. form.value.start_time = value.join('-');
  123. } else if (popup.value.type == 'end_time') {
  124. form.value.end_time = value.join('-');
  125. } else if (popup.value.type == 'type') {
  126. form.value.type = value[0];
  127. } else if (popup.value.type == 'is_use') {
  128. form.value.is_use = value[0];
  129. }
  130. toCancel();
  131. };
  132. // 关闭
  133. const toCancel = () => {
  134. popup.value = { show: false };
  135. };
  136. // 保存
  137. const toSave = async (e) => {
  138. let res: IQueryResult;
  139. if (id.value) res = await actAxios.update({ ...e, _id: id.value });
  140. else res = await actAxios.create(e);
  141. if (res.errcode == '0') {
  142. showToast({ message: '信息删除成功', type: 'success', duration: 500 });
  143. toBack();
  144. } else {
  145. showToast({ message: `${res.errmsg}`, type: 'fail', duration: 500 });
  146. }
  147. };
  148. // 查询其他信息
  149. const searchOther = async () => {
  150. let res: IQueryResult;
  151. // 是否启用
  152. res = await dictAxios.query({ dict_type: 'act_time_type' });
  153. if (res.errcode == '0') {
  154. showList.value = res.data;
  155. }
  156. // 类型
  157. res = await dictAxios.query({ dict_type: 'act_label_type' });
  158. if (res.errcode == '0') {
  159. typeList.value = res.data;
  160. }
  161. };
  162. // 返回;
  163. const toBack = () => {
  164. window.history.go(-1);
  165. };
  166. </script>
  167. <style scoped lang="scss">
  168. .main {
  169. .one {
  170. .btn {
  171. text-align: center;
  172. margin: 10px 0;
  173. }
  174. }
  175. }
  176. </style>