index.php 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434
  1. <?php
  2. require_once('loginCheck.php');
  3. require_once('header.php');
  4. ?>
  5. <div class="container-fluid" id="layerUI">
  6. <div class="box-inner">
  7. <div style="display:none;">
  8. <label class=" control-label">用于layer中获取当前活动ID</label>
  9. <input type="number" id="curActivityID">
  10. <label class="control-label">弹出index</label>
  11. <input type="number" id="addQuestionLayerIndex">
  12. <label class=" control-label">活动ID</label>
  13. <input type="number" id="resetID">
  14. <label class="control-label">弹出index</label>
  15. <input type="number" id="resetLayerIndex">
  16. </div>
  17. <div class="box-content">
  18. <div class="row-fluid alert alert-success">
  19. <strong>温馨提示:</strong>行家APP中需要使用哪个问卷活动,请在加载H5的URL中加入参数<strong>[activityID=问卷活动ID]</strong>
  20. 如:http://xx.pingan.com.cn/pingan_h5?appToken=1111&activityID=123
  21. </div>
  22. <div class="row-fluid alert alert-danger">
  23. <strong>注意事项:</strong>自定义背景尺寸:宽:750,高:1624 &nbsp;&nbsp;<strong>自定义标题尺寸:</strong>:宽不超过500,高不超过200
  24. </div>
  25. <div class="row-fluid">
  26. <button type="button" class="btn btn-default" id="btnAddActivity">新增问卷活动</button>
  27. </div>
  28. <div class="row-fluid">
  29. <div class="span12">
  30. <table border="0" cellspacing="0" cellpadding="2" class="layui-hide" id="activityTable">
  31. </table>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="box-content" id="questionListHTML" style="display:none;">
  36. <div class="row-fluid">
  37. <button type="button" class="btn btn-default" id="btnAddQuestion">新增题目</button>
  38. </div>
  39. <div class="row-fluid">
  40. <div class="span12">
  41. <table border="0" cellspacing="0" cellpadding="2" class="layui-hide" id="questionTable">
  42. </table>
  43. </div>
  44. </div>
  45. </div>
  46. <div class="box-content" id="questionHTML" style="display:none;">
  47. <table class="table table-bordered table-striped responsive" id="tmpQuestionTb">
  48. <tbody>
  49. <tr id="quOrder">
  50. <td width='10%'>
  51. <label class="control-label">排序值:</label>
  52. </td>
  53. <td>
  54. <input type="number" class="form-control" id="qOrder">
  55. </td>
  56. </tr>
  57. <tr id="quType">
  58. <td width='10%'>
  59. <label class="control-label">题目类型:</label>
  60. <span><strong style="color:red">*</strong>必选</span>
  61. </td>
  62. <td>
  63. <label class="radio-inline">
  64. <input type="radio" name="optionRadio" id="qType1" value="1"> 单选题
  65. </label>
  66. <label class="radio-inline">
  67. <input type="radio" name="optionRadio" id="qType2" value="2"> 多选题
  68. </label>
  69. <label class="radio-inline">
  70. <input type="radio" name="optionRadio" id="qType3" value="3"> 问答题
  71. </label>
  72. </td>
  73. </tr>
  74. <tr id="quContent">
  75. <td width='10%'>
  76. <label class="control-label">题目内容:</label>
  77. <span><strong style="color:red">*</strong>最多50个字符</span>
  78. </td>
  79. <td>
  80. <input type="text" class="form-control" id="qContent" maxlength="50">
  81. </td>
  82. </tr>
  83. <tr id="quOptions">
  84. <td width='10%'>
  85. <label class="control-label">选项内容:</label>
  86. <span><strong style="color:red">*</strong>最少需要2个选项,最多支持8个选项</span>
  87. <br /><br />
  88. <a class="btn btn-info" onclick="addOpt()">
  89. <i class="glyphicon glyphicon-plus icon-white"></i>
  90. 增加选项
  91. </a>
  92. </td>
  93. <td>
  94. <table class="table table-bordered table-striped responsive" id="optionsTable">
  95. <tbody>
  96. <tr>
  97. <td width='10%'><label class="control-label">选项1</label></td>
  98. <td>
  99. <input type="text" class="form-control" id="qOptions" placeholder="">
  100. </td>
  101. <td width=50>
  102. <a class="btn btn-info" onclick="delOpt()"><i class="glyphicon glyphicon-trash icon-white" onclick="delOpt()"></i></a>
  103. </td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. </td>
  108. </tr>
  109. <tr id="quAnswers">
  110. <td width='10%'>
  111. <label class="control-label">正确答案:</label>
  112. </td>
  113. <td>
  114. <label class="checkbox-inline">
  115. <input type="checkbox" id="inlineCheckbox1" value="option1"> 多选
  116. </label>
  117. <label class="radio-inline">
  118. <input type="radio" name="optionRadio" id="qType3" value="option2"> 单选
  119. </label>
  120. </td>
  121. </tr>
  122. </tbody>
  123. </table>
  124. <button type="button" class="btn btn-default" id="btnUpdateQuestion" style="margin-left:40%;">确定</button>
  125. </div>
  126. <div class="box-content" id="userListHTML" style="display:none;">
  127. <div class="row-fluid">
  128. <button type="button" class="btn btn-default" id="btnExport">导出数据</button>
  129. </div>
  130. <div class="row-fluid">
  131. <div class="span12">
  132. <table border="0" cellspacing="0" cellpadding="2" class="layui-hide" id="userTable">
  133. </table>
  134. </div>
  135. </div>
  136. </div>
  137. <div class="box-content" id="activityHTML" style="display:none;">
  138. <form role="form">
  139. <div class="form-group">
  140. <label class="control-label">输入活动名称</label>
  141. <input type="text" class="form-control" id="txtName" placeholder="">
  142. </div>
  143. <div class="form-group">
  144. <label class="control-label">输入领奖提示</label>
  145. <input type="text" class="form-control" id="txtTips" placeholder="">
  146. </div>
  147. <button type="button" class="btn btn-default" id="btnUpdateActivity" style="margin-left:40%;">确定</button>
  148. </form>
  149. </div>
  150. <div class="box-content" id="prizeListHTML" style="display:none;">
  151. <div class="row-fluid alert alert-success">
  152. <strong>温馨提示1:</strong>抽奖转盘为8等分扇形区域,每个区域的ID为按顺时针方向0点开始的位置从1至8依次递增
  153. </div>
  154. <div class="row-fluid alert alert-success">
  155. <strong>温馨提示2:</strong>奖项名字为转盘上的名字;奖品名字为抽中后弹出的具体奖品名称。如需要“谢谢参与”这种不中奖的情况,请把奖品和奖项名称都改为谢谢参与
  156. </div>
  157. <div class="row-fluid alert alert-danger">
  158. <strong>注意事项:</strong>请确保8个奖品的抽中概率加起来是100% &nbsp;&nbsp;<strong>奖品图片尺寸:</strong>:70x70
  159. </div>
  160. <table border="0" cellspacing="0" cellpadding="2" class="layui-hide" id="prizeTable">
  161. </table>
  162. </div>
  163. <div class="box-content" id="modifyRateHTML" style="display:none;">
  164. <form role="form">
  165. <div class="form-group">
  166. <label class="control-label">输入奖项名字,最多可输入四个字(如:行家初遇、特等奖)</label>
  167. <input type="text" class="form-control" id="txtType" placeholder="" maxlength="4">
  168. </div>
  169. <div class="form-group">
  170. <label class="control-label">输入奖品名字</label>
  171. <input type="text" class="form-control" id="txtPrizeName" placeholder="">
  172. </div>
  173. <div class="form-group">
  174. <label class="control-label">输入抽中概率,支持两位小数(如:2.5%,请输入2.5)</label>
  175. <input type="text" class="form-control" id="txtRate" placeholder="" onkeyup="RateNumberCheck(this)">
  176. </div>
  177. <div class="form-group">
  178. <label class="control-label">输入奖品总数</label>
  179. <input type="number" class="form-control" id="txtSum" placeholder="">
  180. </div>
  181. <button type="button" class="btn btn-default" id="btnUpdatePrize" style="margin-left:40%;">确定</button>
  182. </form>
  183. </div>
  184. <div class="box-content" id="resetDataHTML" style="display:none;">
  185. <div class="box-content">
  186. <div class="alert alert-danger">
  187. <strong>请注意!</strong> 本操作将重置所有参与本活动用户的抽奖记录以及奖品列表中的中奖数量!正式上线后请勿重置数据,<strong>本功能仅供测试期间多次抽奖用!</strong>
  188. </div>
  189. </div>
  190. <div class="box-content">
  191. <button type="button" class="btn btn-danger" onclick="onClickReset();" style="margin-left:40%;">重置</button>
  192. </div>
  193. </div>
  194. </div>
  195. </div>
  196. <script type="text/javascript" charset="utf-8">
  197. function RateNumberCheck(obj){
  198. obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
  199. obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
  200. obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
  201. obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
  202. obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //控制可输入的小数
  203. }
  204. $(document).on("click", "#btnAddActivity", function() {
  205. var contentHTML = document.getElementById("activityHTML");
  206. layer.open({
  207. type: 1,
  208. title: "新增问卷活动",
  209. area: ['320px', '270px'],
  210. content: $("#activityHTML"),
  211. end: function(index, layero) {
  212. $(document).off("click", "#btnUpdateActivity")
  213. contentHTML.style.display = 'none';
  214. },
  215. success: function(layero, index) {
  216. $("#txtName").val("");
  217. $("#txtTips").val("");
  218. $(document).on("click", "#btnUpdateActivity", function() {
  219. var activityName = $("#txtName").val();
  220. var activityTips = $("#txtTips").val();
  221. $.ajax({
  222. type: 'post',
  223. dataType: "json",
  224. data: {
  225. activityName: activityName,
  226. activityTips: activityTips
  227. },
  228. url: "ajax.php?action=addActivity",
  229. success: function(result) {
  230. if (result && result.code == 200) {
  231. console.log("添加成功");
  232. window.location.reload();
  233. layer.close();
  234. contentHTML.style.display = 'none';
  235. } else {
  236. layer.alert("添加失败");
  237. }
  238. },
  239. error: function(errMsg) {
  240. layer.alert("添加出错");
  241. }
  242. });
  243. });
  244. }
  245. });
  246. });
  247. layui.use('table', function() {
  248. var table = layui.table;
  249. table.render({
  250. elem: '#activityTable',
  251. url: './ajax.php?action=activityList'
  252. //,cellMinWidth: 80 //全局定义常规单元格的最小宽度,layui 2.2.1 新增
  253. ,
  254. page: true,
  255. limit: 30,
  256. cols: [
  257. [{
  258. field: 'id',
  259. title: '问卷活动ID',
  260. width: '5%',
  261. align: 'center'
  262. },
  263. {
  264. field: 'activity_name',
  265. title: '问卷活动名称',
  266. width: '10%',
  267. align: 'center'
  268. },
  269. {
  270. field: 'activity_tips',
  271. title: '领奖提示',
  272. width: '20%',
  273. align: 'center'
  274. },
  275. {
  276. field: 'bg_img',
  277. title: '自定义背景',
  278. align: 'center',
  279. templet: function(d) {
  280. d.activityID = d.id
  281. d.type = 'act'
  282. let btnDel = '<button type="button" id="delBgImg' + d.id + '" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" onclick="delImg(' + JSON.stringify(d).replace(/"/g, '&quot;') + ', 1);" ><i class="layui-icon">&#x1006;</i></button>';
  283. let btnUp = '<button type="button" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" id="upBgImg' + d.id + '"><i class="layui-icon">&#xe67c;</i></button>'
  284. let imgURL = d.bg_img ? ('<?php echo URL_FOR_SAVE_PATH; ?>' + d.bg_img) : '""'
  285. let imgPrev = '<img onclick="showPrizeImg(this)" src=' + imgURL + ' id=bg_img_' + d.id + '>'
  286. if(d.bg_img != null && d.bg_img.length > 0)
  287. {
  288. return imgPrev + btnUp + btnDel
  289. }
  290. return imgPrev + btnUp
  291. }
  292. },
  293. {
  294. field: 'title_img',
  295. title: '自定义标题',
  296. align: 'center',
  297. width: '15%',
  298. templet: function(d) {
  299. d.activityID = d.id
  300. d.type = 'act'
  301. let btnDel = '<button type="button" id="delTitleImg' + d.id + '" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" onclick="delImg(' + JSON.stringify(d).replace(/"/g, '&quot;') + ', 2);" ><i class="layui-icon">&#x1006;</i></button>';
  302. let btnUp = '<button type="button" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" id="upTitleImg' + d.id + '"><i class="layui-icon">&#xe67c;</i></button>'
  303. let imgURL = d.title_img ? ('<?php echo URL_FOR_SAVE_PATH; ?>' + d.title_img) : '""'
  304. let imgPrev = '<img onclick="showPrizeImg(this)" src=' + imgURL + ' id=title_img_' + d.id + '>'
  305. if(d.title_img != null && d.title_img.length > 0)
  306. {
  307. return imgPrev + btnUp + btnDel
  308. }
  309. return imgPrev + btnUp
  310. }
  311. },
  312. {
  313. title: '操作',
  314. align: 'center',
  315. templet: function(d) {
  316. var edit = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="edit(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >修改</button>'
  317. var del = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="del(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >删除</button>'
  318. var user = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="showUserList(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >用户列表</button>'
  319. var reward = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="showPrizeList(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >奖品列表</button>'
  320. var question = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="showQuestionList(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >题目列表</button>'
  321. var reset = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="resetData(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >抽奖重置</button>'
  322. return question + user + reward + reset + edit + del;
  323. }
  324. }
  325. ]
  326. ],
  327. done:function(res, curr, count){
  328. for(let i = 0; i < res.data.length; ++i)
  329. {
  330. let itemData = res.data[i];
  331. uploadActImg(itemData.id, 'upBgImg' + itemData.id, 'bg')
  332. uploadActImg(itemData.id, 'upTitleImg' + itemData.id, 'title')
  333. }
  334. }
  335. });
  336. });
  337. function edit(data) {
  338. var contentHTML = document.getElementById("activityHTML");
  339. layer.open({
  340. type: 1,
  341. title: "修改活动名称",
  342. area: ['320px', '270px'],
  343. content: $("#activityHTML"),
  344. end: function(index, layero) {
  345. $(document).off("click", "#btnUpdateActivity")
  346. contentHTML.style.display = 'none';
  347. },
  348. success: function(layero, index) {
  349. $("#txtName").val(data.activity_name);
  350. $("#txtTips").val(data.activity_tips);
  351. $(document).on("click", "#btnUpdateActivity", function() {
  352. var activityName = $("#txtName").val();
  353. var activityTips = $("#txtTips").val();
  354. $.ajax({
  355. type: 'post',
  356. dataType: "json",
  357. data: {
  358. activityID: data.id,
  359. activityName: activityName,
  360. activityTips: activityTips
  361. },
  362. url: "ajax.php?action=modifyActivity",
  363. success: function(result) {
  364. if (result && result.code == 200) {
  365. console.log("修改成功");
  366. window.location.reload();
  367. layer.close();
  368. contentHTML.style.display = 'none';
  369. } else {
  370. layer.alert("修改失败");
  371. }
  372. },
  373. error: function(errMsg) {
  374. layer.alert("修改出错");
  375. }
  376. });
  377. });
  378. }
  379. });
  380. }
  381. $(document).on("click", "#btnAddQuestion", function() {
  382. let curActivityID = $("#curActivityID").val();
  383. var contentHTML = document.getElementById("questionHTML");
  384. layer.open({
  385. type: 1,
  386. title: "新增问卷题目",
  387. area: ['50%', '62%'],
  388. content: $("#questionHTML"),
  389. end: function(index, layero) {
  390. $(document).off("click", "#btnUpdateQuestion")
  391. contentHTML.style.display = 'none';
  392. },
  393. success: function(layero, index) {
  394. initNewQuestion();
  395. $("#addQuestionLayerIndex").val(index);
  396. $(document).on("click", "#btnUpdateQuestion", function() {
  397. let activityID = $("#curActivityID").val();;
  398. let order = $("#qOrder").val();
  399. let question = $("#qContent").val();
  400. let options = [];
  401. for (let i = 1; i <= totalOptionCount; ++i) {
  402. var td = $("#optRow" + i).children("td").eq(1);
  403. var optContent = td.find("input").val();
  404. options.push(optContent);
  405. }
  406. let answers = "";
  407. let isEmpty = true;
  408. if (curQuestionType == 1) {
  409. var tmp = []
  410. var idx = $("input[name='answerRadio']:checked").val();
  411. if (Number(idx) > 0) {
  412. tmp.push(Number(idx))
  413. answers = JSON.stringify(tmp)
  414. isEmpty = false;
  415. }
  416. } else {
  417. var chks = document.getElementsByName('answerCheckBox')
  418. var tmp = []
  419. for (let i = 0; i < chks.length; i++) {
  420. if (chks[i].checked == true) {
  421. tmp.push(i + 1)
  422. isEmpty = false;
  423. }
  424. }
  425. answers = JSON.stringify(tmp)
  426. }
  427. if (curQuestionType != 3 && (answers == "" || answers == null || isEmpty)) {
  428. layer.alert("正确答案未勾选");
  429. return;
  430. }
  431. $.ajax({
  432. type: 'post',
  433. dataType: "json",
  434. data: {
  435. activityID: activityID,
  436. order: order,
  437. type: curQuestionType,
  438. question: question,
  439. options: (curQuestionType == 3) ? "" : JSON.stringify(options),
  440. answers: (curQuestionType == 3) ? "" : answers,
  441. },
  442. url: "ajax.php?action=addQuestion",
  443. success: function(result) {
  444. if (result && result.code == 200) {
  445. console.log("添加成功");
  446. layui.table.reload('questionTable');
  447. let addQuestionLayerIndex = $("#addQuestionLayerIndex").val();
  448. layer.close(addQuestionLayerIndex);
  449. } else {
  450. layer.alert("添加失败");
  451. }
  452. },
  453. error: function(errMsg) {
  454. layer.alert("添加出错");
  455. }
  456. });
  457. });
  458. }
  459. });
  460. });
  461. $('input[type=radio][name=optionRadio]').change(function() {
  462. let type = $("input[name='optionRadio']:checked").val();
  463. updateTableByQuestionType(type, true);
  464. });
  465. let curQuestionType = 1;
  466. let totalOptionCount = 2;
  467. function initNewQuestion() {
  468. $("#qOrder").val(0);
  469. for (let i = 1; i <= 3; ++i) {
  470. $("input[name='optionRadio'][value='" + i + "']").prop("checked", (i == 1));
  471. }
  472. curQuestionType = 1;
  473. totalOptionCount = 2;
  474. $("#qContent").val("");
  475. var table = $("#optionsTable");
  476. table.children("tbody").remove();
  477. var text = '';
  478. for (let i = 1; i <= totalOptionCount; ++i) {
  479. text += '<tr id=optRow' + i + '><td width="10%"><label class="control-label">' + ("选项" + i) + '</label></td>'
  480. text += '<td><input type="text" class="form-control" id=' + ("qOptions" + i) + ' placeholder="输入选项内容" value=""></td>'
  481. text += '<td width=50></td></tr>'
  482. }
  483. table.append(text);
  484. generateAnswerContent();
  485. updateTableByQuestionType(curQuestionType);
  486. }
  487. function updateTableByQuestionType(type, genAnswer) {
  488. curQuestionType = type;
  489. var optionTR = $("#quOptions");
  490. var answerTR = $("#quAnswers");
  491. if (type == 3) {
  492. optionTR.hide();
  493. answerTR.hide();
  494. } else {
  495. optionTR.show();
  496. answerTR.show();
  497. if (genAnswer) {
  498. generateAnswerContent();
  499. }
  500. }
  501. }
  502. function addOpt() {
  503. if (totalOptionCount >= 8) {
  504. layer.alert("最多只支持8个选项")
  505. return;
  506. }
  507. totalOptionCount++;
  508. var table = $("#optionsTable");
  509. var text = '';
  510. text += '<tr id=optRow' + totalOptionCount + '><td width="10%"><label class="control-label">' + ("选项" + totalOptionCount) + '</label></td>'
  511. text += '<td><input type="text" class="form-control" id=' + ("qOptions" + totalOptionCount) + ' placeholder="输入选项内容" value=""></td>'
  512. if (totalOptionCount <= 2) {
  513. text += '<td width=50></td></tr>'
  514. } else {
  515. text += '<td width=50><a class="btn btn-info" onclick="delOpt(' + totalOptionCount + ')"><i class="glyphicon glyphicon-trash icon-white"></i></a></td></tr>'
  516. }
  517. table.append(text);
  518. generateAnswerContent();
  519. }
  520. function delOpt(optIndex) {
  521. if (totalOptionCount <= 2) {
  522. layer.alert("选择题最少需要保留2个选项")
  523. return;
  524. }
  525. var tr = $("#optRow" + optIndex);
  526. if (tr) {
  527. var optContentArray = [];
  528. for (let i = 1; i <= totalOptionCount; ++i) {
  529. if (optIndex == i) {
  530. continue;
  531. }
  532. var td = $("#optRow" + i).children("td").eq(1);
  533. var optContent = td.find("input").val();
  534. optContentArray.push(optContent);
  535. }
  536. tr.remove();
  537. totalOptionCount--;
  538. var table = $("#optionsTable");
  539. table.children("tbody").remove();
  540. var text = '';
  541. for (let i = 1; i <= totalOptionCount; ++i) {
  542. text += '<tr id=optRow' + i + '><td width="10%"><label class="control-label">' + ("选项" + i) + '</label></td>'
  543. text += '<td><input type="text" class="form-control" id=' + ("qOptions" + i) + ' placeholder="输入选项内容" value="' + optContentArray[i - 1] + '"></td>'
  544. if (i <= 2) {
  545. text += '<td width=50></td></tr>'
  546. } else {
  547. text += '<td width=50><a class="btn btn-info" onclick="delOpt(' + i + ')"><i class="glyphicon glyphicon-trash icon-white"></i></a></td></tr>'
  548. }
  549. }
  550. table.append(text);
  551. generateAnswerContent();
  552. }
  553. }
  554. function generateAnswerContent() {
  555. if (curQuestionType == 3) {
  556. return;
  557. }
  558. var answerTD = "";
  559. for (let i = 1; i <= totalOptionCount; ++i) {
  560. if (curQuestionType == 1) {
  561. answerTD += '<label class="radio-inline"><input type="radio" name="answerRadio" id="answerRadio' + i + '" value="' + i + '">选项' + i + '</label>'
  562. } else if (curQuestionType == 2) {
  563. answerTD += '<label class="checkbox-inline"><input type="checkbox" name="answerCheckBox" id="answerCheck' + i + '" value="' + i + '">选项' + i + '</label>'
  564. }
  565. }
  566. var td = $("#quAnswers").children("td").eq(1);
  567. td.html(answerTD);
  568. }
  569. function showQuestionList(data) {
  570. layui.use('table', function() {
  571. var table = layui.table;
  572. var contentHTML = document.getElementById("questionListHTML");
  573. layer.open({
  574. type: 1,
  575. title: "【" + data.activity_name + "】的题目列表",
  576. area: ['70%', '80%'],
  577. content: $("#questionListHTML"),
  578. end: function(index, layero) {
  579. contentHTML.style.display = 'none';
  580. },
  581. success: function(layero, index) {
  582. $("#curActivityID").val(data.id);
  583. table.render({
  584. elem: '#questionTable',
  585. url: './ajax.php?action=getQuestionList&activityID=' + data.id,
  586. page: true,
  587. limit: 30,
  588. cols: [
  589. [{
  590. field: 'id',
  591. title: '题目ID',
  592. width: 100,
  593. align: 'center'
  594. }, {
  595. field: 'order',
  596. title: '顺序值',
  597. width: 100,
  598. align: 'center'
  599. }, {
  600. field: 'type',
  601. title: '题目类型',
  602. width: 100,
  603. align: 'center',
  604. templet: function(d) {
  605. if (d.type == null) {
  606. return "";
  607. }
  608. let result = "";
  609. switch (parseInt(d.type)) {
  610. case 1:
  611. result = "单选";
  612. break;
  613. case 2:
  614. result = "多选";
  615. break;
  616. case 3:
  617. result = "问答";
  618. break;
  619. }
  620. return result;
  621. }
  622. }, {
  623. field: 'question',
  624. title: '题目内容',
  625. align: 'center'
  626. }, {
  627. field: 'options',
  628. title: '选项和答案',
  629. align: 'center',
  630. templet: function(d) {
  631. if (parseInt(d.type) == 3) {
  632. return "无";
  633. }
  634. if (!d.options) {
  635. return "";
  636. }
  637. let result = "";
  638. let options = JSON.parse(d.options);
  639. let answers = d.answer ? JSON.parse(d.answer) : [];
  640. let right = '<span class="label-success label label-default" style="margin-left:10px;margin-right:10px;"><i class="glyphicon glyphicon-ok "></i></span>'
  641. for (let i = 0; i < options.length; ++i) {
  642. let flag = ""
  643. for (let j = 0; j < answers.length; ++j) {
  644. if (answers[j] == (i + 1)) {
  645. flag = right
  646. break;
  647. }
  648. }
  649. result += "选项" + (i + 1) + ":" + options[i] + flag + "<br/>";
  650. }
  651. return result;
  652. }
  653. }, {
  654. title: '操作',
  655. width: 150,
  656. align: 'center',
  657. templet: function(d) {
  658. let edit = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="editQuestion(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >修改</button>';
  659. let del = '<button type="button" class="btn btn-primary" style="margin-right:5px;margin-top:5px;" onclick="delQuestion(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >删除</button>';
  660. return edit + del;
  661. }
  662. }]
  663. ]
  664. });
  665. }
  666. });
  667. });
  668. }
  669. function editQuestion(data) {
  670. var contentHTML = document.getElementById("questionHTML");
  671. var questionID = data.id;
  672. let activityID = data.activity_id;
  673. layui.use('table', function() {
  674. var table = layui.table;
  675. layer.open({
  676. type: 1,
  677. title: "修改题目:【ID:" + data.id + "】",
  678. area: ['50%', '62%'],
  679. content: $("#questionHTML"),
  680. end: function(index, layero) {
  681. $(document).off("click", "#btnUpdateQuestion")
  682. contentHTML.style.display = 'none';
  683. },
  684. success: function(layero, index) {
  685. $("#addQuestionLayerIndex").val(index);
  686. $("#qOrder").val(data.order);
  687. for (let i = 1; i <= 3; ++i) {
  688. $("input[name='optionRadio'][value='" + i + "']").prop("checked", (i == data.type));
  689. }
  690. curQuestionType = Number(data.type);
  691. let optionData = []
  692. if (data.options) {
  693. optionData = JSON.parse(data.options)
  694. totalOptionCount = optionData.length;
  695. } else {
  696. totalOptionCount = 0
  697. }
  698. $("#qContent").val(data.question);
  699. var table = $("#optionsTable");
  700. table.children("tbody").remove();
  701. var text = '';
  702. for (let i = 1; i <= totalOptionCount; ++i) {
  703. text += '<tr id=optRow' + i + '><td width="10%"><label class="control-label">' + ("选项" + i) + '</label></td>'
  704. text += '<td><input type="text" class="form-control" id=' + ("qOptions" + i) + ' placeholder="输入选项内容" value="' + optionData[i - 1] + '"></td>'
  705. if (i <= 2) {
  706. text += '<td width=50></td></tr>'
  707. } else {
  708. text += '<td width=50><a class="btn btn-info" onclick="delOpt(' + i + ')"><i class="glyphicon glyphicon-trash icon-white"></i></a></td></tr>'
  709. }
  710. }
  711. table.append(text);
  712. var answerTD = "";
  713. for (let i = 1; i <= totalOptionCount; ++i) {
  714. if (curQuestionType == 1) {
  715. answerTD += '<label class="radio-inline"><input type="radio" name="answerRadio" id="answerRadio' + i + '" value="' + i + '">选项' + i + '</label>'
  716. } else if (curQuestionType == 2) {
  717. answerTD += '<label class="checkbox-inline"><input type="checkbox" name="answerCheckBox" id="answerCheck' + i + '" value="' + i + '">选项' + i + '</label>'
  718. }
  719. }
  720. var td = $("#quAnswers").children("td").eq(1);
  721. td.html(answerTD);
  722. let answerData = []
  723. if (data.answer) {
  724. answerData = JSON.parse(data.answer)
  725. }
  726. for (let i = 0; i < answerData.length; ++i) {
  727. let opt = answerData[i]
  728. if (curQuestionType == 1) {
  729. $("input[name='answerRadio'][value='" + opt + "']").prop("checked", true);
  730. } else {
  731. $("input[name='answerCheckBox'][value='" + opt + "']").prop("checked", true);
  732. }
  733. }
  734. updateTableByQuestionType(curQuestionType);
  735. $(document).on("click", "#btnUpdateQuestion", function() {
  736. let order = $("#qOrder").val();
  737. let question = $("#qContent").val();
  738. let options = [];
  739. for (let i = 1; i <= totalOptionCount; ++i) {
  740. var td = $("#optRow" + i).children("td").eq(1);
  741. var optContent = td.find("input").val();
  742. options.push(optContent);
  743. }
  744. let answers = "";
  745. let isEmpty = true;
  746. if (curQuestionType == 1) {
  747. var tmp = []
  748. var idx = $("input[name='answerRadio']:checked").val();
  749. if (Number(idx) > 0) {
  750. tmp.push(Number(idx))
  751. answers = JSON.stringify(tmp)
  752. isEmpty = false;
  753. }
  754. } else {
  755. var chks = document.getElementsByName('answerCheckBox')
  756. var tmp = []
  757. for (let i = 0; i < chks.length; i++) {
  758. if (chks[i].checked == true) {
  759. tmp.push(i + 1)
  760. isEmpty = false;
  761. }
  762. }
  763. answers = JSON.stringify(tmp)
  764. }
  765. if (curQuestionType != 3 && (answers == "" || answers == null || isEmpty)) {
  766. layer.alert("正确答案未勾选");
  767. return;
  768. }
  769. $.ajax({
  770. type: 'post',
  771. dataType: "json",
  772. data: {
  773. questionID: questionID,
  774. activityID: activityID,
  775. order: order,
  776. type: curQuestionType,
  777. question: question,
  778. options: (curQuestionType == 3) ? "" : JSON.stringify(options),
  779. answers: (curQuestionType == 3) ? "" : answers,
  780. },
  781. url: "ajax.php?action=modifyQuestion",
  782. success: function(result) {
  783. if (result && result.code == 200) {
  784. console.log("修改成功");
  785. layui.table.reload('questionTable');
  786. let addQuestionLayerIndex = $("#addQuestionLayerIndex").val();
  787. layer.close(addQuestionLayerIndex);
  788. } else {
  789. layer.alert("修改失败");
  790. }
  791. },
  792. error: function(errMsg) {
  793. layer.alert("修改出错");
  794. }
  795. });
  796. });
  797. }
  798. });
  799. });
  800. }
  801. function delQuestion(data) {
  802. layer.open({
  803. content: "确定要刪除题目ID【" + data.id + "】的题目吗?",
  804. btn: ['确定', '取消'],
  805. yes: function(index, layero) {
  806. //确定的回调
  807. $.ajax({
  808. type: 'post',
  809. dataType: "json",
  810. data: {
  811. questionID: data.id
  812. },
  813. url: "ajax.php?action=delQuestion",
  814. success: function(result) {
  815. if (result && result.code == 200) {
  816. console.log("删除成功");
  817. layui.table.reload('questionTable');
  818. layer.close(index);
  819. } else {
  820. layer.alert("删除失败");
  821. }
  822. },
  823. error: function(errMsg) {
  824. layer.alert("删除出错");
  825. }
  826. });
  827. },
  828. btn2: function(index, layero) {
  829. //取消的回调
  830. }
  831. ,
  832. cancel: function() {
  833. //右上角关闭回调
  834. }
  835. });
  836. }
  837. $(document).on("click", "#btnExport", function() {
  838. let curActivityID = $("#curActivityID").val();
  839. //window.location.href = "ajax.php?action=export&activityID=" + curActivityID
  840. var loading = layer.load(1, {
  841. shade: [0.5, '#000'],
  842. time: 10*1000
  843. });
  844. $.ajax({
  845. dataType: "json",
  846. url: "ajax.php?action=getallusers&activityID=" + curActivityID,
  847. success: function(result) {
  848. if (result && result.code == 200) {
  849. console.log("导出成功");
  850. let data = [];
  851. for(let i = 0; i < result.data.length; ++i)
  852. {
  853. let itemData = result.data[i];
  854. let optResult = "";
  855. if(itemData.options)
  856. {
  857. let opts = itemData.options.substr(0, itemData.options.length - 1);
  858. let answers = opts.split(";");
  859. for (let i = 0; i < answers.length; ++i) {
  860. var info = answers[i];
  861. info = info.replace(/[,]/g, "_");
  862. var info = info == "" ? "未选择" : info;
  863. optResult += "第" + (i + 1) + "题:" + info;
  864. if(i != answers.length - 1)
  865. {
  866. optResult += " "
  867. }
  868. }
  869. }
  870. data.push([itemData.user_id, itemData.user_name, itemData.user_number, itemData.um, optResult, itemData.custom_input, itemData.prize])
  871. }
  872. layui.table.exportFile(['用户ID', '员工姓名', '员工工号', 'UM号', '选择题', '问答题', '中奖奖品ID'], data, 'csv', '用户列表');
  873. layer.close(loading);
  874. } else {
  875. layer.close(loading);
  876. layer.alert("导出失败");
  877. }
  878. },
  879. error: function(errMsg) {
  880. layer.close(loading);
  881. layer.alert("导出错误");
  882. }
  883. });
  884. });
  885. function showUserList(data) {
  886. layui.use('table', function() {
  887. var table = layui.table;
  888. var contentHTML = document.getElementById("userListHTML");
  889. layer.open({
  890. type: 1,
  891. title: "参与【" + data.activity_name + "】的用户列表",
  892. area: ['70%', '80%'],
  893. content: $("#userListHTML"),
  894. end: function(index, layero) {
  895. contentHTML.style.display = 'none';
  896. },
  897. success: function(layero, index) {
  898. $("#curActivityID").val(data.id);
  899. table.render({
  900. elem: '#userTable',
  901. url: './ajax.php?action=userinfo&activityID=' + data.id,
  902. page: true,
  903. //toolbar:true,
  904. //defaultToolbar: ['exports'],
  905. limit: 30,
  906. cols: [
  907. [{
  908. field: 'user_id',
  909. title: '用户ID',
  910. align: 'center'
  911. }, {
  912. field: 'user_name',
  913. title: '员工姓名',
  914. align: 'center'
  915. }, {
  916. field: 'user_number',
  917. title: '员工工号',
  918. align: 'center'
  919. }, {
  920. field: 'um',
  921. title: 'UM号',
  922. align: 'center'
  923. }, {
  924. field: 'options',
  925. title: '选择题',
  926. align: 'center',
  927. templet: function(d) {
  928. if (d.options == null) {
  929. return "";
  930. }
  931. if(d.options.charAt(d.options.length - 1) == ";")
  932. {
  933. d.options = d.options.substr(0, d.options.length - 1);
  934. }
  935. let answers = d.options.split(";");
  936. let result = "";
  937. for (let i = 0; i < answers.length; ++i) {
  938. var info = answers[i];
  939. var info = info == "" ? "未选择" : info;
  940. result += "第" + (i + 1) + "题:" + info + "<br/>";
  941. }
  942. return result;
  943. }
  944. }, {
  945. field: 'custom_input',
  946. title: '问答题',
  947. align: 'center'
  948. }, {
  949. field: 'prize',
  950. title: '中奖奖品',
  951. align: 'center'
  952. }]
  953. ]
  954. });
  955. }
  956. });
  957. });
  958. }
  959. function del(data) {
  960. layer.open({
  961. content: "确定要刪除活动【" + data.activity_name + "】吗?",
  962. btn: ['确定', '取消'],
  963. yes: function(index, layero) {
  964. //确定的回调
  965. $.ajax({
  966. type: 'post',
  967. dataType: "json",
  968. data: {
  969. activityID: data.id
  970. },
  971. url: "ajax.php?action=delActivity",
  972. success: function(result) {
  973. if (result && result.code == 200) {
  974. console.log("删除成功");
  975. window.location.reload();;
  976. } else {
  977. layer.alert("删除失败");
  978. }
  979. },
  980. error: function(errMsg) {
  981. layer.alert("删除出错");
  982. }
  983. });
  984. },
  985. btn2: function(index, layero) {
  986. //取消的回调
  987. }
  988. ,
  989. cancel: function() {
  990. //右上角关闭回调
  991. }
  992. });
  993. }
  994. function showPrizeList(data) {
  995. layui.use('table', function() {
  996. var table = layui.table;
  997. var contentHTML = document.getElementById("prizeListHTML");
  998. var activityID = data.id
  999. layer.open({
  1000. type: 1,
  1001. title: "【" + data.activity_name + "】的奖品列表",
  1002. area: ['70%', '70%'],
  1003. content: $("#prizeListHTML"),
  1004. end: function(index, layero) {
  1005. contentHTML.style.display = 'none';
  1006. },
  1007. success: function(layero, index) {
  1008. table.render({
  1009. elem: '#prizeTable',
  1010. url: './ajax.php?action=prizeConfig&activityID=' + activityID,
  1011. cols: [
  1012. [{
  1013. field: 'order',
  1014. title: '转盘位置',
  1015. width: '8%',
  1016. align: 'center'
  1017. }, {
  1018. field: 'prize_type',
  1019. title: '奖项名字',
  1020. align: 'center'
  1021. }, {
  1022. field: 'prize_name',
  1023. title: '奖品名字',
  1024. align: 'center'
  1025. }, {
  1026. field: 'prize_img',
  1027. title: '奖品图片',
  1028. align: 'center',
  1029. templet: function(d) {
  1030. //d.prize_img = "https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64"
  1031. d.activityID = activityID
  1032. d.type = 'prize'
  1033. let btnDel = '<button type="button" id="btnDel' + d.id + '" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" onclick="delImg(' + JSON.stringify(d).replace(/"/g, '&quot;') + ', 0);" ><i class="layui-icon">&#x1006;</i></button>';
  1034. let btnUp = '<button type="button" class="btn btn-primary" style="margin-left:5px;margin-top:5px;" id="btnUpImage' + d.id + '"><i class="layui-icon">&#xe67c;</i></button>'
  1035. let imgURL = d.prize_img ? ('<?php echo URL_FOR_SAVE_PATH; ?>' + d.prize_img) : '""'
  1036. let imgPrev = '<img onclick="showPrizeImg(this)" src=' + imgURL + ' id=prize_img_' + d.id + '>'
  1037. if(d.prize_img != null && d.prize_img.length > 0)
  1038. {
  1039. return imgPrev + btnUp + btnDel
  1040. }
  1041. return imgPrev + btnUp
  1042. }
  1043. }, {
  1044. field: 'prize_rate',
  1045. title: '抽中概率',
  1046. width: '8%',
  1047. align: 'center',
  1048. templet: function(d) {
  1049. return d.prize_rate + '%'
  1050. }
  1051. }, {
  1052. field: 'sum',
  1053. title: '奖品总数',
  1054. width: '8%',
  1055. align: 'center'
  1056. }, {
  1057. field: 'cur',
  1058. title: '抽中数量',
  1059. width: '8%',
  1060. align: 'center'
  1061. }, {
  1062. title: '操作',
  1063. width: '8%',
  1064. align: 'center',
  1065. templet: function(d) {
  1066. return '<button type="button" class="btn btn-primary" onclick="editPrize(' + JSON.stringify(d).replace(/"/g, '&quot;') + ');" >修改</button>';
  1067. }
  1068. }]
  1069. ],
  1070. done:function(res, curr, count){
  1071. for(let i = 0; i < res.data.length; ++i)
  1072. {
  1073. let itemData = res.data[i];
  1074. uploadImg(activityID, itemData.id)
  1075. }
  1076. }
  1077. });
  1078. }
  1079. });
  1080. });
  1081. }
  1082. function uploadImg(activityID, itemID){
  1083. layui.use('upload', function(){
  1084. var upload = layui.upload;
  1085. var upInst = upload.render({
  1086. elem: '#btnUpImage' + itemID
  1087. ,url: "ajax.php?action=uploadImg"
  1088. ,data:{id:itemID, activityID:activityID, type:'prize', img:""}
  1089. ,acceptMime: 'image/png'
  1090. ,auto:true
  1091. ,field:"prizeImg"
  1092. /*,choose:function(obj){
  1093. //预读本地文件,如果是多文件,则会遍历。(不支持ie8/9)
  1094. obj.preview(function(index, file, result){
  1095. console.log(index); //得到文件索引
  1096. console.log(file); //得到文件对象
  1097. console.log(result); //得到文件base64编码,比如图片
  1098. let img = new Image()
  1099. img.src = result
  1100. img.onload = function(){
  1101. if(img.width != 70 && img.height != 70)
  1102. {
  1103. layer.alert("奖品图片的长宽像素必须为70")
  1104. return false
  1105. }
  1106. else{
  1107. obj.upload(index, file)
  1108. }
  1109. }
  1110. //obj.resetFile(index, file, '123.jpg'); //重命名文件名,layui 2.3.0 开始新增
  1111. //这里还可以做一些 append 文件列表 DOM 的操作
  1112. //obj.upload(index, file); //对上传失败的单个文件重新上传,一般在某个事件中使用
  1113. //delete files[index]; //删除列表中对应的文件,一般在某个事件中使用
  1114. });
  1115. }*/
  1116. ,done: function(res){
  1117. if(res.code == 200)
  1118. {
  1119. //$('#prize_img_' + itemID).attr("src", res.url)
  1120. layer.msg('上传成功');
  1121. layui.table.reload('prizeTable');
  1122. }
  1123. else{
  1124. layer.alert(res.msg);
  1125. }
  1126. }
  1127. });
  1128. });
  1129. }
  1130. function uploadActImg(activityID, tag, imgType)
  1131. {
  1132. layui.use('upload', function(){
  1133. var upload = layui.upload;
  1134. var upInst = upload.render({
  1135. elem: '#' + tag
  1136. ,url: "ajax.php?action=uploadImg"
  1137. ,data:{id:activityID, activityID:activityID, type:'act', img:imgType}
  1138. ,acceptMime: 'image/png'
  1139. ,auto:true
  1140. ,field:"prizeImg"
  1141. ,done: function(res){
  1142. if(res.code == 200)
  1143. {
  1144. layer.msg('上传成功');
  1145. layui.table.reload('activityTable');
  1146. }
  1147. else{
  1148. layer.alert(res.msg);
  1149. }
  1150. }
  1151. });
  1152. });
  1153. }
  1154. function showPrizeImg(t) {
  1155. //var t = $(t).find("img");
  1156. //页面层
  1157. layer.open({
  1158. type: 1,
  1159. skin: 'layui-layer-rim', //加上边框
  1160. area: ['500px', '500px'], //宽高 t.width() t.height()
  1161. shadeClose: true, //开启遮罩关闭
  1162. end: function (index, layero) {
  1163. return false;
  1164. },
  1165. content: '<div style="text-align:center"><img src="' + $(t).attr('src') + '" + " width="50%" height="50%"/></div>'
  1166. });
  1167. }
  1168. function delImg(data, idx){
  1169. let type = data.type
  1170. let itemID = data.id
  1171. let activityID = data.activityID
  1172. let imgIdx = idx
  1173. $.ajax({
  1174. type: 'post',
  1175. dataType: "json",
  1176. data: {
  1177. itemID: itemID,
  1178. activityID:activityID,
  1179. type:type,
  1180. imgIdx:imgIdx
  1181. },
  1182. url: "ajax.php?action=delImg",
  1183. success: function(result) {
  1184. if (result && result.code == 200) {
  1185. if(type == 'prize')
  1186. {
  1187. layui.table.reload('prizeTable');
  1188. }
  1189. else{
  1190. layui.table.reload('activityTable');
  1191. }
  1192. } else {
  1193. layer.alert("删除失败");
  1194. }
  1195. },
  1196. error: function(errMsg) {
  1197. layer.alert("修改失败");
  1198. }
  1199. });
  1200. }
  1201. function editPrize(data) {
  1202. var contentHTML = document.getElementById("modifyRateHTML");
  1203. layui.use('table', function() {
  1204. var table = layui.table;
  1205. layer.open({
  1206. type: 1,
  1207. title: "修改奖品信息:【ID:" + data.id + "】" + data.prize_name,
  1208. area: ['400px', '430px'],
  1209. content: $("#modifyRateHTML"),
  1210. end: function(index, layero) {
  1211. $(document).off("click", "#btnUpdatePrize")
  1212. contentHTML.style.display = 'none';
  1213. },
  1214. success: function(layero, index) {
  1215. $("#txtType").val(data.prize_type);
  1216. $("#txtPrizeName").val(data.prize_name);
  1217. $("#txtSum").val(data.sum);
  1218. $("#txtRate").val(data.prize_rate);
  1219. $(document).on("click", "#btnUpdatePrize", function() {
  1220. var sum = $("#txtSum").val();
  1221. var rate = $("#txtRate").val();
  1222. rate = Number(rate).toFixed(2);
  1223. var type = $("#txtType").val();
  1224. var name = $("#txtPrizeName").val();
  1225. $.ajax({
  1226. type: 'post',
  1227. dataType: "json",
  1228. data: {
  1229. itemID: data.id,
  1230. type: type,
  1231. name: name,
  1232. sum: sum,
  1233. rate: rate
  1234. },
  1235. url: "ajax.php?action=modifyItem",
  1236. success: function(result) {
  1237. if (result && result.code == 200) {
  1238. console.log("修改成功");
  1239. table.reload('prizeTable');
  1240. layer.close(index);
  1241. contentHTML.style.display = 'none';
  1242. } else {
  1243. layer.alert("修改失败");
  1244. }
  1245. },
  1246. error: function(errMsg) {
  1247. layer.alert("修改失败");
  1248. }
  1249. });
  1250. });
  1251. }
  1252. });
  1253. });
  1254. }
  1255. function resetData(data) {
  1256. var contentHTML = document.getElementById("resetDataHTML");
  1257. layer.open({
  1258. type: 1,
  1259. title: "重置【" + data.activity_name + "】的数据",
  1260. area: ['500px', '260px'],
  1261. content: $("#resetDataHTML"),
  1262. end: function(index, layero) {
  1263. contentHTML.style.display = 'none';
  1264. },
  1265. success: function(layero, index) {
  1266. $("#resetID").val(data.id);
  1267. $("#resetLayerIndex").val(index);
  1268. }
  1269. });
  1270. }
  1271. function onClickReset() {
  1272. layui.use('layer', function() {
  1273. let resetID = $("#resetID").val();
  1274. let resetLayerIndex = $("#resetLayerIndex").val();
  1275. layer.open({
  1276. content: '确定要重置数据吗?',
  1277. btn: ['确定', '取消'],
  1278. yes: function(index, layero) {
  1279. //确定的回调
  1280. $.ajax({
  1281. type: 'post',
  1282. url: "ajax.php?action=resetdata&activityID=" + resetID,
  1283. success: function(result) {
  1284. if (result && result.code == 200) {
  1285. layer.close(index);
  1286. parent.layer.close(resetLayerIndex);
  1287. layer.alert("重置成功");
  1288. } else {
  1289. layer.alert("重置失败");
  1290. }
  1291. },
  1292. error: function(errMsg) {
  1293. layer.alert("重置失败");
  1294. }
  1295. });
  1296. },
  1297. btn2: function(index, layero) {
  1298. //取消的回调
  1299. }
  1300. ,
  1301. cancel: function() {
  1302. //右上角关闭回调
  1303. }
  1304. });
  1305. });
  1306. }
  1307. </script>
  1308. <?php require_once('footer.php'); ?>