detail.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <div class="modal">
  3. <el-dialog
  4. v-model="dialogVisible"
  5. :title="dialogTitle"
  6. :width="modalConfig.dialogWidth || '80%'"
  7. center
  8. @close="handleExcel(ruleFormRef)"
  9. :close-on-click-modal="false"
  10. >
  11. <template #header>
  12. <pageTitle :title="dialogTitle"></pageTitle>
  13. </template>
  14. <div class="form">
  15. <el-form
  16. ref="ruleFormRef"
  17. :rules="modalConfig.formRules"
  18. label-suffix=":"
  19. :model="formData"
  20. :label-width="modalConfig.labelWidth || '100px'"
  21. size="large"
  22. autocomplete="off"
  23. >
  24. <el-row :gutter="12">
  25. <template v-for="item in modalConfig.formItems" :key="item.prop">
  26. <el-col :span="item.span || 24">
  27. <el-form-item :label="item.label" :prop="item.prop">
  28. <template v-if="item.type === 'input'">
  29. <el-input
  30. :disabled="dialogLook || item.disabled"
  31. v-model="formData[item.prop]"
  32. :placeholder="item.placeholder"
  33. />
  34. </template>
  35. <template v-if="item.type === 'textarea'">
  36. <el-input
  37. :disabled="dialogLook || item.disabled"
  38. type="textarea"
  39. v-model="formData[item.prop]"
  40. :autosize="{ minRows: 3 }"
  41. show-word-limit
  42. :maxlength="item.maxlength || 200"
  43. :placeholder="item.placeholder"
  44. />
  45. </template>
  46. <template v-if="item.type === 'number'">
  47. <el-input
  48. v-model="formData[item.prop]"
  49. type="number"
  50. :min="0"
  51. :max="999999999999"
  52. :disabled="dialogLook || item.disabled"
  53. :placeholder="item.placeholder"
  54. />
  55. </template>
  56. <template v-if="item.type === 'select'">
  57. <el-select
  58. v-model="formData[item.prop]"
  59. :placeholder="item.placeholder"
  60. style="width: 100%"
  61. :disabled="dialogLook || item.disabled"
  62. >
  63. <template v-for="(val, index) in item.options" :key="index">
  64. <el-option :value="val.value" :label="val.label" />
  65. </template>
  66. </el-select>
  67. </template>
  68. <template v-if="item.type === 'date-picker'">
  69. <el-date-picker
  70. :type="item.dateType || 'daterange'"
  71. range-separator="-"
  72. start-placeholder="开始时间"
  73. end-placeholder="结束时间"
  74. v-model="formData[item.prop]"
  75. :disabled="dialogLook || item.disabled"
  76. />
  77. </template>
  78. <template v-if="item.type === 'date'">
  79. <el-date-picker
  80. type="date"
  81. :placeholder="item.placeholder"
  82. style="width: 100%"
  83. v-model="formData[item.prop]"
  84. :disabled="dialogLook || item.disabled"
  85. />
  86. </template>
  87. <!-- 发布单位 -->
  88. <template v-if="item.type === 'publishingUnit'">
  89. <el-tree-select
  90. v-model="formData[item.prop]"
  91. :data="treeData"
  92. :render-after-expand="false"
  93. :disabled="dialogLook || item.disabled"
  94. node-key="id"
  95. filterable
  96. :placeholder="item.placeholder"
  97. style="width: 100%"
  98. />
  99. </template>
  100. <!-- 发布状态 -->
  101. <template v-if="item.type === 'releaseStatus'">
  102. <el-select
  103. v-model="formData[item.prop]"
  104. :placeholder="item.placeholder"
  105. style="width: 100%"
  106. :disabled="dialogLook || item.disabled"
  107. >
  108. <template v-for="(val, index) in bj_nl_released_status" :key="index">
  109. <el-option :value="val.value" :label="val.label" />
  110. </template>
  111. </el-select>
  112. </template>
  113. <!-- 通报类型 -->
  114. <template v-if="item.type === 'notificationType'">
  115. <el-select
  116. v-model="formData[item.prop]"
  117. :placeholder="item.placeholder"
  118. style="width: 100%"
  119. :disabled="dialogLook || item.disabled"
  120. >
  121. <template v-for="(val, index) in bj_notification_type" :key="index">
  122. <el-option :value="val.value" :label="val.label" />
  123. </template>
  124. </el-select>
  125. </template>
  126. <!-- 通报事项类别 -->
  127. <template v-if="item.type === 'conm'">
  128. <el-select
  129. v-model="formData[item.prop]"
  130. :placeholder="item.placeholder"
  131. style="width: 100%"
  132. :disabled="dialogLook || item.disabled"
  133. >
  134. <template v-for="(val, index) in bj_category_onm" :key="index">
  135. <el-option :value="val.value" :label="val.label" />
  136. </template>
  137. </el-select>
  138. </template>
  139. <!-- 发出单位 -->
  140. <template v-if="item.type === 'deliveryUnit'">
  141. <el-select
  142. v-model="formData[item.prop]"
  143. :placeholder="item.placeholder"
  144. filterable
  145. style="width: 100%"
  146. :disabled="dialogLook || item.disabled"
  147. >
  148. <template v-for="(val, index) in bj_lssuing_unit" :key="index">
  149. <el-option :value="val.value" :label="val.label" />
  150. </template>
  151. </el-select>
  152. </template>
  153. </el-form-item>
  154. </el-col>
  155. </template>
  156. </el-row>
  157. </el-form>
  158. </div>
  159. <template #footer>
  160. <span class="dialog-footer">
  161. <el-button type="primary" v-show="dialogLook == false" @click="handleConfirmClick(ruleFormRef, '1')"
  162. >保存</el-button
  163. >
  164. <el-button type="primary" v-show="dialogLook == false" @click="handleConfirmClick(ruleFormRef, '2')"
  165. >提交</el-button
  166. >
  167. <el-button @click="handleExcel(ruleFormRef)">返回</el-button>
  168. <slot name="button"></slot>
  169. </span>
  170. </template>
  171. </el-dialog>
  172. </div>
  173. </template>
  174. <script setup lang="ts" name="modal">
  175. import { reactive, ref } from 'vue';
  176. import type { FormInstance } from 'element-plus';
  177. import useSystemStore from '@/store/main';
  178. import { TreeOptions } from '@/types/global';
  179. import dayjs from 'dayjs';
  180. import { outTypeList, outDeptTree } from '@/libs/commonMeth';
  181. const bj_notification_type = outTypeList('bj_notification_type'); //通报类型
  182. const bj_category_onm = outTypeList('bj_category_onm'); //通报事项类别
  183. const bj_nl_released_status = outTypeList('bj_nl_released_status'); //通报事项清单发布状态
  184. const bj_lssuing_unit = outTypeList('bj_lssuing_unit'); //发出单位
  185. // 定义props
  186. interface IProps {
  187. modalConfig: {
  188. pageName: string;
  189. addTitle: string;
  190. editTitle: string;
  191. detailTitle: string;
  192. dialogWidth: string;
  193. labelWidth: string;
  194. formItems: any[];
  195. formRules: object;
  196. pageListParams?: object; //新增一个对象,用来传给特殊的列表接口刷新页面(非必传)
  197. };
  198. otherInfo?: any;
  199. }
  200. const props = defineProps<IProps>();
  201. const dialogVisible = ref(false);
  202. const isEdit = ref(false);
  203. const ruleFormRef = ref<FormInstance>();
  204. const systemStore = useSystemStore();
  205. const { pageDetailInfo, pageOperateType } = storeToRefs(systemStore);
  206. // 定义数据绑定
  207. const initialForm: any = {};
  208. for (const item of props.modalConfig.formItems) {
  209. initialForm[item.prop] = item.initialValue ?? '';
  210. }
  211. let formData = ref(JSON.parse(JSON.stringify(initialForm)));
  212. const dialogTitle = ref();
  213. const dialogLook = ref(false);
  214. const nowStr = dayjs().format('YYYY-MM-DD');
  215. // 新建或者编辑
  216. async function setDialogVisible(isNew: boolean = true, check: boolean = false) {
  217. dialogVisible.value = true;
  218. ruleFormRef.value?.resetFields();
  219. await nextTick();
  220. dialogLook.value = false;
  221. if (!isNew) {
  222. watch(pageDetailInfo, newVal => {
  223. formData.value = pageDetailInfo.value;
  224. });
  225. if (check) {
  226. dialogTitle.value = props.modalConfig.detailTitle;
  227. dialogLook.value = true;
  228. systemStore.getDetailType('detail');
  229. } else {
  230. dialogTitle.value = props.modalConfig.editTitle;
  231. systemStore.getDetailType('edit');
  232. }
  233. } else {
  234. props.modalConfig.formItems.map((m: any) => {
  235. if (m.prop === 'addName') {
  236. initialForm[m.prop] = '张浩楠';
  237. }
  238. if (m.prop === 'publishingUnit') {
  239. initialForm[m.prop] = '100';
  240. }
  241. if (m.prop === 'addDate') {
  242. initialForm[m.prop] = nowStr;
  243. }
  244. if (m.prop === 'releaseStatus') {
  245. initialForm[m.prop] = '1';
  246. }
  247. });
  248. formData.value = JSON.parse(JSON.stringify(initialForm));
  249. await nextTick();
  250. dialogTitle.value = props.modalConfig.addTitle;
  251. systemStore.detailPageEval(initialForm);
  252. systemStore.getDetailType('add');
  253. }
  254. isEdit.value = !isNew;
  255. }
  256. // 点击确定
  257. function handleConfirmClick(formEl: FormInstance | undefined, status: string) {
  258. if (!formEl) return;
  259. formEl.validate((valid, fields) => {
  260. if (valid) {
  261. dialogVisible.value = false;
  262. // 可用状态 编辑始终 都是可用
  263. if (formData.value.releaseStatus != '2') {
  264. formData.value.releaseStatus == status;
  265. }
  266. let data = { ...formData.value };
  267. if (props.otherInfo) {
  268. data = { ...data, ...props.otherInfo };
  269. }
  270. if (!isEdit.value) {
  271. systemStore.newPageDataAction(props.modalConfig.pageName, data, props.modalConfig.pageListParams);
  272. } else {
  273. if (pageOperateType.value === 'edit') {
  274. systemStore.editPageDataAction(props.modalConfig.pageName, data, props.modalConfig.pageListParams);
  275. }
  276. }
  277. } else {
  278. console.log('error submit!', fields);
  279. }
  280. });
  281. }
  282. // 取消
  283. function handleExcel(formEl: FormInstance | undefined) {
  284. dialogVisible.value = false;
  285. if (!formEl) return;
  286. formEl.resetFields();
  287. }
  288. // 获取详情
  289. function onPageDetail(urlId: number | [] | string) {
  290. systemStore.detailPageDataAction(props.modalConfig.pageName, urlId);
  291. }
  292. const treeData = ref<TreeOptions[]>();
  293. onMounted(async () => {
  294. treeData.value = await outDeptTree();
  295. });
  296. defineExpose({
  297. setDialogVisible,
  298. onPageDetail,
  299. });
  300. </script>
  301. <style scoped lang="scss">
  302. .form {
  303. padding: 10px 30px;
  304. }
  305. </style>