ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<script lang="ts" setup>
import { reactive, ref, toRefs } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { useModal } from '@jnpf/ui/modal';
import { BasicPopup, usePopup, usePopupInner } from '@jnpf/ui/popup';
import { formValidate } from '@jnpf/utils';
 
import { Grid as VxeGrid } from 'vxe-table';
 
import { create, getInfo, update } from '#/api/msgCenter/sendConfig';
import { $t } from '#/locales';
import { useBaseStore } from '#/store';
 
import Detail from '../msgTemplate/Detail.vue';
import TemplateForm from './components/TemplateForm.vue';
 
const emit = defineEmits(['register', 'reload']);
 
interface State {
  title: string;
  dataForm: any;
  dataRule: any;
  messageTypeList: any[];
  messageSourceList: any[];
  refreshKey: number;
}
 
const state = reactive<State>({
  title: '',
  dataForm: {
    id: '',
    fullName: '',
    enCode: '',
    description: '',
    enabledMark: 1,
    sortCode: 0,
    messageSource: '',
    templateType: 0,
    sendConfigTemplateList: [],
  },
  dataRule: {
    fullName: [{ required: true, message: '必填', trigger: 'blur' }],
    enCode: [
      { required: true, message: '必填', trigger: 'blur' },
      { validator: formValidate('enCode'), trigger: 'blur' },
    ],
    messageSource: [{ required: true, message: '必填', trigger: 'change' }],
    messageType: [{ required: true, message: '必填', trigger: 'change' }],
  },
  messageTypeList: [],
  messageSourceList: [],
  refreshKey: 0,
});
const { dataForm, dataRule, title, messageSourceList, refreshKey } = toRefs(state);
const formElRef = ref();
const baseStore = useBaseStore();
const { createMessage, createConfirm } = useMessage();
const [registerPopup, { changeLoading, changeOkLoading, closePopup }] = usePopupInner(init);
const [registerTemplateForm, { openModal: openTemplateFormModal }] = useModal();
const [registerDetail, { openPopup: openDetailPopup }] = usePopup();
const columns: any[] = [
  { title: $t('component.table.index'), width: 50, type: 'seq', align: 'center' },
  { title: '消息类型', field: 'messageType', width: 150, slots: { default: 'messageType' } },
  { title: '模板编码', field: 'templateCode', width: 150 },
  { title: '模板名称', field: 'templateName', minWidth: 150 },
  { title: '账号编码', field: 'accountCode', width: 150 },
  { title: '账号名称', field: 'accountName', width: 150 },
  { title: '状态', field: 'enabledMark', width: 70, align: 'center', slots: { default: 'enabledMark' } },
  { title: '操作', field: 'action', width: 150, slots: { default: 'action' } },
];
 
function init(data) {
  formElRef.value?.resetFields();
  resetForm();
  state.dataForm.id = data.id || '';
  state.title = state.dataForm.id ? $t('common.editText') : $t('common.addText');
  initData();
  if (state.dataForm.id) {
    changeLoading(true);
    getInfo(state.dataForm.id)
      .then((res) => {
        changeLoading(false);
        res.data.enabledMark = Number(res.data.enabledMark);
        state.dataForm = res.data;
      })
      .catch(() => {
        changeLoading(false);
      });
  }
}
async function initData() {
  state.messageTypeList = (await baseStore.getDictionaryData('msgSendType')) as any[];
  state.messageTypeList.map((o) => (o.id = o.enCode));
  state.messageSourceList = (await baseStore.getDictionaryData('msgSourceType')) as any[];
  state.messageSourceList.map((o) => (o.id = o.enCode));
}
function addTemplateData(record?: any, index?: any) {
  if (!state.dataForm.messageSource) return createMessage.warning('请选择消息来源');
  openTemplateFormModal(true, { row: record, index, messageSource: state.dataForm.messageSource });
}
function addEditTemplate(e, index) {
  if (!index && index != 0) {
    state.dataForm.sendConfigTemplateList.push(e);
  } else {
    state.dataForm.sendConfigTemplateList[index] = e;
  }
  state.refreshKey = Date.now();
}
function handleDelete(index) {
  createConfirm({
    iconType: 'warning',
    title: $t('common.tipTitle'),
    content: '删除记录,不可恢复?',
    onOk: () => {
      state.dataForm.sendConfigTemplateList.splice(index, 1);
    },
  });
}
function handleDetail(id) {
  openDetailPopup(true, { id, msgTypeList: state.messageTypeList });
}
function resetForm() {
  state.dataForm = {
    id: '',
    fullName: '',
    enCode: '',
    description: '',
    enabledMark: 1,
    sortCode: 0,
    messageSource: '',
    templateType: 0,
    sendConfigTemplateList: [],
  };
}
async function handleSubmit() {
  try {
    const values = await formElRef.value?.validate();
    if (!values) return;
    changeOkLoading(true);
    const formMethod = state.dataForm.id ? update : create;
    formMethod(state.dataForm)
      .then((res) => {
        createMessage.success(res.msg);
        closePopup();
        changeOkLoading(false);
        emit('reload');
      })
      .catch(() => {
        changeOkLoading(false);
      });
  } catch {}
}
function onMessageSourceChange() {
  state.dataForm.sendConfigTemplateList = [];
}
function getMsgType(record) {
  const item = state.messageTypeList.find((o) => record.messageType == o.enCode);
  return item.fullName || '';
}
</script>
<template>
  <BasicPopup v-bind="$attrs" @register="registerPopup" show-ok-btn :title="title" @ok="handleSubmit" destroy-on-close>
    <a-form class="!mx-[20px]" :colon="false" :model="dataForm" :rules="dataRule" ref="formElRef" :label-col="{ style: { width: '100px' } }">
      <a-row :gutter="20">
        <a-col :span="12">
          <a-form-item label="名称" name="fullName">
            <a-input v-model:value="dataForm.fullName" placeholder="请输入" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="编码" name="enCode">
            <a-input v-model:value="dataForm.enCode" placeholder="请输入" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="模板类型">
            <a-input value="自定义模板" disabled allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="消息来源" name="messageSource">
            <jnpf-select
              v-model:value="dataForm.messageSource"
              placeholder="请选择"
              :disabled="!!dataForm.id"
              :options="messageSourceList"
              @change="onMessageSourceChange" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="排序" name="sortCode">
            <a-input-number :min="0" :max="999999" v-model:value="dataForm.sortCode" placeholder="请输入" />
          </a-form-item>
        </a-col>
        <a-col :span="12">
          <a-form-item label="状态" name="enabledMark">
            <a-switch v-model:checked="dataForm.enabledMark" :checked-value="1" :un-checked-value="0" />
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <a-form-item label="说明" name="description">
            <a-textarea v-model:value="dataForm.description" placeholder="请输入" type="textarea" :rows="3" />
          </a-form-item>
        </a-col>
        <a-col :span="24">
          <VxeGrid :data="dataForm.sendConfigTemplateList" :columns size="small" border="inner" :key="refreshKey">
            <template #enabledMark="{ row }">
              <a-switch v-model:checked="row.enabledMark" :checked-value="1" :un-checked-value="0" />
            </template>
            <template #messageType="{ row }">
              {{ getMsgType(row) }}
            </template>
            <template #action="{ row, rowIndex }">
              <a-button size="small" type="link" @click="addTemplateData(row, rowIndex)">{{ $t('common.editText') }}</a-button>
              <a-button size="small" type="link" color="error" @click="handleDelete(rowIndex)">{{ $t('common.delText') }}</a-button>
              <a-button size="small" type="link" @click="handleDetail(row.templateId)">{{ $t('common.detailText') }}</a-button>
            </template>
          </VxeGrid>
          <div class="table-add-action" @click="addTemplateData">
            <a-button type="link" pre-icon="icon-ym icon-ym-btn-add">{{ $t('common.addText') }}</a-button>
          </div>
        </a-col>
      </a-row>
    </a-form>
    <TemplateForm @register="registerTemplateForm" @reload="addEditTemplate" />
  </BasicPopup>
  <Detail @register="registerDetail" />
</template>