index.blade.php 16 KB

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