informationApplication.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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-autocomplete
  75. v-model="formData.examine_by"
  76. :fetch-suggestions="querySearch"
  77. placeholder="请输入审核人姓名"
  78. style="width: 368px !important"
  79. @select="handleSelect"
  80. >
  81. <template #suffix>
  82. <i class="el-icon-search"></i>
  83. </template>
  84. <template #prepend>
  85. <el-button icon="el-icon-search" @click="openUserSelect"></el-button>
  86. </template>
  87. </el-autocomplete>
  88. </el-form-item>
  89. </div>
  90. </el-form>
  91. <div class="common-dialog-footer">
  92. <!--
  93. <el-button @click="$emit('close')">返回</el-button>
  94. -->
  95. <el-button :loading="buttonLoading" type="primary" @click="submitForm">提交</el-button>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. <ContactSelect
  101. v-model="contactSelectState.show"
  102. :tree-data="treeContactSelectData"
  103. :default-check-data="selectContactSelectData"
  104. @confirm="handleContactSelectData"
  105. />
  106. </template>
  107. <script setup lang="ts">
  108. import { ref, onMounted } from 'vue';
  109. import { ElMessage } from 'element-plus';
  110. import { addInformation, getTemplateList, getUser } from '@/api/informationissue/informationissue';
  111. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  112. const formRef = ref(null);
  113. const buttonLoading = ref(false);
  114. const formData = ref({
  115. title: '',
  116. publish_group: '',
  117. template_type: '0',
  118. template_id: '',
  119. template_url: '',
  120. content: '',
  121. publish_type: '0', // 默认选择立即发布
  122. publish_time: '', // 存储定时发布的时间
  123. response_type: '',
  124. examine_by: '',
  125. attachs: [],
  126. examine_attachs: [],
  127. user_count: 0,
  128. users: [],
  129. publish_channel: '粤政易' // 默认
  130. });
  131. const formatTime = (isoString) => {
  132. const date = new Date(isoString);
  133. const year = date.getFullYear();
  134. const month = String(date.getMonth() + 1).padStart(2, '0');
  135. const day = String(date.getDate()).padStart(2, '0');
  136. const hours = String(date.getHours()).padStart(2, '0');
  137. const minutes = String(date.getMinutes()).padStart(2, '0');
  138. const seconds = String(date.getSeconds()).padStart(2, '0');
  139. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  140. };
  141. const publishNow = () => {
  142. formattedCurrentTime.value = formatTime(new Date().toISOString()); // 设置当前时间为发布时间
  143. };
  144. const formattedCurrentTime = ref(formatTime(new Date().toISOString()));
  145. // 审核人模糊查询
  146. const users = ref([]);
  147. const querySearch = (queryString, cb) => {
  148. const results = queryString ? users.value.filter(this.createFilter(queryString)) : users.value;
  149. // 调用 callback 返回建议列表的数据
  150. cb(results);
  151. };
  152. const handleSelect = (item) => {
  153. formData.value.examine_by = item.username;
  154. };
  155. const rules = {
  156. title: [{ required: true, message: '请填写标题', trigger: 'blur' }],
  157. content: [{ required: true, message: '请填写信息内容', trigger: 'blur' }],
  158. publish_group: [{ required: true, message: '请填写发布单位', trigger: 'blur' }],
  159. publish_time: [{ required: true, message: '请选择发布时间', trigger: 'change' }],
  160. response_type: [{ required: true, message: '请选择消息反馈方式', trigger: 'change' }],
  161. examine_by: [{ required: true, message: '请填写审核人', trigger: 'blur' }],
  162. attachs: [
  163. {
  164. validator: (rule, value, callback) => {
  165. if (value.length == 0) {
  166. return callback(new Error('请上传附件'));
  167. } else {
  168. callback();
  169. }
  170. },
  171. trigger: 'change'
  172. }
  173. ],
  174. examine_attachs: [
  175. {
  176. validator: (rule, value, callback) => {
  177. if (value.length == 0) {
  178. return callback(new Error('请上传审批附件'));
  179. } else {
  180. callback();
  181. }
  182. },
  183. trigger: 'change'
  184. }
  185. ]
  186. };
  187. const feedbackOptions = [
  188. { value: '0', label: '仅需阅读' },
  189. { value: '1', label: '点击确认' },
  190. { value: '2', label: '签字确认' }
  191. ];
  192. const presetTemplates = ref([]);
  193. const submitForm = () => {
  194. formRef.value?.validate(async (valid) => {
  195. if (valid) {
  196. if (formData.value.user_count <= 0) {
  197. proxy?.$modal.msgError('请选择发布名单');
  198. return;
  199. }
  200. formData.value.users = selectContactSelectData.value.map((u) => ({ user_id: u.userId, nick_name: u.label }));
  201. try {
  202. buttonLoading.value = true;
  203. await addInformation(formData.value);
  204. proxy?.$modal.msgSuccess('信息发布申请已提交');
  205. } finally {
  206. buttonLoading.value = false;
  207. }
  208. }
  209. });
  210. };
  211. const showTemplateExample = () => {
  212. ElMessage.info('点击了查看模板样例');
  213. };
  214. const handleTemplateIdChanged = async (value: any) => {
  215. const n = presetTemplates.value.find((i) => i.value === value);
  216. formData.value.content = n.content;
  217. };
  218. // 通讯录(用玉波做的接口改成动态获取)
  219. const treeContactSelectData = reactive([
  220. {
  221. id: 1,
  222. label: '茂南区',
  223. deptType: true,
  224. children: [
  225. {
  226. id: 2,
  227. userId: 1,
  228. label: '李里丽'
  229. },
  230. {
  231. id: 3,
  232. userId: 2,
  233. label: '何里'
  234. },
  235. {
  236. id: 4,
  237. userId: 3,
  238. label: '张力'
  239. }
  240. ]
  241. },
  242. {
  243. id: 5,
  244. label: '电白区',
  245. deptType: true,
  246. children: [
  247. {
  248. id: 6,
  249. userId: 4,
  250. label: '王五'
  251. },
  252. {
  253. id: 7,
  254. userId: 5,
  255. label: '冯可'
  256. },
  257. {
  258. id: 8,
  259. userId: 6,
  260. label: '刘森'
  261. },
  262. {
  263. id: 9,
  264. userId: 3,
  265. label: '张力'
  266. }
  267. ]
  268. }
  269. ]);
  270. let contactSelectState = reactive({
  271. show: false
  272. });
  273. const selectContactSelectData = ref([]);
  274. const handleContactSelectData = (data) => {
  275. selectContactSelectData.value = data;
  276. formData.value.user_count = data.length;
  277. };
  278. const toggleReleaseList = () => {
  279. contactSelectState.show = !contactSelectState.show;
  280. };
  281. onMounted(() => {
  282. formData.value.publish_time = formattedCurrentTime.value;
  283. getTemplateList({}).then((res) => {
  284. res.data.forEach((item, index) => {
  285. presetTemplates.value.push({ value: item.name, label: item.name, content: item.content });
  286. });
  287. getUser({}).then((res) => {
  288. users.value = res.data.map((user) => ({ value: user.username, username: user.username }));
  289. });
  290. });
  291. });
  292. </script>
  293. <style scoped>
  294. .box1 {
  295. border: 1px solid #dcdfe6; /* 浅灰色边框 */
  296. padding: 10px; /* 可选:为了美观,可以添加一些内边距 */
  297. margin-bottom: 10px;
  298. }
  299. .highlight-text {
  300. font-weight: bold; /* 加粗 */
  301. font-size: 1.2em; /* 放大字体大小 */
  302. }
  303. </style>