detail.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_back="true" @toBack="toBack"></cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cForm :span="24" :fields="formFields" :form="form" :rules="rules" @save="onSubmit" @dataChange="dataChange">
  10. <template #column_id>
  11. <el-option v-for="(i, index) in columnList" :key="index" :label="i.title" :value="i._id"></el-option>
  12. </template>
  13. <template #is_use>
  14. <el-option v-for="(i, index) in is_useList" :key="index" :label="i.label" :value="i.value"></el-option>
  15. </template>
  16. <template #is_money>
  17. <el-option v-for="(i, index) in moneyList" :key="index" :label="i.label" :value="i.value"></el-option>
  18. </template>
  19. <template #type>
  20. <el-option v-for="(i, index) in typeList" :key="index" :label="i.label" :value="i.value"></el-option>
  21. </template>
  22. <template #expo_id>
  23. <el-option v-for="(i, index) in dockList" :key="index" :label="i.title" :value="i._id"></el-option>
  24. </template>
  25. <template #image_file="{ item }">
  26. <cUpload
  27. :model="item.model"
  28. :limit="6"
  29. url="/files/zkzx/news/upload"
  30. :list="form[item.model]"
  31. listType="picture-card"
  32. @change="onUpload"
  33. ></cUpload>
  34. </template>
  35. <template #video_file="{ item }">
  36. <cUpload :model="item.model" :limit="1" url="/files/zkzx/news/upload" :list="form[item.model]" listType="text" @change="onUpload"></cUpload>
  37. </template>
  38. <template #annex_file="{ item }">
  39. <cUpload :model="item.model" :limit="1" url="/files/zkzx/news/upload" :list="form[item.model]" listType="text" @change="onUpload"></cUpload>
  40. </template>
  41. <template #money_file="{ item }">
  42. <cUpload :model="item.model" :limit="6" url="/files/news/upload" :list="form[item.model]" listType="picture-card" @change="onUpload"></cUpload>
  43. </template>
  44. </cForm>
  45. </el-col>
  46. </el-col>
  47. </el-row>
  48. </div>
  49. </template>
  50. <script setup lang="ts">
  51. import type { Ref } from 'vue';
  52. import { ref, reactive, onMounted } from 'vue';
  53. import { useRoute } from 'vue-router';
  54. import { ElMessage } from 'element-plus';
  55. import type { FormRules } from 'element-plus';
  56. import store from '@/stores/counter';
  57. // 接口
  58. import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
  59. import { NewsMessStore } from '@common/src/stores/allAdmin/newsMess';
  60. import { NewsColumnStore } from '@common/src/stores/allAdmin/newsColumn';
  61. import { DockStore } from '@common/src/stores/allAdmin/dock';
  62. import type { IQueryResult } from '@/util/types.util';
  63. const newsMess = NewsMessStore();
  64. const dictData = DictDataStore();
  65. const newsColumn = NewsColumnStore();
  66. const dock = DockStore();
  67. // 路由
  68. const route = useRoute();
  69. // 加载中
  70. const loading = ref(false);
  71. let user: Ref<any> = ref({});
  72. // 表单
  73. let form: Ref<any> = ref({});
  74. let formFields: Ref<any[]> = ref([
  75. { label: '所属栏目', model: 'column_id', type: 'select' },
  76. { label: '标题', model: 'title' },
  77. { label: '信息类型', model: 'type', type: 'select' },
  78. { label: '发布时间', model: 'create_date', type: 'date' },
  79. { label: '信息来源', model: 'origin' },
  80. { label: '信息简介', model: 'brief', type: 'textarea' },
  81. { label: '图片文件', model: 'image_file', custom: true },
  82. { label: '视频文件', model: 'video_file', custom: true },
  83. { label: '附件文件', model: 'annex_file', custom: true },
  84. { label: '是否收费', model: 'is_money', type: 'select' },
  85. { label: '收费图片', model: 'money_file', custom: true },
  86. { label: '关联展会', model: 'expo_id', type: 'select' },
  87. { label: '信息内容', model: 'content', type: 'textarea' },
  88. { label: '是否启用', model: 'is_use', type: 'select' }
  89. ]);
  90. const rules = reactive<FormRules>({});
  91. // 字典表
  92. let typeList: Ref<any> = ref([]);
  93. let moneyList: Ref<any> = ref([]);
  94. let is_useList: Ref<any> = ref([]);
  95. let columnList: Ref<any> = ref([]);
  96. let dockList: Ref<any> = ref([]);
  97. onMounted(async () => {
  98. loading.value = true;
  99. user.value = store.state.user;
  100. await searchOther();
  101. await search();
  102. loading.value = false;
  103. });
  104. const search = async () => {
  105. if (route.query.id) {
  106. let res: IQueryResult = await newsMess.fetch(route.query.id);
  107. if (res.errcode == 0) form.value = res.data as {};
  108. } else form.value = { is_use: '0' };
  109. };
  110. const dataChange = (e: { model: string; value: any }) => {
  111. const { model, value } = e;
  112. if (model == 'is_money') {
  113. if (value == '1') formFields.value = formFields.value.filter((i) => i.model != 'money_file');
  114. else formFields.value.splice(10, 0, { label: '收费图片', model: 'money_file', custom: true });
  115. }
  116. };
  117. const onUpload = (e: { model: string; value: Array<[]> }) => {
  118. const { model, value } = e;
  119. form.value[model] = value;
  120. };
  121. // 提交
  122. const onSubmit = async (data) => {
  123. let res: IQueryResult;
  124. if (data._id) res = await newsMess.update(data);
  125. else res = await newsMess.create(data);
  126. if (res.errcode == 0) {
  127. ElMessage({ type: `success`, message: `维护信息成功` });
  128. toBack();
  129. }
  130. };
  131. // 返回上一页
  132. const toBack = () => {
  133. window.history.go(-1);
  134. };
  135. const searchOther = async () => {
  136. let res: IQueryResult;
  137. // 信息类型
  138. res = await dictData.query({ type: 'news_type' });
  139. if (res.errcode == 0) typeList.value = res.data;
  140. // 是否收费
  141. res = await dictData.query({ type: 'common_isno' });
  142. if (res.errcode == 0) moneyList.value = res.data;
  143. // 是否使用
  144. res = await dictData.query({ type: 'common_use' });
  145. if (res.errcode == 0) is_useList.value = res.data;
  146. res = await newsColumn.query({ is_use: '0' });
  147. if (res.errcode == 0) columnList.value = res.data;
  148. res = await dock.query({ status: '1' });
  149. if (res.errcode == 0) dockList.value = res.data;
  150. };
  151. </script>
  152. <style scoped lang="scss"></style>