广州市综治平台前端
xusd
19 hours ago bdeacb9f02dfa74bac74296a4a2c989a8e0d45ff
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
import React, { useState, useEffect } from 'react';
import { Modal, Space, Tooltip } from 'antd';
import TableView from '@/components/TableView';
import * as $$ from '@/utils/utility';
import './index.less';
 
// 获取模板列表
function getTemplateListApi(params) {
  return $$.ax.request({ 
    url: '/sy/template/page', 
    type: 'get',
    data: params,
    service: 'mediate' 
  });
}
 
const TemplateChoose = ({ 
  visible = false, 
  onCancel, 
  onSelect,
  type = '' 
}) => {
  const [templateList, setTemplateList] = useState([]);
  const [pagination, setPagination] = useState({
    current: 1,
    pageSize: 10,
    total: 0,
    tempType: type
  });
 
  // 获取模板列表
  const getTemplateList = async (params = {}) => {
    const res = await getTemplateListApi({
      page: pagination.current,
      size: pagination.pageSize,
      businessType:pagination.tempType,
      templateType:2,
      ...params
    });
    if (res.type) {
      setTemplateList(res.data.records.map((item, index) => ({
        ...item,
        indexNo: (pagination.current - 1) * pagination.pageSize + index + 1
      })));
      setPagination({
        ...pagination,
        total: res.data.total
      });
    }
  };
 
  useEffect(() => {
    if (visible) {
      getTemplateList();
    }
  }, [visible, pagination.current, pagination.pageSize]);
 
  // 表格列定义
  const templateColumns = [
    {
      title: '序号',
      dataIndex: 'indexNo',
      width: 50,
    },
    {
      title: '类型',
      dataIndex: 'templateType',
      width: 50,
    },
    {
      title: '模板名称',
      dataIndex: 'templateName',
      width: 100,
    },
    {
      title: '模板内容',
      dataIndex: 'templateContent',
      width: 500,
      render: (text, record) => {
        return (
          <div className="template-content">
            <div className="content-text">
              {text}
            </div>
            <div className="view-more-row">
              <span 
                className="view-more" 
                onClick={(e) => {
                  e.stopPropagation();
                  Modal.confirm({
                    title: (
                      <div className="modal-title-wrapper">
                        <div className="modal-title-label">模板</div>
                        <div className="template-name">{record.templateName}</div>
                      </div>
                    ),
                    content: (
                      <div className="template-detail-content">
                        <div className="template-text">{text}</div>
                      </div>
                    ),
                    width: 400,
                    className: 'template-detail-modal',
                    icon: null,
                    cancelText: '关闭',
                    okText: '使用',
                    okButtonProps: {
                      className: 'confirm-ok-btn'
                    },
                    cancelButtonProps: {
                      className: 'confirm-cancel-btn'
                    },
                    onOk: () => {
                      onSelect && onSelect(record);
                      onCancel && onCancel();
                    }
                  });
                }}
              >
                ...查看更多
              </span>
            </div>
          </div>
        );
      }
    },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      render: (_, record) => (
        <Space>
          <div 
            onClick={() => {
              onSelect && onSelect(record);
              onCancel && onCancel();
            }} 
            className="operate-link"
          >
            使用
          </div>
        </Space>
      )
    },
  ];
 
  return (
    <Modal
      title="选择模版"
      open={visible}
      onCancel={onCancel}
      width={938}
      style={{ 
        top: 100,
      }}
      footer={null}
      destroyOnClose
      bodyStyle={{
        padding: '12px 24px',
        maxHeight: '600px'
      }}
    >
      <TableView
        columns={templateColumns}
        dataSource={templateList}
        rowKey="id"
        pagination={{
          ...pagination,
          onChange: (page, pageSize) => {
            setPagination({
              ...pagination,
              current: page,
              pageSize
            });
          }
        }}
        scroll={{ y: 260 }}
        style={{
          marginTop: -8
        }}
      />
    </Modal>
  );
};
 
export default TemplateChoose;