informationApplication.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. <div class="box1">
  10. <h3 class="common-dialog-title" style="font-weight: bold;margin-bottom: 20px;margin-left: 50px">信息内容</h3>
  11. <div style="margin-left: 60px;margin-bottom: 60px">
  12. <el-form-item label="标题:" prop="title">
  13. <el-input v-model="formData.title" placeholder="请输入标题" style="width: 468px !important" />
  14. </el-form-item>
  15. <el-form-item label="信息类型:" prop="info_type">
  16. <el-select v-model="formData.info_type" placeholder="请选择信息类型" style="width: 468px !important">
  17. <el-option v-for="dict in mm_info_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item label="发布单位:" prop="publish_group">
  21. <el-input v-model="formData.publish_group" placeholder="请输入发布单位" style="width: 468px !important" />
  22. </el-form-item>
  23. <el-form-item label="信息模板:" prop="template_type">
  24. <el-radio-group v-model="formData.template_type">
  25. <el-radio value="0">预设模板</el-radio>
  26. <el-radio value="1">自定义模板</el-radio>
  27. </el-radio-group>
  28. </el-form-item>
  29. <el-form-item v-if="formData.template_type === '0'" label="预设模板:" prop="template_type">
  30. <el-select
  31. v-model="formData.template_id"
  32. placeholder="请选择预设模板"
  33. style="width: 468px !important"
  34. @change="handleTemplateIdChanged"
  35. >
  36. <el-option v-for="option in presetTemplates" :key="option.value" :label="option.label" :value="option.value"></el-option>
  37. </el-select>
  38. <el-text class="common-btn-text-primary" @click="showTemplateExample">样例</el-text>
  39. </el-form-item>
  40. <el-form-item v-if="formData.template_type === '1'" prop="template_url">
  41. <el-input v-model="formData.template_url" placeholder="请输入自定义详情页面链接地址" style="width: 468px !important" />
  42. </el-form-item>
  43. <el-form-item label="信息内容:" prop="content">
  44. <el-input v-model="formData.content" :rows="6" type="textarea" placeholder="请输入信息内容" style="width: 468px !important"></el-input>
  45. </el-form-item>
  46. <el-form-item label="上传附件:" prop="attachs">
  47. <file-upload v-model="formData.attachs" :limit="4" :file-type="['pdf', 'doc', 'docx', 'jpg', 'png']" />
  48. </el-form-item>
  49. </div>
  50. </div>
  51. <div class="box1">
  52. <h3 class="common-dialog-title" style="font-weight: bold;margin-bottom: 20px;margin-left: 50px">推送配置</h3>
  53. <div style="margin-left: 60px;margin-bottom: 60px">
  54. <el-form-item label="发布名单:" prop="releaseList" style="width: 468px !important">
  55. <span class="highlight-text" style="margin-right: 20px; margin-left: 20px">已选择{{ formData.user_count }}人</span>
  56. <el-text class="common-btn-text-primary" @click="toggleReleaseList">查看详情</el-text>
  57. </el-form-item>
  58. <el-row :gutter="18">
  59. <el-col :span="14">
  60. <el-form-item label="发布时间:" prop="publish_time">
  61. <el-radio-group v-model="formData.publish_type" style="margin-left: 20px">
  62. <el-radio :value="'0'" @change="publishNow">立即发布</el-radio>
  63. <el-radio :value="'1'">定时发布</el-radio>
  64. </el-radio-group>
  65. <div v-if="formData.publish_type === '0'" style="min-width: 240px; margin-left: 20px">发布时间:{{ formattedCurrentTime }}</div>
  66. <el-date-picker v-else v-model="formData.publish_time" type="datetime" placeholder="选择发布时间" style="width: 250px !important; margin-left: 20px" />
  67. </el-form-item>
  68. </el-col>
  69. </el-row>
  70. <el-form-item label="消息反馈方式:" prop="response_type" style="width: 600px !important">
  71. <el-select v-model="formData.response_type" placeholder="请选择消息反馈方式" style="margin-left: 20px">
  72. <el-option v-for="option in feedbackOptions" :key="option.value" :label="option.label" :value="option.value"></el-option>
  73. </el-select>
  74. </el-form-item>
  75. </div>
  76. </div>
  77. <div class="box1">
  78. <h3 class="common-dialog-title" style="font-weight: bold;margin-bottom: 20px;margin-left: 50px">审核配置</h3>
  79. <div style="margin-left: 60px;margin-bottom: 60px">
  80. <el-form-item label="审核材料:" prop="examine_attachs">
  81. <file-upload v-model="formData.examine_attachs" :limit="4" :file-type="['pdf', 'doc', 'docx', 'jpg', 'png']" style="margin-left: 20px" />
  82. </el-form-item>
  83. <el-form-item label="审核人:" prop="auditor">
  84. <el-autocomplete
  85. v-model="formData.examine_user"
  86. :fetch-suggestions="querySearch"
  87. placeholder="请输入审核人姓名"
  88. style="width: 460px !important; margin-left: 20px"
  89. @select="handleSelect"
  90. >
  91. <template #default="{ item }">
  92. <div class="item_row">
  93. <div class="item_row_user_name">账号:<span v-html="highlightKeyword(item)"></span></div>
  94. <div class="item_row_nick_name">姓名:{{ item.nickName }}</div>
  95. <div class="item_row_dept_name">单位:{{ item.deptName || "(空)" }}</div>
  96. </div>
  97. </template>
  98. <template #suffix>
  99. <i class="el-icon-search"></i>
  100. </template>
  101. </el-autocomplete>
  102. </el-form-item>
  103. </div>
  104. </div>
  105. </el-form>
  106. <div class="common-dialog-footer">
  107. <el-button :loading="buttonLoading" type="primary" @click="submitForm" :disabled="buttonDisabled">提交</el-button>
  108. </div>
  109. </div>
  110. </div>
  111. <ContactSelect
  112. v-model="contactSelectState.show"
  113. :tree-data="treeData"
  114. :default-check-data="selectContactSelectData"
  115. @confirm="handleContactSelectData"
  116. />
  117. </div>
  118. </template>
  119. <script setup lang="ts">
  120. import { ref, onMounted } from 'vue';
  121. import { ElMessage } from 'element-plus';
  122. import { addInformation, getPhoneList, getTemplateList, getUser } from '@/api/informationissue/informationissue';
  123. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  124. import debounce from 'lodash/debounce';
  125. const { mm_info_type, mm_info_template_type } = toRefs<any>(
  126. proxy?.useDict('mm_info_type', 'mm_info_template_type')
  127. );
  128. const formRef = ref(null);
  129. const buttonLoading = ref(false);
  130. const buttonDisabled = ref(false);
  131. const formData = ref({
  132. title: '',
  133. info_type: '',
  134. publish_group: '',
  135. template_type: '0',
  136. template_id: '',
  137. template_url: '',
  138. content: '',
  139. publish_type: '0', // 默认选择立即发布
  140. publish_time: '', // 存储定时发布的时间
  141. response_type: '',
  142. examine_by: '',
  143. examine_user: '', // 显示
  144. attachs: [],
  145. examine_attachs: [],
  146. user_count: 0,
  147. users: [],
  148. publish_channel: '粤政易' // 默认
  149. });
  150. const formatTime = (isoString) => {
  151. const date = new Date(isoString);
  152. const year = date.getFullYear();
  153. const month = String(date.getMonth() + 1).padStart(2, '0');
  154. const day = String(date.getDate()).padStart(2, '0');
  155. const hours = String(date.getHours()).padStart(2, '0');
  156. const minutes = String(date.getMinutes()).padStart(2, '0');
  157. const seconds = String(date.getSeconds()).padStart(2, '0');
  158. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  159. };
  160. const publishNow = () => {
  161. formattedCurrentTime.value = formatTime(new Date().toISOString()); // 设置当前时间为发布时间
  162. };
  163. const formattedCurrentTime = ref(formatTime(new Date().toISOString()));
  164. // 用户数据存储在这里
  165. const users = ref([]);
  166. // 防抖搜索方法
  167. const querySearch = debounce((queryString, cb) => {
  168. if (queryString) {
  169. getUser({ userName: queryString })
  170. .then((res) => {
  171. users.value = res.rows.map((user) => ({ value: user.userName, userName: user.userName, nickName: user.nickName, deptName: user.deptName }));
  172. console.log('users: ', users.value)
  173. cb(users.value);
  174. })
  175. .catch((error) => {
  176. console.error('Error fetching users:', error);
  177. cb([]);
  178. });
  179. } else {
  180. cb([]);
  181. }
  182. }, 3000);
  183. function highlightKeyword(item) {
  184. const keyword = formData.value.examine_user;
  185. if (!keyword) {
  186. return item.userName;
  187. }
  188. const regex = new RegExp(keyword, 'gi');
  189. let val = item.userName.replace(regex, match => `<span class="highlight">${match}</span>`);
  190. return val;
  191. }
  192. const handleSelect = (item) => {
  193. formData.value.examine_by = item.userName;
  194. };
  195. const rules = {
  196. title: [{ required: true, message: '请填写标题', trigger: 'blur' }],
  197. info_type: [{ required: true, message: '请选择信息类型', trigger: 'change' }],
  198. content: [{ required: true, message: '请填写信息内容', trigger: 'blur' }],
  199. publish_group: [{ required: true, message: '请填写发布单位', trigger: 'blur' }],
  200. publish_time: [{ required: true, message: '请选择发布时间', trigger: 'change' }],
  201. response_type: [{ required: true, message: '请选择消息反馈方式', trigger: 'change' }],
  202. examine_by: [{ required: true, message: '请填写审核人', trigger: 'blur' }],
  203. attachs: [
  204. {
  205. validator: (rule, value, callback) => {
  206. if (value.length == 0) {
  207. return callback(new Error('请上传附件'));
  208. } else {
  209. callback();
  210. }
  211. },
  212. trigger: 'change'
  213. }
  214. ],
  215. examine_attachs: [
  216. {
  217. validator: (rule, value, callback) => {
  218. if (value.length == 0) {
  219. return callback(new Error('请上传审批附件'));
  220. } else {
  221. callback();
  222. }
  223. },
  224. trigger: 'change'
  225. }
  226. ]
  227. };
  228. const feedbackOptions = [
  229. { value: '0', label: '仅需阅读' },
  230. { value: '1', label: '点击确认' },
  231. { value: '2', label: '签字确认' }
  232. ];
  233. const presetTemplates = ref([]);
  234. const submitForm = () => {
  235. formRef.value?.validate(async (valid) => {
  236. if (valid) {
  237. if (formData.value.user_count <= 0) {
  238. proxy?.$modal.msgError('请选择发布名单');
  239. return;
  240. }
  241. formData.value.users = selectContactSelectData.value.map((u) => ({ user_id: u.id, nick_name: u.label }));
  242. try {
  243. buttonLoading.value = true;
  244. await addInformation(formData.value);
  245. buttonDisabled.value = true;
  246. proxy?.$modal.msgSuccess('信息发布申请已提交');
  247. } finally {
  248. buttonLoading.value = false;
  249. }
  250. }
  251. });
  252. };
  253. const showTemplateExample = () => {
  254. ElMessage.info('点击了查看模板样例');
  255. };
  256. const handleTemplateIdChanged = async (value: any) => {
  257. const n = presetTemplates.value.find((i) => i.value === value);
  258. formData.value.content = n.content;
  259. };
  260. let treeData = ref([]);
  261. let contactSelectState = reactive({
  262. show: false
  263. });
  264. const selectContactSelectData = ref([]);
  265. const handleContactSelectData = (data) => {
  266. console.log('handleContactSelectData:', data);
  267. selectContactSelectData.value = data;
  268. formData.value.user_count = data.length;
  269. };
  270. const toggleReleaseList = () => {
  271. contactSelectState.show = !contactSelectState.show;
  272. };
  273. const fetchTreeData = async () => {
  274. try {
  275. const response = await getPhoneList({});
  276. if (response && response.data) {
  277. treeData.value = response.data;
  278. }
  279. } catch (error) {
  280. console.error('Failed to fetch information:', error);
  281. }
  282. };
  283. const openUserSelect = async() => {
  284. };
  285. onMounted(() => {
  286. fetchTreeData();
  287. formData.value.publish_time = formattedCurrentTime.value;
  288. getTemplateList({}).then((res) => {
  289. res.data.forEach((item, index) => {
  290. presetTemplates.value.push({ value: item.id, label: item.name, content: item.content });
  291. });
  292. getUser({}).then((res) => {
  293. // console.log('getUser res:', res);
  294. users.value = res.rows.map((user) => ({ value: user.userName, userName: user.userName, nickName: user.nickName, deptName: user.deptName }));
  295. console.log('users.value:', users.value);
  296. });
  297. });
  298. });
  299. </script>
  300. <style scoped>
  301. .box1 {
  302. border: 1px solid #dcdfe6; /* 浅灰色边框 */
  303. padding: 10px; /* 可选:为了美观,可以添加一些内边距 */
  304. margin-bottom: 10px;
  305. width: 800px;
  306. background-color: white;
  307. border-radius: 5px;
  308. box-shadow: 0px 0px 4px rgba(0, 0, 0, .06);
  309. }
  310. .highlight-text {
  311. font-weight: bold; /* 加粗 */
  312. font-size: 1.2em; /* 放大字体大小 */
  313. }
  314. .el-icon-search {
  315. height:20px;
  316. width:20px;
  317. background: url("@/assets/images/search.png") no-repeat;
  318. background-size:20px;
  319. }
  320. :deep(.highlight) {
  321. color: #fd0f0f;
  322. }
  323. .item_row {
  324. display: flex;
  325. justify-content: space-between;
  326. align-items: center;
  327. .item_row_user_name {
  328. margin-left:0px;
  329. }
  330. .item_row_nick_name {
  331. margin-left:10px;
  332. }
  333. .item_row_dept_name {
  334. margin-left:10px;
  335. }
  336. }
  337. </style>