addModal.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @cancel="resetFields"
  5. @register="register"
  6. :title="title"
  7. width="60%"
  8. min-width="600px"
  9. @ok="handleOk"
  10. >
  11. <div class="pt-3px pr-3px">
  12. <BasicForm @register="registerForm" :model="modelRef" />
  13. </div>
  14. </BasicModal>
  15. </template>
  16. <script lang="ts">
  17. // computed
  18. import { defineComponent, ref, h } from 'vue';
  19. import { addNoticeApi, editNoticeApi } from '/@/api/notification/list';
  20. import { BasicModal, useModalInner } from '/@/components/Modal';
  21. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  22. // import { ListAllCompanyApi } from '/@/api/corporation/list';
  23. import { useI18n } from '/@/hooks/web/useI18n';
  24. import { useMessage } from '/@/hooks/web/useMessage';
  25. // import { useUserStore } from '/@/store/modules/user';
  26. import { Tinymce } from '/@/components/Tinymce';
  27. import { formatToDateTime } from '/@/utils/dateUtil';
  28. const { t } = useI18n();
  29. export default defineComponent({
  30. components: { BasicModal, BasicForm },
  31. props: {
  32. userData: { type: Object },
  33. },
  34. emits: ['register', 'ok', 'cancel'],
  35. setup(_, { emit }) {
  36. const modelRef = ref({});
  37. // const userStore = useUserStore();
  38. // const { getCheckRole } = userStore;
  39. // const userinfo = computed(() => userStore.getUserInfo);
  40. // const { companyId } = userinfo.value;
  41. const schemas: FormSchema[] = [
  42. {
  43. field: 'id',
  44. component: 'Input',
  45. label: 'id',
  46. show: false,
  47. },
  48. {
  49. field: 'title',
  50. component: 'Input',
  51. label: '标题',
  52. required: true,
  53. colProps: {
  54. span: 22,
  55. },
  56. },
  57. {
  58. field: 'effectiveTime',
  59. component: 'RangePicker',
  60. componentProps: {
  61. format: 'YYYY-MM-DD HH:mm:ss',
  62. },
  63. label: '时间段',
  64. required: true,
  65. colProps: {
  66. span: 22,
  67. },
  68. },
  69. {
  70. field: 'type',
  71. component: 'RadioButtonGroup',
  72. label: '类型',
  73. required: true,
  74. colProps: {
  75. span: 22,
  76. },
  77. defaultValue: 0,
  78. componentProps: {
  79. options: [
  80. { label: '文字', value: 0 },
  81. { label: '图片', value: 1 },
  82. ],
  83. },
  84. },
  85. {
  86. field: 'content',
  87. label: '内容',
  88. component: 'Input',
  89. render: ({ model, field }) => {
  90. return h(Tinymce, {
  91. value: model[field],
  92. maxlength: 200,
  93. onChange: (value: string) => {
  94. model[field] = value;
  95. },
  96. showImageUpload: false,
  97. });
  98. },
  99. },
  100. ];
  101. const title = ref('新 增');
  102. const { createMessage } = useMessage();
  103. const [registerForm, { validate, resetFields }] = useForm({
  104. labelWidth: 120,
  105. schemas,
  106. showActionButtonGroup: false,
  107. actionColOptions: {
  108. span: 24,
  109. },
  110. });
  111. // closeModal
  112. const [register, { closeModal }] = useModalInner((data) => {
  113. data && onDataReceive(data);
  114. });
  115. function onDataReceive(data) {
  116. // 方式1;
  117. console.log('useModalInner', data);
  118. // setFieldsValue({
  119. // ...data,
  120. // roleId: data.roleId != 2 ? data.roleId : '',
  121. // });
  122. // let setSchema = [
  123. // {
  124. // field: 'roleId',
  125. // component: 'ApiSelect',
  126. // componentProps: {
  127. // disabled: data.roleId == 2 ? false : data.id ? true : false,
  128. // api: getRoleListByParam,
  129. // labelField: 'roleName',
  130. // valueField: 'roleId',
  131. // params: {
  132. // type: data.roleId ? 1 : 0,
  133. // roleId: data.roleId,
  134. // },
  135. // },
  136. // },
  137. // {
  138. // field: 'phone',
  139. // componentProps: {
  140. // disabled: getCheckRole('plat_admin') ? false : data.id ? true : false,
  141. // },
  142. // },
  143. // {
  144. // field: 'companyId',
  145. // componentProps: {
  146. // disabled: data.id ? (data.roleId != 2 ? true : false) : false,
  147. // },
  148. // },
  149. // {
  150. // field: 'permList',
  151. // componentProps: {
  152. // disabled: data.roleId == 2 ? false : data.id ? true : false,
  153. // params: {
  154. // companyId: data.companyId || companyId,
  155. // },
  156. // },
  157. // },
  158. // ];
  159. // title.value = data.id ? '编辑' : '新增';
  160. // updateSchema(setSchema);
  161. }
  162. async function handleOk() {
  163. let data = await validate();
  164. console.log('data', data);
  165. const requestApi = data.id ? editNoticeApi : addNoticeApi;
  166. let res = await requestApi({
  167. title: data.title,
  168. content: data.content,
  169. type: String(data.type),
  170. effectiveTime: data.effectiveTime.map((i) => formatToDateTime(i)),
  171. id: data.id,
  172. });
  173. console.log('res', res);
  174. emit('ok', res);
  175. createMessage.success(t('common.optSuccess'));
  176. closeModal();
  177. resetFields();
  178. }
  179. return {
  180. register,
  181. title,
  182. schemas,
  183. registerForm,
  184. modelRef,
  185. handleOk,
  186. resetFields,
  187. };
  188. },
  189. });
  190. </script>