| <div class="layui-fluid layui-anim febs-anim" id="febs-activity-option" lay-title="活动选项列表"> | 
|     <div class="layui-row febs-container"> | 
|         <div class="layui-col-md12"> | 
|             <div class="layui-card"> | 
|                 <div class="layui-card-body febs-table-full"> | 
|                     <form class="layui-form layui-table-form" lay-filter="activity-table-form"> | 
|                         <div class="layui-row"> | 
|                             <div class="layui-col-md10"> | 
|                                 <div class="layui-form-item"> | 
|                                     <div class="layui-inline"> | 
|                                         <label class="layui-form-label layui-form-label-sm">选项名称</label> | 
|                                         <div class="layui-input-inline"> | 
|                                             <input type="text" placeholder="选项名称" name="optionName" autocomplete="off" class="layui-input"> | 
|                                         </div> | 
|                                     </div> | 
|                                     <div class="layui-inline"> | 
|                                         <label class="layui-form-label layui-form-label-sm">活动</label> | 
|                                         <div class="layui-input-inline"> | 
|                                             <select name="activityId" class="activity-type-option"> | 
|                                                 <option value="">请选择</option> | 
|                                             </select> | 
|                                         </div> | 
|                                     </div> | 
|                                     <div class="layui-inline"> | 
|                                         <label class="layui-form-label layui-form-label-sm">状态</label> | 
|                                         <div class="layui-input-inline"> | 
|                                             <select name="state"> | 
|                                                 <option value="">请选择</option> | 
|                                                 <option value="0">待审核</option> | 
|                                                 <option value="1">同意</option> | 
|                                                 <option value="2">拒绝</option> | 
|                                             </select> | 
|                                         </div> | 
|                                     </div> | 
|                                 </div> | 
|   | 
|                             </div> | 
|                             <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area"> | 
|                                 <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query"> | 
|                                     <i class="layui-icon"></i> | 
|                                 </div> | 
|                                 <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset"> | 
|                                     <i class="layui-icon"></i> | 
|                                 </div> | 
|                                 <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="export" title="导出"> | 
|                                     <i class="layui-icon"></i> | 
|                                 </div> | 
|                             </div> | 
|                         </div> | 
|                     </form> | 
|                     <table lay-filter="optionTable" lay-data="{id: 'optionTable'}"></table> | 
|                 </div> | 
|             </div> | 
|         </div> | 
|     </div> | 
| </div> | 
| <!-- 表格操作栏 start --> | 
| <script type="text/html" id="user-option"> | 
|     <span shiro:lacksPermission="list:view,add:add,votesActivityUpdate:update"> | 
|         <span class="layui-badge-dot febs-bg-orange"></span> 无权限 | 
|     </span> | 
|     <a lay-event="edit" shiro:hasPermission="votesActivityUpdate:update"><i | 
|             class="layui-icon febs-edit-area febs-blue"></i></a> | 
| </script> | 
| <script type="text/html" id="optionStateType"> | 
|     {{# | 
|     var state = { | 
|     0: {title: '待审核', color: 'blue'}, | 
|     1: {title: '同意', color: 'green'}, | 
|     2: {title: '拒绝', color: 'red'}, | 
|     }[d.state]; | 
|     }} | 
|     <span class="layui-badge febs-bg-{{state.color}}">{{ state.title }}</span> | 
| </script> | 
| <script type="text/html" id="optionToolbar"> | 
|     <div class="layui-btn-container"> | 
|         <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="optionAdd:add" lay-event="addOption">新增活动选项</button> | 
|     </div> | 
| </script> | 
|   | 
| <script type="text/html" id="optionOption"> | 
|     <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="optionInfo:view" lay-event="optionInfo">审核</button> | 
|     <button class="layui-btn layui-btn-normal layui-btn-sm" type="button" shiro:hasPermission="voteRecord:view" lay-event="voteRecord">得票记录</button> | 
|     <button class="layui-btn layui-btn-danger layui-btn-sm" type="button" shiro:hasPermission="optionDelete:delete" lay-event="optionDelete">删除</button> | 
| </script> | 
|   | 
| <style> | 
|     .layui-form-onswitch { | 
|         background-color: #5FB878 !important; | 
|     } | 
| </style> | 
| <!-- 表格操作栏 end --> | 
| <script data-th-inline="none" type="text/javascript"> | 
|     // 引入组件并初始化 | 
|     layui.use([ 'jquery', 'form', 'table', 'febs'], function () { | 
|         var $ = layui.jquery, | 
|             febs = layui.febs, | 
|             form = layui.form, | 
|             table = layui.table, | 
|             $view = $('#febs-activity-option'), | 
|             $query = $view.find('#query'), | 
|             $reset = $view.find('#reset'), | 
|             $searchForm = $view.find('form'), | 
|             sortObject = {field: 'phone', type: null}, | 
|             $export= $view.find('#export'), | 
|             tableIns; | 
|   | 
|         form.render(); | 
|         //(下拉框) | 
|         $.get(ctx + 'admin/happyActivity/allActivities', function (res) { | 
|             var data = res.data; | 
|             for (let k in data) | 
|             { | 
|                 $(".activity-type-option").append("<option value='" + data[k].id + "'>" + data[k].name + "</option>"); | 
|             } | 
|             layui.use('form', function () { | 
|                 var form = layui.form; | 
|                 form.render(); | 
|             }); | 
|         }); | 
|   | 
|         // 表格初始化 | 
|         initOptionTable(); | 
|         // 初始化表格操作栏各个按钮功能 | 
|         table.on('tool(optionTable)', function (obj) { | 
|             var data = obj.data, | 
|                 layEvent = obj.event; | 
|             if (layEvent === 'optionDelete') { | 
|                 febs.modal.confirm('删除', '确认删除该选项?', function () { | 
|                     optionDelete(data.id); | 
|                 }); | 
|             } | 
|   | 
|             if (layEvent === 'voteRecord') { | 
|                 febs.modal.open( '得票记录', 'modules/votesActivity/voteRecord/' + data.id, { | 
|                     maxmin: true, | 
|                 }); | 
|             } | 
|             if (layEvent === 'optionInfo') { | 
|                 febs.modal.open('审核编辑','modules/votesActivity/optionInfo/' + data.id, { | 
|                     btn: ['提交', '取消'], | 
|                     area: ['100%', '100%'], | 
|                     yes: function (index, layero) { | 
|                         $('#febs-option-info').find('#submit').trigger('click'); | 
|                     }, | 
|                     btn2: function () { | 
|                         layer.closeAll(); | 
|                     } | 
|                 }); | 
|             } | 
|         }); | 
|         function optionDelete(id) { | 
|             febs.get(ctx + 'admin/happyActivity/optionDelete/' + id, null, function (data) { | 
|                 febs.alert.success(data.message); | 
|                 $query.click(); | 
|             }); | 
|         } | 
|   | 
|         // 初始化表格操作栏各个按钮功能 | 
|         table.on('toolbar(optionTable)', function (obj) { | 
|             let data = obj.data, | 
|                     layEvent = obj.event; | 
|             console.log("触发事件:", obj.event); // 调试信息 | 
|             if(layEvent === 'addOption'){ | 
|                 febs.modal.open('新增','modules/votesActivity/optionAdd/', { | 
|                     btn: ['提交', '取消'], | 
|                     area: ['100%', '100%'], | 
|                     yes: function (index, layero) { | 
|                         $('#febs-option-add').find('#submit').trigger('click'); | 
|                     }, | 
|                     btn2: function () { | 
|                         layer.closeAll(); | 
|                     } | 
|                 }); | 
|             } | 
|         }); | 
|   | 
|         function changeState(id,state) { | 
|             febs.get(ctx + 'admin/happyActivity/changeOptionState/' + id+'/' + state, null, function (data) { | 
|                 febs.alert.success(data.message); | 
|                 $query.click(); | 
|             }); | 
|         } | 
|   | 
|   | 
|         function initOptionTable() { | 
|             tableIns = febs.table.init({ | 
|                 elem: $view.find('table'), | 
|                 id: 'optionTable', | 
|                 url: ctx + 'admin/happyActivity/optionList', | 
|                 toolbar:"#optionToolbar", | 
|                 defaultToolbar:[], | 
|                 cols: [[ | 
|                     {type: 'numbers', title: '', width: 80}, | 
|                     {title: '操作', toolbar: '#optionOption', minWidth: 200, align: 'center'}, | 
|                     {field: 'orderCnt', title: '编号', minWidth: 100,align:'center'}, | 
|                     {field: 'optionName', title: '选项名称', minWidth: 200,align:'center'}, | 
|                     {title: '审核状态', templet: '#optionStateType', minWidth: 100,align:'center'}, | 
|                     {field: 'createdTime', title: '创建时间', minWidth: 150,align:'left'} | 
|                 ]] | 
|             }); | 
|         } | 
|   | 
|         form.on('switch(optionAuditSwitch)', function (data) { | 
|             if (data.elem.checked) { | 
|                 changeState(data.value,1); | 
|             } else { | 
|                 changeState(data.value,0); | 
|             } | 
|         }) | 
|   | 
|   | 
|   | 
|         // 查询按钮 | 
|         $query.on('click', function () { | 
|             var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type}); | 
|             tableIns.reload({where: params, page: {curr: 1}}); | 
|         }); | 
|   | 
|        // 导出功能 | 
|         $export.on('click', function () { | 
|             var params = getQueryParams(); | 
|             var queryString = Object.keys(params).map(key => `${key}=${encodeURIComponent(params[key])}`).join('&'); | 
|   | 
|             window.location.href = ctx + 'admin/happyActivity/exportOptionList?' + queryString; | 
|         }); | 
|         // 刷新按钮 | 
|         $reset.on('click', function () { | 
|             $searchForm[0].reset(); | 
|             sortObject.type = 'null'; | 
|             tableIns.reload({where: getQueryParams(), page: {curr: 1}, initSort: sortObject}); | 
|         }); | 
|         // 获取查询参数 | 
|         function getQueryParams() { | 
|             return { | 
|                 optionName: $searchForm.find('input[name="optionName"]').val().trim(), | 
|                 activityId: $searchForm.find("select[name='activityId']").val(), | 
|                 state: $searchForm.find("select[name='state']").val(), | 
|             }; | 
|         } | 
|   | 
|     }) | 
| </script> |