informationApplication.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="common-dialog">
  3. <div class="common-dialog-content">
  4. <div class="common-dialog-title-box">
  5. <h3 class="common-dialog-title">信息发布申请</h3>
  6. </div>
  7. <div class="common-dialog-box">
  8. <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
  9. <h4 class="common-dialog-title">信息内容</h4>
  10. <div class="box1">
  11. <el-form-item label="标题:" prop="title">
  12. <el-input v-model="formData.title" placeholder="请输入标题" style="width: 468px !important" />
  13. </el-form-item>
  14. <el-form-item label="发布单位:" prop="publish_group">
  15. <el-input v-model="formData.publish_group" placeholder="请输入发布单位" style="width: 468px !important" />
  16. </el-form-item>
  17. <el-form-item label="信息模板:" prop="templateType">
  18. <el-radio-group v-model="formData.template_type">
  19. <el-radio value="0">预设模板</el-radio>
  20. <el-radio value="1">自定义模板</el-radio>
  21. </el-radio-group>
  22. </el-form-item>
  23. <el-form-item v-if="formData.template_type === '0'" label="预设模板:" prop="template_type">
  24. <el-select
  25. v-model="formData.template_id"
  26. placeholder="请选择预设模板"
  27. style="width: 300px !important"
  28. @change="handleTemplateIdChanged"
  29. >
  30. <el-option v-for="option in presetTemplates" :key="option.value" :label="option.label" :value="option.value"></el-option>
  31. </el-select>
  32. <el-text class="common-btn-text-primary" @click="showTemplateExample">样例</el-text>
  33. </el-form-item>
  34. <el-form-item v-if="formData.template_type === '1'" prop="template_url">
  35. <el-input v-model="formData.template_url" placeholder="请输入自定义详情页面链接地址" style="width: 468px !important" />
  36. </el-form-item>
  37. <el-form-item label="信息内容:" prop="content">
  38. <el-input v-model="formData.content" :rows="4" type="textarea" placeholder="请输入信息内容" style="width: 468px !important"></el-input>
  39. </el-form-item>
  40. <el-form-item label="上传附件:" prop="attachs">
  41. <file-upload v-model="formData.attachs" :limit="4" :file-type="['pdf', 'doc', 'docx', 'jpg', 'png']" />
  42. </el-form-item>
  43. </div>
  44. <h4 class="common-dialog-title">推送配置</h4>
  45. <div class="box1">
  46. <el-form-item label="发布名单:" prop="releaseList" style="width: 468px !important"
  47. ><span class="highlight-text">已选择{{ formData.user_count }}人</span>
  48. <el-text class="common-btn-text-primary" @click="toggleReleaseList">查看详情</el-text>
  49. </el-form-item>
  50. <el-row :gutter="18">
  51. <el-col :span="14">
  52. <el-form-item label="发布时间:" prop="publish_time">
  53. <el-radio-group v-model="formData.publish_type">
  54. <el-radio :value="'0'" @change="publishNow">立即发布</el-radio>
  55. <el-radio :value="'1'">定时发布</el-radio>
  56. </el-radio-group>
  57. <div v-if="formData.publish_type === '0'" style="min-width: 240px">发布时间:{{ formattedCurrentTime }}</div>
  58. <el-date-picker v-else v-model="formData.publish_time" type="datetime" placeholder="选择发布时间" style="width: 250px !important" />
  59. </el-form-item>
  60. </el-col>
  61. </el-row>
  62. <el-form-item label="消息反馈方式:" prop="response_type" style="width: 300px !important">
  63. <el-select v-model="formData.response_type" placeholder="请选择消息反馈方式">
  64. <el-option v-for="option in feedbackOptions" :key="option.value" :label="option.label" :value="option.value"></el-option>
  65. </el-select>
  66. </el-form-item>
  67. </div>
  68. <h4 class="common-dialog-title">审核配置</h4>
  69. <div class="box1">
  70. <el-form-item label="审核材料:" prop="examine_attachs">
  71. <file-upload v-model="formData.examine_attachs" :limit="4" :file-type="['pdf', 'doc', 'docx', 'jpg', 'png']" />
  72. </el-form-item>
  73. <el-form-item label="审核人:" prop="auditor">
  74. <el-input v-model="formData.examine_by" placeholder="请输入审核人姓名" style="width: 368px !important" />
  75. </el-form-item>
  76. </div>
  77. </el-form>
  78. <div class="common-dialog-footer">
  79. <!--
  80. <el-button @click="$emit('close')">返回</el-button>
  81. -->
  82. <el-button :loading="buttonLoading" type="primary" @click="submitForm">提交</el-button>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. <ContactSelect
  88. v-model="contactSelectState.show"
  89. :tree-data="treeData"
  90. :default-check-data="selectContactSelectData"
  91. @confirm="handleContactSelectData"
  92. />
  93. </template>
  94. <script setup lang="ts">
  95. import { ref, onMounted } from 'vue';
  96. import { ElMessage } from 'element-plus';
  97. import {addInformation, getPhoneList, getTemplateList} from '@/api/informationissue/informationissue';
  98. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  99. const formRef = ref(null);
  100. const buttonLoading = ref(false);
  101. const formData = ref({
  102. title: '',
  103. publish_group: '',
  104. template_type: '0',
  105. template_id: '',
  106. template_url: '',
  107. content: '',
  108. publish_type: '0', // 默认选择立即发布
  109. publish_time: '', // 存储定时发布的时间
  110. response_type: '',
  111. examine_by: '',
  112. attachs: [],
  113. examine_attachs: [],
  114. user_count: 0,
  115. users: [],
  116. publish_channel: '粤政易' // 默认
  117. });
  118. const formatTime = (isoString) => {
  119. const date = new Date(isoString);
  120. const year = date.getFullYear();
  121. const month = String(date.getMonth() + 1).padStart(2, '0');
  122. const day = String(date.getDate()).padStart(2, '0');
  123. const hours = String(date.getHours()).padStart(2, '0');
  124. const minutes = String(date.getMinutes()).padStart(2, '0');
  125. const seconds = String(date.getSeconds()).padStart(2, '0');
  126. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  127. };
  128. const publishNow = () => {
  129. formattedCurrentTime.value = formatTime(new Date().toISOString()); // 设置当前时间为发布时间
  130. };
  131. const formattedCurrentTime = ref(formatTime(new Date().toISOString()));
  132. const rules = {
  133. title: [{ required: true, message: '请填写标题', trigger: 'blur' }],
  134. content: [{ required: true, message: '请填写信息内容', trigger: 'blur' }],
  135. publish_group: [{ required: true, message: '请填写发布单位', trigger: 'blur' }],
  136. publish_time: [{ required: true, message: '请选择发布时间', trigger: 'change' }],
  137. response_type: [{ required: true, message: '请选择消息反馈方式', trigger: 'change' }],
  138. examine_by: [{ required: true, message: '请填写审核人', trigger: 'blur' }],
  139. attachs: [
  140. {
  141. validator: (rule, value, callback) => {
  142. if (value.length == 0) {
  143. return callback(new Error('请上传附件'));
  144. } else {
  145. callback();
  146. }
  147. },
  148. trigger: 'change'
  149. }
  150. ],
  151. examine_attachs: [
  152. {
  153. validator: (rule, value, callback) => {
  154. if (value.length == 0) {
  155. return callback(new Error('请上传审批附件'));
  156. } else {
  157. callback();
  158. }
  159. },
  160. trigger: 'change'
  161. }
  162. ]
  163. };
  164. const feedbackOptions = [
  165. { value: '0', label: '仅需阅读' },
  166. { value: '1', label: '点击确认' },
  167. { value: '2', label: '签字确认' }
  168. ];
  169. const presetTemplates = ref([]);
  170. const submitForm = () => {
  171. formRef.value?.validate(async (valid) => {
  172. if (valid) {
  173. if (formData.value.user_count <= 0) {
  174. proxy?.$modal.msgError('请选择发布名单');
  175. return;
  176. }
  177. formData.value.users = selectContactSelectData.value.map((u) => ({ user_id: u.userId, nick_name: u.label }));
  178. try {
  179. buttonLoading.value = true;
  180. await addInformation(formData.value);
  181. proxy?.$modal.msgSuccess('信息发布申请已提交');
  182. } finally {
  183. buttonLoading.value = false;
  184. }
  185. }
  186. });
  187. };
  188. const showTemplateExample = () => {
  189. ElMessage.info('点击了查看模板样例');
  190. };
  191. const handleTemplateIdChanged = async (value: any) => {
  192. const n = presetTemplates.value.find((i) => i.value === value);
  193. formData.value.content = n.content;
  194. };
  195. let treeData = ref([]);
  196. let contactSelectState = reactive({
  197. show: false
  198. });
  199. const selectContactSelectData = ref([]);
  200. const handleContactSelectData = (data) => {
  201. selectContactSelectData.value = data;
  202. formData.value.user_count = data.length;
  203. };
  204. const toggleReleaseList = () => {
  205. contactSelectState.show = !contactSelectState.show;
  206. };
  207. const fetchTreeData = async () => {
  208. try {
  209. const response = await getPhoneList();
  210. if (response && response.data) {
  211. treeData.value = response.data;
  212. }
  213. } catch (error) {
  214. console.error('Failed to fetch information:', error);
  215. }
  216. };
  217. onMounted(() => {
  218. fetchTreeData();
  219. formData.value.publish_time = formattedCurrentTime.value;
  220. getTemplateList({}).then((res) => {
  221. res.data.forEach((item, index) => {
  222. presetTemplates.value.push({ value: item.name, label: item.name, content: item.content });
  223. });
  224. });
  225. });
  226. </script>
  227. <style scoped>
  228. .box1 {
  229. border: 1px solid #dcdfe6; /* 浅灰色边框 */
  230. padding: 10px; /* 可选:为了美观,可以添加一些内边距 */
  231. margin-bottom: 10px;
  232. }
  233. .highlight-text {
  234. font-weight: bold; /* 加粗 */
  235. font-size: 1.2em; /* 放大字体大小 */
  236. }
  237. </style>