ReportOperation.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div class="page">
  3. <div class="top">
  4. <div class="topLeft" @click="clickBack">
  5. <img src="./img/rollback.png" style="margin-right: 8px" /><span>返回</span>
  6. </div>
  7. <div class="topRight">
  8. <span v-if="pageType === 1">新建报表配置</span>
  9. <span v-if="pageType === 2">查看报表配置</span>
  10. <span v-if="pageType === 3">编辑报表配置</span>
  11. </div>
  12. </div>
  13. <div class="content">
  14. <div class="left">
  15. <el-form
  16. ref="ruleFormRef"
  17. style="max-width: 1000px;"
  18. :model="form"
  19. :rules="rules"
  20. label-width="auto"
  21. class="demo-ruleForm"
  22. :size="formSize"
  23. :label-position="labelPosition"
  24. >
  25. <el-form-item
  26. v-if="form.type === 3"
  27. label="指定人员:"
  28. required
  29. prop="designatedUserList.value"
  30. style="width: 660px;"
  31. :rules="{ required: true, message: '请选择推送人员', trigger: ['change'] }"
  32. >
  33. <el-col :span="18">
  34. <DesignatedUserList :form="form" :disableType="disableType" />
  35. </el-col>
  36. </el-form-item>
  37. <el-form-item label="报表周期:" prop="statisticType" required>
  38. <el-radio-group
  39. v-model="form.statisticType"
  40. :disabled="disableType.statisticTypeDisable"
  41. >
  42. <el-tooltip :visible="weekVisible" placement="top">
  43. <template #content>
  44. <span>每次推送上个自然周数据</span><br /><div style="text-align: center;">(每周一至周日)</div>
  45. </template>
  46. <el-radio
  47. :value="1"
  48. @mouseenter="weekVisible = true"
  49. @mouseleave="weekVisible = false"
  50. >周报</el-radio
  51. >
  52. </el-tooltip>
  53. <el-tooltip :visible="monthVisible" placement="top">
  54. <template #content>
  55. <span>每次推送上个自然月数据</span><br /><div style="text-align: center;">(每月第一天至最后一天)</div>
  56. </template>
  57. <el-radio
  58. :value="2"
  59. @mouseenter="monthVisible = true"
  60. @mouseleave="monthVisible = false"
  61. >月报</el-radio
  62. >
  63. </el-tooltip>
  64. <el-tooltip :visible="seasonVisible" placement="top">
  65. <template #content>
  66. <span>每次将推送上个自然季度数据</span>
  67. </template>
  68. <el-radio
  69. :value="3"
  70. @mouseenter="seasonVisible = true"
  71. @mouseleave="seasonVisible = false"
  72. >季报</el-radio
  73. >
  74. </el-tooltip>
  75. <el-tooltip :visible="yearVisible" placement="top">
  76. <template #content>
  77. <span>每次推送上一整年的数据</span>
  78. </template>
  79. <el-radio
  80. :value="4"
  81. @mouseenter="yearVisible = true"
  82. @mouseleave="yearVisible = false"
  83. >年报</el-radio
  84. >
  85. </el-tooltip>
  86. <el-tooltip :visible="customVisible" placement="top">
  87. <template #content>
  88. <span>根据个人需求按开始和结束日期进行统计</span>
  89. </template>
  90. <el-radio
  91. el-radio
  92. :value="5"
  93. @mouseenter="customVisible = true"
  94. @mouseleave="customVisible = false"
  95. >自定义</el-radio
  96. >
  97. </el-tooltip>
  98. </el-radio-group>
  99. </el-form-item>
  100. <div v-if="form.statisticType === 1">
  101. <WeekReport :form="form" :disableType="disableType"></WeekReport>
  102. </div>
  103. <div v-if="form.statisticType === 2">
  104. <MonthReport :form="form" :disableType="disableType"></MonthReport>
  105. </div>
  106. <div v-if="form.statisticType === 4">
  107. <YearReport :form="form" :disableType="disableType"></YearReport>
  108. </div>
  109. <div v-if="form.statisticType === 5" class="custom-report">
  110. <CustomReport
  111. ref="CustomReportComponent"
  112. :form="form"
  113. :disableType="disableType"
  114. :ruleFormRef="ruleFormRef"
  115. ></CustomReport>
  116. </div>
  117. <el-form-item label="推送渠道:" prop="pushChannel" required>
  118. <el-checkbox-group v-model="form.pushChannel" :disabled="disableType.contentDisable">
  119. <el-col :span="2">
  120. <el-checkbox :value="1" name="channel"> 蓝信推送 </el-checkbox>
  121. </el-col>
  122. <el-col :span="2">
  123. <el-checkbox :value="2" name="channel"> 平台推送 </el-checkbox>
  124. </el-col>
  125. </el-checkbox-group>
  126. </el-form-item>
  127. <el-form-item label="操作人:" style="margin-left: 10px;">
  128. <el-input style="width: 425px; margin-left: -10px ;" disabled :placeholder="operater" />
  129. </el-form-item>
  130. </el-form>
  131. <div class="two-btns">
  132. <el-button @click="clickBack">取消</el-button>
  133. <el-button
  134. type="primary"
  135. @click="submitForm(ruleFormRef)"
  136. :disabled="disableType.contentDisable"
  137. >
  138. 确定
  139. </el-button>
  140. </div>
  141. </div>
  142. <div class="right">
  143. <TemplateExample :form="form" :disableType="disableType"></TemplateExample>
  144. </div>
  145. </div>
  146. </div>
  147. </template>
  148. <script lang="ts" setup>
  149. import { reactive, ref, watch, onBeforeMount } from 'vue';
  150. import type { FormInstance } from 'element-plus';
  151. import TemplateExample from './TemplateExample.vue';
  152. import WeekReport from './WeekReport.vue';
  153. import MonthReport from './MonthReport.vue';
  154. import YearReport from './YearReport.vue';
  155. import CustomReport from './CustomReport.vue';
  156. import { reportMessage, toReportMessage, reportMessageToFinal } from './class.ts';
  157. import { addMassage, searchMassage, editMassage } from '@/api/sendMessage/sendMessage';
  158. import { ElMessage } from 'element-plus';
  159. import { storeToRefs } from 'pinia';
  160. import { useUserStore } from '@/store/modules/user';
  161. import { useFormList } from './store/useFormList';
  162. import { useRoute, useRouter } from 'vue-router';
  163. import DesignatedUserList from '@/views/message/designatedUserSelectTree.vue';
  164. import type { FormProps } from 'element-plus';
  165. const labelPosition = ref<FormProps['labelPosition']>('left');
  166. const useUser = useUserStore();
  167. const FormList = useFormList();
  168. const { info } = storeToRefs(useUser);
  169. const { type } = storeToRefs(FormList);
  170. let operater = info.value.nickname;
  171. const weekVisible = ref(false); // 控制Tooltip显示
  172. const monthVisible = ref(false); // 控制Tooltip显示
  173. const seasonVisible = ref(false); // 控制Tooltip显示
  174. const yearVisible = ref(false); // 控制Tooltip显示
  175. const customVisible = ref(false); // 控制Tooltip显示
  176. let disableType = ref({ statisticTypeDisable: false, contentDisable: false }); // 控制是否可编辑
  177. const formSize = ref('default'); // 校验表单
  178. const ruleFormRef = ref();
  179. // let pageType = 3 // 功能类型:1是新增,2是查询,3是编辑
  180. // let reportType = 1 // 报表类型:1是违规报警,2是平台访问,3是指定人员访问
  181. const route = useRoute();
  182. const router = useRouter();
  183. const pageType = ref<number>(route.query.operationType ? Number(route.query.operationType) : 0);
  184. const reportType = ref<number>(route.query.type ? Number(route.query.type) : 0);
  185. const statisticType = ref<number>(
  186. route.query.statisticType ? Number(route.query.statisticType) : 0,
  187. );
  188. let queryType = { type: reportType.value, statisticType: statisticType.value };
  189. const form = reactive<reportMessage>({
  190. configIdList: null,
  191. type: 0,
  192. statisticType: 0,
  193. monthAndDayList: ['1', '1'],
  194. dayOfWeek: 1,
  195. monthList: [''],
  196. dayOfMonthList: ['1'],
  197. pushTimeList: ['09:00:00'],
  198. pushChannel: [],
  199. userGroupList: [],
  200. designatedUserList: [],
  201. recipientType: undefined,
  202. customPushConfigList: [],
  203. customUserList: [],
  204. });
  205. form.customUserList.value = []; // 防止进入页面开始就显示校验错误
  206. form.designatedUserList.value = [];
  207. const rules = reactive({
  208. statisticType: [{ required: true, message: '请选择统计时间段', trigger: 'change, blur' }],
  209. pushChannel: [{ required: true, message: '请选择推送渠道', trigger: 'change' }],
  210. dayOfWeek: [{ required: true, message: '请选择推送日期', trigger: 'change' }],
  211. dayOfMonthList: [{ required: true, message: '请选择推送日', trigger: 'change' }],
  212. recipientType: [{ required: true, message: '请选择推送对象', trigger: ['blur', 'change'] }],
  213. userGroupList: [{ required: true, message: '请选择推送分组', trigger: 'change' }],
  214. // customUserList: [{ required: true, message: '请选择推送人员', trigger: 'change, blur' }],
  215. });
  216. // const form = reactive<reportMessage>({
  217. // configIdList: null,
  218. // type: 0,
  219. // statisticType: 0,
  220. // monthAndDayList: ['1', '1'],
  221. // dayOfWeek: 1,
  222. // monthList: [''],
  223. // dayOfMonthList: ['1'],
  224. // pushTimeList: ['09:00:00'],
  225. // pushChannel: [],
  226. // userGroupList: [],
  227. // designatedUserList: [],
  228. // recipientType: undefined,
  229. // customPushConfigList: [],
  230. // customUserList: []
  231. // });
  232. const submitForm = async (formEl: FormInstance | undefined) => {
  233. if (!formEl) return;
  234. await formEl.validate((valid, fields) => {
  235. if (valid) {
  236. console.log('submit!');
  237. let submitForm = reportMessageToFinal(form);
  238. console.log('submitForm', submitForm);
  239. if (pageType.value != 3) {
  240. addMassage(submitForm).then((res) => {
  241. console.log('新增res', res);
  242. ElMessage.success('新增成功');
  243. router.back();
  244. return res;
  245. });
  246. } else {
  247. editMassage(submitForm).then((res) => {
  248. console.log('修改res', res);
  249. ElMessage.success('修改成功');
  250. router.back();
  251. return res;
  252. });
  253. }
  254. } else {
  255. console.log('error submit!', fields);
  256. }
  257. });
  258. };
  259. const resetForm = (formEl: FormInstance | undefined) => {
  260. if (!formEl) return;
  261. formEl.resetFields();
  262. };
  263. const clickBack = () => {
  264. type.value = reportType.value;
  265. router.back();
  266. };
  267. watch(form, () => {
  268. console.log(`form newvalue:`, form);
  269. });
  270. const getDisableType = (pageType) => {
  271. if (pageType === 1) {
  272. // 新增
  273. disableType.value.statisticTypeDisable = false;
  274. disableType.value.contentDisable = false;
  275. } else if (pageType === 2) {
  276. // 查询
  277. disableType.value.statisticTypeDisable = true;
  278. disableType.value.contentDisable = true;
  279. } else if (pageType === 3) {
  280. // 编辑
  281. disableType.value.statisticTypeDisable = true;
  282. disableType.value.contentDisable = false;
  283. }
  284. };
  285. onBeforeMount(() => {
  286. if (pageType.value === 1) {
  287. // 新增
  288. getDisableType(1);
  289. }
  290. if (pageType.value === 2) {
  291. // 查询
  292. getDisableType(2);
  293. searchMassage(queryType).then((res) => {
  294. console.log('res', res);
  295. toReportMessage(form, res);
  296. return res;
  297. });
  298. }
  299. if (pageType.value === 3) {
  300. // 编辑
  301. getDisableType(3);
  302. searchMassage(queryType).then((res) => {
  303. console.log('res', res);
  304. toReportMessage(form, res);
  305. return res;
  306. });
  307. }
  308. form.type = reportType.value;
  309. });
  310. </script>
  311. <style lang="scss" scoped>
  312. .page {
  313. height: calc(100vh - 64px - 18px);
  314. background-color: rgba(255, 255, 255, 1);
  315. .top {
  316. display: flex;
  317. padding: 16px 0 15px 20px;
  318. border-bottom: 1px solid #e9e9e9;
  319. .topLeft {
  320. display: flex;
  321. align-items: center;
  322. cursor: pointer;
  323. a {
  324. display: flex;
  325. align-items: center;
  326. }
  327. }
  328. .topRight {
  329. margin-left: 20px;
  330. }
  331. }
  332. .content {
  333. display: flex;
  334. height: calc(100vh - 130px);
  335. .left {
  336. display: flex;
  337. flex-direction: column;
  338. position: relative;
  339. padding: 20px 0 0 32px;
  340. width: 769px;
  341. border-right: 1px solid rgba(0, 0, 0, 0.06);
  342. overflow-y: auto;
  343. .custom-report{
  344. max-height: calc(100vh - 450px);
  345. overflow-y: auto;
  346. }
  347. .two-btns {
  348. position: absolute;
  349. right: 33px;
  350. bottom: 32px;
  351. }
  352. }
  353. .right {
  354. height: 299px;
  355. width: 363px;
  356. margin-left: 31px;
  357. margin-top: 20px;
  358. background: #ffffff;
  359. border-radius: 4px 4px 0px 0px;
  360. border: 1px solid #e9e9e9;
  361. }
  362. }
  363. }
  364. </style>