forked from kidgrow-microservices-platform

zhaoxiaohao
2021-03-02 1a50269b1d072fe2da7e70ae48315ebeb4ef95f4
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
230
231
232
233
234
235
236
237
238
239
240
241
242
<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">医生模板</h2>
        <span class="layui-breadcrumb pull-right">
            <a href="#!home_console">首页</a>
            <a><cite>医生模板</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            <select id="templeteType" placeholder="话术类型">
                <option value="">-请选择-</option>
                <option value="0">结论</option>
                <option value="1">建议</option>
                <option value="2">方案</option>
            </select>
            <select id="publicType" placeholder="开放类型">
                <option value="">-请选择-</option>
                <option value="0">公开-</option>
                <option value="1">私有</option>
            </select>
            <input name="templeteTitle" id="templeteTitle" autocomplete="off" placeholder="按标题" type="text"
                class="layui-input search-input" maxlength="20" />
            <button id="app-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
            <button id="docto-templete-btn-add" class="layui-btn icon-btn permissions" permissions="doctortemplete-edit"><i class="layui-icon">&#xe654;</i>添加</button>
        </div>
 
        <!-- 数据表格 -->
        <table class="layui-table permissions" permissions="doctortemplete-list" id="app-table" lay-filter="app-table"></table>
    </div>
</div>
 
<!-- 表格操作列 -->
<script type="text/html" id="doctor-templete-table-bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs permissions" permissions="doctortemplete-edit"  lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-xs permissions" permissions="doctortemplete-del"  lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="doctor-templete-tpl-state">
    <input type="checkbox" lay-filter="doctor-templete-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="正常|锁定"
           {{d.enabled==true?'checked':''}} class="permissions" permissions="doctortemplete-enable"/>
</script>
 
<!-- 表单弹窗 -->
<script type="text/html" id="app-model">
    <form id="app-form" lay-filter="app-form" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input name="templeteTitle" autocomplete="off" type="text" class="layui-input" maxlength="20"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">话术类型</label>
            <div class="layui-input-block">
                <select name="templeteType" placeholder="话术类型" lay-verify="required" required>
                    <option value="">-请选择-</option>
                    <option value="0">结论</option>
                    <option value="1">建议</option>
                    <option value="2">方案</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">开放类型</label>
            <div class="layui-input-block">
                <select id="publicType-add" name="publicType" placeholder="开放类型" lay-verify="required" required>
                    <option value="">-请选择-</option>
                    <option value="0">公开</option>
                    <option value="1">私有</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">说明:</label>
            <div class="layui-input-block">
                <textarea name="templeteNote" placeholder="请输入内容" class="layui-textarea"></textarea>
              </div>
        </div>
        <div class="layui-form-item model-form-footer">
            <button class="layui-btn layui-btn-primary"  ew-event="closeDialog" type="button">取消</button>
            <button class="layui-btn" id="sure" lay-filter="user-form-submit" permissions="    
            doctortemplete-edit" lay-submit>保存</button>
        </div>
    </form>
</script>
 
 
<script>
    layui.use(['form', 'table', 'laydate', 'util', 'config', 'admin'], function () {
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var layer = layui.layer;
        var util = layui.util;
        var admin = layui.admin;
 
        // 添加按钮点击事件
        $('#docto-templete-btn-add').click(function () {
            showEditModel(undefined, 1);
        });
        //// 刷新
        $('#docto-templete-btn-update').click(function () {
            table.reload('app-table', { where: {} });
        });
 
        // 渲染表格
        table.render({
            elem: '#app-table',
            url: config.base_server + 'api-opration/doctortemplete',
            method: 'GET',
            headers: { 'Authorization': 'Bearer ' + config.getToken().access_token },
            page: true,
            cols: [[
                { field: 'templeteTitle',align:'center', width: 300, title: '标题' },
                {
                    field: 'publicType',align:'center', width: 100, title: '开放类型', templet: function (d) {
                        return d.publicType ==true ? "私有" : "公开"
                    }
                },
                {
                    field: 'templeteType',align:'center', width: 100, title: '话术类型', templet: function (d) {
                        if (d.templeteType == 0) {
                            return "结论";
                        } else if (d.templeteType == 1) {
                            return "建议";
                        } else if (d.templeteType == 2) {
                            return "方案";
                        }
                    }
                },
                { field: 'createUserName',align:'center', width: 180, title: '创建者' },
                { field: 'createTime',align:'center', width: 150, sort: true, title: '创建时间', templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy/MM/dd HH:mm')}}</div>" },
                { field: 'enabled',align:'center', width: 100, templet: '#doctor-templete-tpl-state', title: '状态' ,fixed: 'right' },
                { field: 'recordTitle',align:'center', width: 150, toolbar: '#doctor-templete-table-bar', title: '操作',fixed: 'right' },
            ]],
            done:function(res){
                permissionsInput(res,config);
            }
        });
 
        // 工具条点击事件
        table.on('tool(app-table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 查看详情
                showEditModel(data, 2);
            }else if(layEvent === 'del'){
                layer.confirm('确定删除此用户吗?', function (i) {
                    layer.close(i);
                    layer.load(2);
                    admin.req('api-opration/doctortemplete/' + obj.data.id, {}, function (data) {
                        layer.closeAll('loading');
                        if (data.code == 0) {
                            layer.msg(data.msg, { icon: 1, time: 2000 });
                            table.reload('app-table', {});
                        } else {
                            layer.msg(data.msg, { icon: 2, time: 2000 });
                        }
                    }, 'delete');
                });
            }
        });
 
        // 搜索按钮点击事件
        $('#app-btn-search').click(function () {
            var templeteType = $('#templeteType').val();
            var publicType = $('#publicType').val();
            var templeteTitle = $('#templeteTitle').val();
            table.reload('app-table', { where: { templeteType: templeteType, publicType: publicType, templeteTitle: templeteTitle },page: {curr: 1  } });
        });
 
        // 修改user状态
        form.on('switch(doctor-templete-tpl-state)', function (obj) {
            layer.load(2);
            admin.req('api-opration/doctortemplete/updateEnabled', {
                id: obj.elem.value,
                enabled: obj.elem.checked ? true : false
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    layer.msg(data.msg, { icon: 1, time: 2000 });
                    table.reload('app-table', {});
                } else {
                    layer.msg(data.msg, { icon: 2, time: 2000 });
                    $(obj.elem).prop('checked', !obj.elem.checked);
                    form.render('checkbox');
                }
            }, 'GET');
        });
 
        // 表单提交事件
        form.on('submit(user-form-submit)', function (data) {
            layer.load(2);
            if(data.field.publicType==1){
                data.field.publicType=true;
            }else if (data.field.publicType==0){
                data.field.publicType=false;
            }
            admin.req('api-opration/doctortemplete', JSON.stringify(data.field), function (data) {
                layer.closeAll('loading');
                if (data.code == 0) {
                    // layer.msg(data.msg, { icon: 1, time: 2000 });
                    layer.closeAll();
                    table.reload('app-table', {});
                } else {
                    layer.msg(data.msg, { icon: 2, time: 2000 });
                }
            }, "POST");
            return false;
        });
        // // 显示编辑弹窗
        var showEditModel = function (data, index) {
            var title = "";
            if (index == 1) {
                title = "新增";
            } else if (index == 2) {
                title = "修改";
            }
            layer.open({
                type: 1,
                title: title,
                area: '450px',
                offset: '120px',
                content: $('#app-model').html(),
                success: function () {
                    $('#app-form')[0].reset();
                    $('#app-form').attr('method', 'POST');
                    if (data) {
                        if(index==1){
                            $('#sure').hide();
                        }
                        form.val('app-form', data);
                        $('#publicType-add').val(data.publicType == true ? 1 : 0);
                    }
                }
            });
        };
    });
</script>