number.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. layui.use(['laypage', 'layer', 'table', 'element', 'form', 'upload'], function () {
  2. var laypage = layui.laypage //分页
  3. , $ = layui.jquery
  4. , layer = layui.layer //弹层
  5. , table = layui.table //表格
  6. , element = layui.element //元素操作
  7. , form = layui.form
  8. , upload = layui.upload;
  9. var tableIds = 'list'; //表格ID
  10. //第一个实例
  11. table.render({
  12. elem: '#' + tableIds
  13. , url: '/testnumber/indexform' //数据接口
  14. , where: {token: csrfToken}
  15. , method: 'post'
  16. , page: true //开启分页
  17. , text: '数据加载中'
  18. , id: 'tablerReload'
  19. , limit: 20
  20. , cols: [[ //表头
  21. {type: 'numbers', title: '序号', width: 50},
  22. {field: 'number', title: '测试号码', align: 'center'},
  23. {field: 'explain', title: '号码说明', align: 'center'},
  24. {field: 'create_at', title: '添加时间', width: 180, align: 'center'},
  25. {
  26. field: 'is_show', title: '审核', align: 'center', width: 100, templet: function (d) {
  27. if (d.is_show == 2) {
  28. return '<input type="checkbox" value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  29. } else {
  30. return '<input type="checkbox" checked value="' + d.id + '" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="|">'
  31. }
  32. }
  33. },
  34. {fixed: 'right', title: '操作', width: 300, align: 'center', toolbar: '#operate'}
  35. ]]
  36. });
  37. //监听指定开关
  38. form.on('switch(switchTest)', function (data) {
  39. layer.confirm('确定要修改此操作吗?', {btn: ['确定', '取消']}, function () {
  40. $.post('/testnumber/setnumber', {id: data.value, type: 'show'}, function (data) {
  41. layer.msg(data.msg);
  42. table.reload('tablerReload');
  43. })
  44. }, function (aa) {
  45. table.reload('tablerReload'); //重新加载
  46. })
  47. });
  48. //列表操作
  49. table.on('tool(' + tableIds + ')', function (obj) {
  50. var layEvent = obj.event,
  51. data = obj.data;
  52. if (layEvent === 'del') {
  53. layer.confirm('您确定要删除该号码吗?', {btn: ['确定', '取消']}, function () {
  54. $.post('/testnumber/setnumber', {id: data.id, type: 'del'}, function (data) {
  55. layer.msg(data.msg);
  56. table.reload('tablerReload');
  57. })
  58. })
  59. } else if (layEvent === 'edit') {
  60. var index = layer.open({
  61. type: 2,
  62. title: '编辑测试号码',
  63. area: ['50%', '50%'],
  64. content: '/testnumber/edit?id=' + data.id,
  65. end: function () {
  66. table.reload('tablerReload'); //重新加载
  67. }
  68. });
  69. }
  70. });
  71. // 新增
  72. var $ = layui.$, active = {
  73. addData: function () { //获取选中数据
  74. var index = layui.layer.open({
  75. type: 2,
  76. title: '新增测试号码',
  77. closeBtn: 1, //不显示关闭按钮
  78. area: ['50%', '50%'],
  79. content: '/testnumber/add' //iframe的url,no代表不显示滚动条
  80. , success: function (layero, index) {
  81. },
  82. end: function () {
  83. table.reload('tablerReload');
  84. }
  85. });
  86. },
  87. reload: function () {//搜索
  88. var form = pfgs_serialize($('form'));
  89. var name = '';
  90. table.reload('tablerReload', {
  91. where: {
  92. number: form.input_number_text,
  93. },
  94. page: {
  95. curr: 1
  96. }
  97. })
  98. },
  99. };
  100. $('.demoTable .layui-btn').on('click', function () {
  101. var type = $(this).data('type');
  102. active[type] ? active[type].call(this) : '';
  103. });
  104. //添加页面提交数据
  105. form.on('submit(add_number)', function (data) {
  106. var formData = new FormData($('form')[0]);
  107. layer.confirm('您确定添加该号码吗?', {btn: ['确定', '取消']}, function () {
  108. layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  109. $.ajax({
  110. type: "post",
  111. url: "/testnumber/addform",
  112. data: formData,
  113. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  114. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  115. error: function (request) {
  116. layer.close(index);
  117. layer.msg("请联系管理员");
  118. },
  119. success: function (data) {
  120. if (data.data != null) {
  121. layer.msg(ReturnInfo(data.data), {icon: 5});
  122. return;
  123. }
  124. layer.msg(data.msg);
  125. parent.layer.close(oindex); //再执行关闭
  126. }
  127. });
  128. })
  129. return false;
  130. });
  131. form.on('submit(edit_number)', function (data) {
  132. var index = layer.msg('数据提交中,请稍候', {icon: 16, time: false, shade: 0.8}); //数据提交提示
  133. var formData = new FormData($('form')[0]);
  134. $.ajax({
  135. type: "post",
  136. url: "/testnumber/editform",
  137. data: formData,
  138. contentType: false, //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作,从而失去分界符,而使服务器不能正常解析文件
  139. processData: false, //当设置为true的时候,jquery ajax 提交的时候不会序列化 data,而是直接使用data
  140. error: function (request) {
  141. layer.close(index);
  142. layer.msg("请联系管理员");
  143. },
  144. success: function (data) {
  145. if (data.data != null) {
  146. layer.msg(ReturnInfo(data.data), {icon: 5});
  147. return;
  148. }
  149. layer.msg(data.msg);
  150. parent.layer.close(oindex); //再执行关闭
  151. }
  152. });
  153. return false;
  154. });
  155. // form.on('select(position)', function (data) {
  156. // console.log(data.value);
  157. // var type = data.value;
  158. // table.reload('tablerReload', {
  159. // url: 'brandform'
  160. // , where: {token: csrfToken, abroad: type}
  161. // , method: 'post'
  162. // });
  163. // });
  164. })