rollaward.tpl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>欢迎页面-X-admin2.0</title>
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  7. <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  8. <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  9. <link rel="stylesheet" href="./static/css/font.css">
  10. <link rel="stylesheet" href="./static/css/xadmin.css">
  11. <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  12. <script src="./static/lib/layui/layui.js" charset="utf-8"></script>
  13. <script type="text/javascript" src="./static/js/xadmin.js"></script>
  14. </head>
  15. <body onload="InitParams({{.ItemList}})">
  16. <input type="text" id="token" value={{.token}} hidden=true>
  17. <dialog open id="modalAdd" class="x-body layui-anim layui-anim-up" hidden=true style = "center;">
  18. <form action="rollaward" method="post" class="layui-form layui-form-pane">
  19. 物品列表
  20. <table class="radio-table" border="1" id="tb_item">
  21. <thead>
  22. <th style="width:100px;">物品</th>
  23. <th style="width:100px;">价值</th>
  24. <th style="width:256px;">操作</th>
  25. </thead>
  26. </table>
  27. <br>
  28. <input class="layui-btn" type="button" onclick="modalAddItem()" value=新增道具>
  29. <hr class="hr15">
  30. <input value="新增" class="layui-btn" style="width:100%;" type="button" onclick="addRollAward()">
  31. <br>
  32. <br>
  33. <input value="关闭" class="layui-btn" style="width:100%;" type="button" onclick="closeModalAdd()">
  34. <hr class="hr20" >
  35. </form>
  36. </dialog>
  37. <dialog open id="modalModify" class="x-body layui-anim layui-anim-up" hidden=true style = "center;">
  38. <form action="rollaward" method="put" class="layui-form layui-form-pane">
  39. <input id="id_modify" hidden=true type="text">
  40. 随机物品列表
  41. <table class="radio-table" border="1" id="tb_item_modify">
  42. <thead>
  43. <th style="width:100px;">物品</th>
  44. <th style="width:100px;">价值</th>
  45. <th style="width:256px;">操作</th>
  46. </thead>
  47. </table>
  48. <br>
  49. <input class="layui-btn" type="button" onclick="modalAddItem()" value=新增道具>
  50. <hr class="hr15">
  51. <input value="修改" class="layui-btn" style="width:100%;" type="button" onclick="modifyRollAward()">
  52. <br>
  53. <br>
  54. <input value="关闭" class="layui-btn" style="width:100%;" type="button" onclick="closeModalModify()">
  55. <hr class="hr20" >
  56. </form>
  57. </dialog>
  58. <dialog open id="modalItem" class="x-body layui-anim layui-anim-up" hidden=true style="center;width:512px;">
  59. <form class="layui-form layui-form-pane">
  60. <input id="item_id" name="item_id" placeholder="道具ID" type="text" lay-verify="required" class="layui-input">
  61. <hr class="hr15">
  62. <input id="btn" value="新增" class="layui-btn" style="width:64px;" type="button" onclick="addItem()">
  63. <br>
  64. <br>
  65. <input value="关闭" class="layui-btn" style="width:64px;" type="button" onclick="closeModalItem()">
  66. <hr class="hr20" >
  67. </form>
  68. </dialog>
  69. <div class="x-body layui-anim layui-anim-up">
  70. <blockquote class="layui-elem-quote">
  71. <input class="layui-btn" type="button" onclick="OpenAddItem()" value=新增>
  72. <input class="layui-btn" type="button" onclick="Refresh()" value=刷新>
  73. </blockquote>
  74. </div>
  75. <table class="radio-table" border="1">
  76. <thead>
  77. <th style="width:256px;">操作</th>
  78. <th style="width:64px;">ID</th>
  79. <th style="width:1024px;">奖励列表</th>
  80. </thead>
  81. <tbody>
  82. {{range .infoList}}
  83. <tr>
  84. <td style = "text-align:center;">
  85. <input class="layui-btn" type="button" onclick="OpenModifyItem({{.Id}}, {{.ItemIdList}})" value=修改>
  86. {{" | "}}
  87. <input class="layui-btn" type="button" onclick="clickDelete({{.Id}})" value=删除>
  88. </td>
  89. <td style = "text-align:center;">{{.Id}}</td>
  90. <td style = "text-align:center;">{{BeegoItemNameList .ItemIdList}}</td>
  91. </tr>
  92. {{end}}
  93. </tbody>
  94. </table>
  95. <script language="JavaScript">
  96. var isModelAdd = true
  97. var _ItemList = [];
  98. var addSelectIndex = 0;
  99. var awardItemIdList = [];
  100. function InitParams(itemList) {
  101. console.log("InitParams");
  102. _ItemList = itemList;
  103. // UpdateSelectItems()
  104. }
  105. // 更新select控件
  106. function UpdateSelectItems() {
  107. var itemDialog = document.getElementById("modalItem")
  108. var obj = itemDialog.querySelector("#item_id")
  109. console.info("UpdateSelectItems options:" + obj.length)
  110. var maxItemsIndex = _ItemList.length - 1
  111. var startIndex = addSelectIndex
  112. var endIndex = addSelectIndex + 10
  113. if (endIndex > maxItemsIndex) {
  114. endIndex = maxItemsIndex
  115. }
  116. for (var i = startIndex; i <= endIndex; i ++) {
  117. if (i > maxItemsIndex) {
  118. break
  119. }
  120. var id = _ItemList[i].id
  121. var name = _ItemList[i].name + "(" + getItemPrice(id) +")"
  122. console.log("modalAddItem index:"+i+" name:"+name+" id:"+id)
  123. obj.add(new Option(name, id))
  124. // obj.options[obj.length] = new Option(name, id)
  125. // obj.options[obj.length].style = 'display:list-item';
  126. addSelectIndex += 1
  127. }
  128. obj.options[0].selected = true;
  129. console.info("UpdateSelectItems options:" + obj.length)
  130. }
  131. function gradeItemChange(itemId) {
  132. console.info("gradeItemChange itemId:" + itemId)
  133. }
  134. // 道具名称
  135. function getItemName(itemId) {
  136. var id = parseInt(itemId)
  137. for (var i = 0; i < _ItemList.length; i ++){
  138. if (_ItemList[i].id == id){
  139. return _ItemList[i].name
  140. }
  141. }
  142. return ""
  143. }
  144. // 道具价格
  145. function getItemPrice(itemId) {
  146. var id = parseInt(itemId)
  147. for (var i = 0; i < _ItemList.length; i ++){
  148. if (_ItemList[i].id == id){
  149. return _ItemList[i].price
  150. }
  151. }
  152. return ""
  153. }
  154. // 刷新物品列表
  155. function refreshTableItem() {
  156. var key = "tb_item"
  157. if (isModelAdd == false){key = "tb_item_modify"}
  158. var obj = document.getElementById(key)
  159. var tbody = obj.getElementsByTagName("tbody")[0];
  160. if (tbody) {
  161. if (-[1,]) {
  162. obj.removeChild(tbody);
  163. }else{
  164. obj.removeNode(tbody);
  165. }
  166. }
  167. for (var i = 0; i < awardItemIdList.length; i ++){
  168. console.info("refreshTableItem awardItemId:"+awardItemIdList[i])
  169. }
  170. if (awardItemIdList.length > 0 && awardItemIdList[0] != "") {
  171. tbody = document.createElement("tbody")
  172. for (var i = 0; i < awardItemIdList.length; i++){
  173. var tr = document.createElement("tr")
  174. var td1 = document.createElement("td")
  175. td1.style = "text-align:center;"
  176. td1.innerHTML = getItemName(awardItemIdList[i])
  177. tr.appendChild(td1)
  178. var td2 = document.createElement("td")
  179. td2.style = "text-align:center;"
  180. td2.innerHTML = getItemPrice(awardItemIdList[i])
  181. tr.appendChild(td2)
  182. var td4 = document.createElement("td")
  183. td4.style = "text-align:center;"
  184. td4.innerHTML = '<input class="layui-btn" type="button" onclick="itemDelete(' + awardItemIdList[i] + ')" value=删除>'
  185. tr.appendChild(td4)
  186. tbody.appendChild(tr)
  187. }
  188. obj.appendChild(tbody)
  189. }
  190. }
  191. // 物品弹窗
  192. function modalAddItem() {
  193. refreshTableItem()
  194. // UpdateSelectItems()
  195. document.getElementById("modalItem").hidden = false;
  196. }
  197. function closeModalItem() {
  198. document.getElementById("modalItem").hidden = true;
  199. }
  200. function addItem() {
  201. var item_id = parseInt(document.getElementById("item_id").value);
  202. if (item_id == null || item_id == 0){
  203. alert("请选择道具");
  204. return;
  205. }
  206. var itemName = getItemName(item_id)
  207. if (itemName == ""){
  208. alert("该道具未配置");
  209. return;
  210. }
  211. awardItemIdList.push(item_id)
  212. refreshTableItem()
  213. document.getElementById("modalItem").hidden = true;
  214. }
  215. // 删除物品
  216. function itemDelete(itemId) {
  217. var id = parseInt(itemId)
  218. console.log("itemDelete itemId:" + itemId)
  219. for (var i = 0; i < awardItemIdList.length; i ++) {
  220. if (awardItemIdList[i] == id) {
  221. console.log("itemDelete 找到道具")
  222. awardItemIdList.splice(i, 1)
  223. break
  224. }
  225. }
  226. refreshTableItem()
  227. document.getElementById("modalItem").hidden = true;
  228. }
  229. function OpenAddItem() {
  230. isModelAdd = true
  231. document.getElementById("modalAdd").hidden = false;
  232. }
  233. function closeModalAdd() {
  234. document.getElementById("modalAdd").hidden = true;
  235. }
  236. function addRollAward () {
  237. var token = document.getElementById("token").value;
  238. if (awardItemIdList.length <= 0){
  239. alert("奖励物品空!");
  240. return;
  241. }
  242. var text = "token=" + encodeURI(token);
  243. text += "&items=" + encodeURI(JSON.stringify(awardItemIdList));
  244. $.ajax({
  245. type:"post",
  246. url:"/rollaward?" + text,
  247. success:function (data) {
  248. // alert(data.status);
  249. if (data.status){
  250. window.location.href="/rollaward";
  251. }else{
  252. if (data.info){
  253. alert(data.info);
  254. }else{
  255. window.location.href="/accountlogin";
  256. }
  257. }
  258. }
  259. });
  260. }
  261. function closeModalItem() {
  262. document.getElementById("modalItem").hidden = true;
  263. }
  264. function OpenModifyItem(id, itemIdList) {
  265. isModelAdd = false;
  266. awardItemIdList = []
  267. for (var i = 0; i < itemIdList.length; i ++) {
  268. awardItemIdList.push(itemIdList[i]);
  269. }
  270. document.getElementById("id_modify").value = id;
  271. refreshTableItem()
  272. document.getElementById("modalModify").hidden = false;
  273. }
  274. function closeModalModify() {
  275. document.getElementById("modalModify").hidden = true;
  276. }
  277. function modifyRollAward () {
  278. var token = document.getElementById("token").value;
  279. var id = document.getElementById("id_modify").value;
  280. if (awardItemIdList.length <= 0){
  281. alert("奖励物品空!");
  282. return;
  283. }
  284. var text = "token=" + encodeURI(token);
  285. text += "&id=" + encodeURI(id);
  286. text += "&items=" + encodeURI(JSON.stringify(awardItemIdList));
  287. $.ajax({
  288. type:"put",
  289. url:"/rollaward?" + text,
  290. success:function (data) {
  291. // alert(data.status);
  292. if (data.status){
  293. window.location.href="/rollaward";
  294. }else{
  295. if (data.info){
  296. alert(data.info);
  297. }else{
  298. window.location.href="/accountlogin";
  299. }
  300. }
  301. }
  302. });
  303. }
  304. function clickDelete (pcode) {
  305. var token = document.getElementById("token").value;
  306. var text = "token=" + encodeURI(token);
  307. text += "&pcode=" + encodeURI(pcode);
  308. $.ajax({
  309. type:"delete",
  310. url:"/rollaward?" + text,
  311. success:function (data) {
  312. // alert(data.status);
  313. if (data.status){
  314. window.location.href="/rollaward";
  315. }else{
  316. if (data.info){
  317. alert(data.info);
  318. }else{
  319. window.location.href="/accountlogin";
  320. }
  321. }
  322. }
  323. });
  324. }
  325. </script>
  326. </body>
  327. </html>