index.blade.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. @extends('admin.layout-content')
  2. @section('header')
  3. <style>
  4. .sg-search-box {
  5. display: flex;
  6. align-items: center;
  7. justify-content: space-between;
  8. }
  9. .sg-import-box {
  10. display: none;
  11. }
  12. .sg-import-box.sg-show {
  13. display: block;
  14. }
  15. .sg-import-box .layui-col-sm8 {
  16. float: none;
  17. }
  18. .layui-card .layui-form-item .layui-inline {
  19. margin-bottom: 0;
  20. }
  21. .sg-export-list {
  22. margin: 50px 0;
  23. }
  24. .sg-export-list .sg-item {
  25. margin: 20px 0;
  26. }
  27. .sg-export-list .sg-item .sg-title {
  28. margin: 20px 0;
  29. }
  30. .sg-export-list .sg-item .sg-desc,
  31. .sg-export-list .sg-item ul {
  32. color: rgb(140, 140, 140);
  33. margin-left: 30px;
  34. }
  35. .sg-down-link {
  36. color: blue;
  37. text-decoration: underline;
  38. }
  39. .sg-down-link:hover {
  40. color: blue;
  41. }
  42. </style>
  43. @endsection
  44. @section('content')
  45. <div class="layui-card">
  46. <div class="layui-card-header sg-card-header">
  47. {{ $model_name }}管理
  48. <div class="sg-card-create">
  49. <button id="sg-import-all" class="layui-btn layui-btn-sm layui-btn-normal">批量导入</button>
  50. </div>
  51. <div class="sg-card-create" style="margin-right: 10px">
  52. <button id="sg-create-btn" class="layui-btn layui-btn-sm">创建</button>
  53. </div>
  54. </div>
  55. <div class="layui-card-body">
  56. <form class="layui-form" id="sg-search-form">
  57. <input type="hidden" name="index" value="index">
  58. <div class="layui-form-item layui-row">
  59. <div class="layui-inline">
  60. <div class="layui-input-inline">
  61. <input type="text" name="name" placeholder="请输入项目名称" autocomplete="off" class="layui-input" value="{{ request('name') }}">
  62. </div>
  63. </div>
  64. <div class="layui-inline">
  65. <div class="layui-input-inline">
  66. <select name="manager_user_id">
  67. {{--<option value="0">项目经理</option>--}}
  68. <option value="0" selected>项目经理</option>
  69. @foreach($manager_user_id as $option)
  70. <option value="{{ $option['user_id'] }}" {{ request('manager_user_id',0) == $option['user_id'] ? 'selected' : '' }}>{{ $option['name'] }}</option>
  71. @endforeach
  72. </select>
  73. </div>
  74. </div>
  75. <div class="layui-inline">
  76. <div class="layui-btn" id="sg-search-btn">搜索</div>
  77. </div>
  78. </div>
  79. </form>
  80. <table id="sg-main-table" class="layui-hide" lay-filter="tableEvent"></table>
  81. <script type="text/html" id="sg-table-bar">
  82. <div class="layui-btn-group">
  83. <div class="layui-btn-group">
  84. @{{# if(d.active == 2) { }}
  85. <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="active">激活</a>
  86. @{{# } }}
  87. <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="member">成员列表</a>
  88. <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  89. <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
  90. </div>
  91. </div>
  92. </script>
  93. </div>
  94. </div>
  95. <div id="sg-import-box" class="sg-import-box">
  96. <div class="layui-row">
  97. {{--<input type="file" id="sg-upload-file">--}}
  98. <div class="layui-col-sm8 layui-col-sm-offset2">
  99. <div class="sg-export-list">
  100. <div class="sg-item">
  101. <h3 class="sg-title">一、请按照数据模板的格式准备要导入的数据。<a href="{{ $pre_uri . 'exportTemplate?t=' . time() }}" class="sg-down-link">点击下载</a>《项目导入模板》</h3>
  102. <ul>
  103. <li>注意事项</li>
  104. <li>1、模板中的表头名称不能更改,表头行不能删除</li>
  105. <li>2、导入文件请勿超过 20 MB</li>
  106. </ul>
  107. </div>
  108. <div class="sg-item">
  109. <h3 class="sg-title">二、请选择需要导入的文件</h3>
  110. <div class="sg-desc"><input type="file" id="sg-upload-file"></div>
  111. </div>
  112. </div>
  113. </div>
  114. </div>
  115. </div>
  116. @endsection
  117. @section('footer')
  118. <script>
  119. $(function () {
  120. layui.use(['table', 'layer'], function(){
  121. var table = layui.table,
  122. layer = layui.layer,
  123. form = layui.form,
  124. laydate = layui.laydate,
  125. top_window = window;
  126. $('#sg-import-all').click(function() {
  127. layer.open({
  128. title: '导入设备',
  129. type: 1,
  130. area: ['90%', '90%'],
  131. content: $('#sg-import-box'),
  132. btn: ['导入', '取消'],
  133. yes: function () {
  134. importFile();
  135. }
  136. });
  137. // $('#sg-upload-file').click();
  138. });
  139. function importFile() {
  140. var file = $('#sg-upload-file')[0].files[0];
  141. if(file) {
  142. var name = file['name'];
  143. var ext = name.split('.').pop();
  144. if(['xls', 'xlsx'].indexOf(ext) !== -1) {
  145. var formData = new FormData();
  146. formData.append('file', file);
  147. $.ajax({
  148. method: 'POST',
  149. url: '{{ $pre_uri }}' + 'import',
  150. headers: {
  151. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  152. },
  153. data: formData,
  154. contentType: false,
  155. cache: false,
  156. processData: false,
  157. success: function (data) {
  158. if(data.status === 'success') {
  159. layer.msg('上传成功', {
  160. icon: 1
  161. });
  162. setTimeout(function() {
  163. top_window.location.reload();
  164. }, 1000)
  165. } else {
  166. layer.alert(data.info, {
  167. icon: 2
  168. });
  169. }
  170. },
  171. error: function () {
  172. layer.msg('导入失败', {
  173. icon: 2
  174. });
  175. }
  176. });
  177. }
  178. } else {
  179. layer.msg('只支持xls,xlsx格式的文件', {
  180. icon: 2
  181. });
  182. }
  183. this.value = '';
  184. }
  185. table.render({
  186. elem: '#sg-main-table',
  187. url: '{{ $pre_uri }}' + 'get',
  188. cellMinWidth: 80,
  189. cols: [[
  190. { field: 'id', title: 'ID', align: 'center' },
  191. { field: 'name', title: '项目名称', align: 'center' },
  192. { field: 'manager_name', title: '项目经理', align: 'center' },
  193. { field: 'manager_phone', title: '手机号', align: 'center' },
  194. { field: 'created_at', title: '创建时间', align: 'center' },
  195. { field: 'active_label', title: '项目状态', align: 'center' },
  196. { title: '操作', align:'center', toolbar: '#sg-table-bar' }
  197. ]],
  198. page: {
  199. layout: ['count', 'prev', 'page', 'next', 'skip', 'refresh'],
  200. limit: 15
  201. },
  202. even: true,
  203. where: transformToJson($('#sg-search-form').serializeArray()),
  204. done: function(res, curr, count) {
  205. }
  206. });
  207. table.on('tool(tableEvent)', function(obj){
  208. var data = obj.data;
  209. if(obj.event === 'delete'){
  210. layer.confirm('确定要删除吗?', function(index) {
  211. $.ajax({
  212. method: 'POST',
  213. url: '{{ $pre_uri }}' + 'delete',
  214. headers: {
  215. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  216. },
  217. data: {
  218. id: data.id
  219. },
  220. success: function (data) {
  221. if(data.status === 'success') {
  222. obj.del();
  223. } else {
  224. layer.msg(data.info, {
  225. icon: 2
  226. });
  227. }
  228. layer.close(index);
  229. },
  230. error: function () {
  231. layer.close(index);
  232. layer.msg('删除失败', {
  233. icon: 2
  234. });
  235. }
  236. });
  237. });
  238. } else if(obj.event === 'edit') {
  239. layer.open({
  240. title: '编辑成员',
  241. type: 2,
  242. area: ['90%', '90%'],
  243. content: '{{ $pre_uri }}' + 'edit?id=' + data.id,
  244. end: function () {
  245. top_window.location.reload();
  246. }
  247. });
  248. } else if(obj.event === 'member') {
  249. window.location = '/admin/ProjectUser/index?project_id=' + data.id
  250. } else if(obj.event === 'active') {
  251. layer.confirm('确定激活吗?', function(index) {
  252. $.ajax({
  253. method: 'POST',
  254. url: '{{ $pre_uri }}' + 'active',
  255. headers: {
  256. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  257. },
  258. data: {
  259. id: data.id
  260. },
  261. success: function (data) {
  262. if(data.status === 'success') {
  263. updateTableBySearch()
  264. } else {
  265. layer.msg(data.info, {
  266. icon: 2
  267. });
  268. }
  269. layer.close(index);
  270. },
  271. error: function () {
  272. layer.close(index);
  273. layer.msg('操作失败', {
  274. icon: 2
  275. });
  276. }
  277. });
  278. });
  279. }
  280. });
  281. if($('#search-begin-date').length > 0) {
  282. laydate.render({
  283. elem: '#search-begin-date',
  284. done: function () {
  285. updateTableBySearch();
  286. }
  287. });
  288. }
  289. if($('#search-end-date').length > 0) {
  290. laydate.render({
  291. elem: '#search-end-date',
  292. done: function () {
  293. updateTableBySearch();
  294. }
  295. });
  296. }
  297. function transformToJson(formData){
  298. var obj={};
  299. for (var i in formData) {
  300. obj[formData[i].name]=formData[i]['value'];
  301. }
  302. return obj;
  303. }
  304. function updateTableBySearch() {
  305. table.reload('sg-main-table', {
  306. where: transformToJson($('#sg-search-form').serializeArray()),
  307. page: {
  308. curr: 1
  309. }
  310. });
  311. }
  312. $('#sg-search-btn').click(function() {
  313. updateTableBySearch();
  314. });
  315. // $('#sg-search-form').change(function () {
  316. // updateTableBySearch();
  317. // });
  318. //
  319. // form.on('select()', function(){
  320. // updateTableBySearch();
  321. // });
  322. $('#sg-create-btn').on('click', function () {
  323. layer.open({
  324. title: '创建' + '{{ $model_name }}',
  325. type: 2,
  326. area: ['90%', '90%'],
  327. content: '{{ $pre_uri }}' + 'create',
  328. end: function () {
  329. top_window.location.reload();
  330. }
  331. });
  332. });
  333. $('#sg-table-top-container').on('click', '.btn-delete-many', function () {
  334. layer.confirm('确定要删除所有选中行吗?', function () {
  335. var data = table.checkStatus('sg-main-table').data;
  336. if(data.length <= 0) {
  337. layer.msg('选择不能为空', {
  338. icon: 2
  339. });
  340. return false;
  341. }
  342. var ids = [];
  343. for(var i = 0; i < data.length; ++i) {
  344. ids.push(data[i]['id']);
  345. }
  346. $.ajax({
  347. method: 'POST',
  348. url: '{{ $pre_uri }}' + 'deleteMany',
  349. headers: {
  350. 'X-CSRF-TOKEN': '{{ csrf_token() }}'
  351. },
  352. data: {
  353. ids: JSON.stringify(ids)
  354. },
  355. success: function (data) {
  356. if(data.status === 'success') {
  357. top_window.location.reload();
  358. } else {
  359. layer.msg(data.info, {
  360. icon: 2
  361. });
  362. }
  363. },
  364. error: function () {
  365. layer.msg('删除失败', {
  366. icon: 2
  367. });
  368. }
  369. });
  370. })
  371. });
  372. });
  373. })
  374. </script>
  375. @endsection