project.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. {extend name="public/layout" /} {block name="title"}工程预算{/block} {block
  2. name="body"}
  3. <link rel="stylesheet" href="__LAYUI__/common.css" media="all" />
  4. <style type="text/css">
  5. html,
  6. body {
  7. display: block;
  8. min-width: 1100px;
  9. }
  10. .layui-table thead tr,
  11. .layui-table-header {
  12. background-color: #d8e6f1 !important;
  13. }
  14. .layui-fluid {
  15. display: block;
  16. box-shadow: 0 0 4px 0 #b6cade;
  17. border-radius: 5px;
  18. margin: 15px;
  19. background-color: #ffffff;
  20. min-height: 100vh;
  21. height: auto !important;
  22. overflow: hidden;
  23. }
  24. .layui-form-label {
  25. width: auto;
  26. }
  27. .layui-laydate-range {
  28. width: 581px;
  29. }
  30. .layui-table-page > div {
  31. display: flex;
  32. justify-content: flex-start;
  33. }
  34. .layui-btn-primary,
  35. .layui-btn-primary:hover {
  36. border: 1px solid #249efb;
  37. background-color: #fff;
  38. color: #249efb;
  39. }
  40. .layui-btn-normal,
  41. .layui-btn-normal:hover {
  42. border: 1px solid #249efb;
  43. background-color: #fff;
  44. color: #249efb;
  45. }
  46. .layui-btn-danger,
  47. .layui-btn-danger:hover {
  48. color: #ff5722;
  49. border: 1px solid #ff5722;
  50. background-color: #fff;
  51. }
  52. .layui-form-selected dl {
  53. z-index: 99999999;
  54. }
  55. .xq-Catebox {
  56. width: 100%;
  57. height: 50px;
  58. background-color: #f2f2f2;
  59. display: flex;
  60. align-items: center;
  61. justify-content: space-between;
  62. box-sizing: border-box;
  63. padding: 0px 15px;
  64. }
  65. .xq-left,
  66. .xq-right {
  67. display: flex;
  68. align-items: center;
  69. }
  70. .xq-edit {
  71. color: #249efb;
  72. margin: 0px 10px;
  73. font-size: 20px;
  74. cursor: pointer;
  75. }
  76. .xq-delete {
  77. color: red;
  78. font-size: 20px;
  79. cursor: pointer;
  80. }
  81. .mr10 {
  82. margin-right: 10px;
  83. }
  84. .xq-Table {
  85. width: 100%;
  86. }
  87. .xq-Table table {
  88. width: 100%;
  89. border-color: #f0f0f0;
  90. }
  91. thead {
  92. background-color: #d8e6f1 !important;
  93. }
  94. thead,
  95. tr {
  96. width: 100%;
  97. height: 40px;
  98. }
  99. thead > tr > th {
  100. height: 40px;
  101. }
  102. tbody > tr > td {
  103. box-sizing: border-box;
  104. padding: 5px 10px;
  105. }
  106. .xq-Box {
  107. width: 100%;
  108. height: auto;
  109. margin-bottom: 20px;
  110. }
  111. .xq-AddCate {
  112. width: 100px;
  113. height: 38px;
  114. background-color: #249efb;
  115. color: #fff;
  116. border-radius: 4px;
  117. line-height: 38px;
  118. text-align: center;
  119. cursor: pointer;
  120. }
  121. .xq-collasp {
  122. cursor: pointer;
  123. }
  124. .layui-layer-loading .layui-layer-content::after {
  125. content: "正在加载内容...";
  126. position: absolute;
  127. top: 30px;
  128. color: #fff;
  129. white-space: nowrap;
  130. left: 50%;
  131. transform: translateX(-50%);
  132. }
  133. </style>
  134. <body>
  135. <div class="layui-fluid">
  136. <div class="layui-card">
  137. <div class="layui-form layui-card-header layuiadmin-card-header-auto">
  138. <div class="layui-form-item">
  139. <div class="layui-inline" style="float: left">
  140. <button
  141. class="layui-btn layui-btn-primary layuiadmin-btn-course"
  142. data-type="import"
  143. >
  144. + 导入
  145. </button>
  146. <button
  147. class="layui-btn layui-btn-primary layuiadmin-btn-course"
  148. data-type="add"
  149. >
  150. 添加
  151. </button>
  152. </div>
  153. <div style="float: right">
  154. <div class="layui-inline">
  155. <div class="layui-input-inline">
  156. <input
  157. type="text"
  158. name="keyword"
  159. placeholder="请输入定额名称"
  160. autocomplete="off"
  161. class="layui-input"
  162. />
  163. </div>
  164. </div>
  165. <div class="layui-inline">
  166. <button
  167. class="layui-btn layuiadmin-btn-course searchBtn"
  168. lay-submit
  169. lay-filter="LAY-user-front-search"
  170. >
  171. <i
  172. class="layui-icon layui-icon-search layuiadmin-button-btn"
  173. ></i>
  174. </button>
  175. </div>
  176. </div>
  177. </div>
  178. </div>
  179. <div class="layui-card-body" style="text-align: center">
  180. <div id="renderHtml"></div>
  181. <div class="xq-AddCate">添加分类</div>
  182. </div>
  183. </div>
  184. </div>
  185. </body>
  186. {/block} {block name="js"}
  187. <script>
  188. layui
  189. .config({
  190. base: "__LAYUI__/",
  191. urlbase: "/sys",
  192. })
  193. .extend({
  194. index: "lib/index", //主入口模块
  195. })
  196. .use(["index", "form", "table", "laydate"], function () {
  197. var $ = layui.$,
  198. form = layui.form,
  199. laydate = layui.laydate,
  200. table = layui.table,
  201. showIndex = [];
  202. //日期范围
  203. laydate.render({
  204. elem: "#select_date",
  205. range: true,
  206. });
  207. //监听搜索
  208. form.on("submit(LAY-user-front-search)", function (data) {
  209. var field = data.field;
  210. getlist(field)
  211. });
  212. //事件
  213. var active = {
  214. add: function () {
  215. layer.open({
  216. type: 2,
  217. title: ["添加工程预算", "color:#333333;background-color:#D8E6F1;"],
  218. content: '{:url("smart_screen_more/project_add")}',
  219. resize: false,
  220. area: ["80%", "80%"],
  221. // btn: ['确定', '取消'],
  222. yes: function (index, layero) {
  223. //点击确认触发 iframe 内容中的按钮提交
  224. // var submit = layero.find('iframe').contents().find("#activity-submit");
  225. // submit.click();
  226. },
  227. });
  228. },
  229. import: function () {
  230. layer.open({
  231. type: 2,
  232. title: ["导入工程预算", "color:#333333;background-color:#D8E6F1;"],
  233. content: '{:url("smart_screen_more/importLog")}?type=2',
  234. resize: false,
  235. area: ["60%", "80%"],
  236. // btn: ['确定', '取消'],
  237. yes: function (index, layero) {
  238. //点击确认触发 iframe 内容中的按钮提交
  239. // var submit = layero.find('iframe').contents().find("#activity-submit");
  240. // submit.click();
  241. },
  242. });
  243. },
  244. };
  245. window.reloadlistFun = function () {
  246. getlist();
  247. };
  248. $(".xq-AddCate").click(function () {
  249. layer.prompt(
  250. {
  251. value: "",
  252. title: ["添加分类", "color:#333333;background-color:#D8E6F1;"],
  253. },
  254. function (value, index, elem) {
  255. if (!value) {
  256. layer.msg("请输入分类名称");
  257. return false;
  258. }
  259. $.ajax({
  260. type: "post",
  261. url: "{:url('smart_screen_more/project_cate_add')}",
  262. data: {
  263. name: value,
  264. },
  265. success: function (res) {
  266. if (res.code == 0) {
  267. layer.msg(
  268. res.msg,
  269. {
  270. anim: 0,
  271. },
  272. function () {
  273. //执行重载
  274. getlist();
  275. }
  276. );
  277. } else {
  278. layer.msg(res.msg, {
  279. anim: 6,
  280. });
  281. }
  282. },
  283. });
  284. layer.close(index);
  285. }
  286. );
  287. });
  288. function editCateName(name, id) {
  289. layer.prompt(
  290. {
  291. value: name,
  292. title: ["编辑分类", "color:#333333;background-color:#D8E6F1;"],
  293. },
  294. function (value, index, elem) {
  295. if (!value) {
  296. layer.msg("请输入分类名称");
  297. return false;
  298. }
  299. $.ajax({
  300. type: "post",
  301. url: "{:url('smart_screen_more/project_cate_edit')}",
  302. data: {
  303. name: value,
  304. id: id,
  305. },
  306. success: function (res) {
  307. if (res.code == 0) {
  308. layer.msg(
  309. res.msg,
  310. {
  311. anim: 0,
  312. },
  313. function () {
  314. //执行重载
  315. getlist();
  316. }
  317. );
  318. } else {
  319. layer.msg(res.msg, {
  320. anim: 6,
  321. });
  322. }
  323. },
  324. });
  325. layer.close(index);
  326. }
  327. );
  328. }
  329. function deleteCate(id) {
  330. layer.confirm(
  331. "确定删除此分类?",
  332. { title: ["信息", "color:#333333;background-color:#D8E6F1;"] },
  333. function (index) {
  334. layer.close(index);
  335. $.ajax({
  336. type: "post",
  337. url: "{:url('smart_screen_more/project_cate_delete')}",
  338. data: {
  339. id: id,
  340. },
  341. success: function (res) {
  342. if (res.code == 0) {
  343. layer.msg(
  344. res.msg,
  345. {
  346. anim: 0,
  347. },
  348. function () {
  349. //执行重载
  350. getlist();
  351. }
  352. );
  353. } else {
  354. layer.msg(res.msg, {
  355. anim: 6,
  356. });
  357. }
  358. },
  359. });
  360. }
  361. );
  362. }
  363. function deleteProject(id) {
  364. layer.confirm(
  365. "确定删除此工程预算?",
  366. { title: ["信息", "color:#333333;background-color:#D8E6F1;"] },
  367. function (index) {
  368. layer.close(index);
  369. $.ajax({
  370. type: "post",
  371. url: "{:url('smart_screen_more/project_delete')}",
  372. data: {
  373. id: id,
  374. },
  375. success: function (res) {
  376. if (res.code == 0) {
  377. layer.msg(
  378. res.msg,
  379. {
  380. anim: 0,
  381. },
  382. function () {
  383. //执行重载
  384. getlist();
  385. }
  386. );
  387. } else {
  388. layer.msg(res.msg, {
  389. anim: 6,
  390. });
  391. }
  392. },
  393. });
  394. }
  395. );
  396. }
  397. getlist();
  398. function getlist(params = {}) {
  399. let loadingIndex = layer.load("Loading...", {
  400. shade: [0.6, "#000"], //0.1透明度的白色背景
  401. });
  402. $.ajax({
  403. url: "{:url('smart_screen_more/project')}",
  404. type: "post",
  405. data: {
  406. ...params
  407. },
  408. success: (res) => {
  409. setTimeout(() => {
  410. layer.close(loadingIndex);
  411. }, 1500);
  412. if (res.code == 0) {
  413. if (res.data.length) {
  414. renderHtmlFunc(res.data);
  415. } else {
  416. $("#renderHtml").html('<div style="width: 100%;text-align:center;line-height: 150px;color: #999;font-size: 16px;border: 1px solid #f2f2f2;margin-bottom: 20px;">请添加分类</div>');
  417. }
  418. }
  419. },
  420. });
  421. }
  422. function renderHtmlFunc(dataArr) {
  423. let htmls = dataArr
  424. .map((item, index) => {
  425. return `<div class="xq-Box">
  426. <div class="xq-Catebox">
  427. <div class="xq-left">
  428. <span>${item.name}</span>
  429. <i class="layui-icon layui-icon-edit xq-edit" data-name="${
  430. item.name
  431. }" data-id="${item.id}"></i>
  432. <i class="layui-icon layui-icon-delete xq-delete" data-id="${
  433. item.id
  434. }"></i>
  435. </div>
  436. <div class="xq-right">
  437. <span class="mr10">共${item.project_count}个工程</span>
  438. <i class="layui-icon ${
  439. showIndex.includes(index)
  440. ? "layui-icon-down"
  441. : "layui-icon-up"
  442. } xq-collasp" data-index="${index}"></i>
  443. </div>
  444. </div>
  445. <div class="xq-Table ${
  446. showIndex.includes(index) ? "" : "layui-hide"
  447. }">
  448. <table border="1px">
  449. <thead>
  450. <tr>
  451. <th style="width: 180px">类别</th>
  452. <th style="width: 220px">定额名称</th>
  453. <th style="width: 120px">单位</th>
  454. <th style="width: 140px">综合单价</th>
  455. <th>项目说明</th>
  456. <th style="width: 120px">上传人员</th>
  457. <th style="width: 180px">操作</th>
  458. </tr>
  459. </thead>
  460. <tbody>
  461. ${renderTableHtmls(item.project)}
  462. </tbody>
  463. </table>
  464. ${
  465. item.project_count == 0
  466. ? `<div style="width: 100%;text-align:center;line-height:100px;">暂无数据</div>`
  467. : ""
  468. }
  469. </div>
  470. </div>`;
  471. })
  472. .join("");
  473. $("#renderHtml").html(htmls);
  474. setTimeout(() => {
  475. $(".xq-edit").click(function () {
  476. let dataObj = $(this).prop("dataset");
  477. editCateName(dataObj.name, dataObj.id);
  478. });
  479. $(".xq-delete").click(function () {
  480. let dataObj = $(this).prop("dataset");
  481. deleteCate(dataObj.id);
  482. });
  483. $(".xq-collasp").click(function () {
  484. let dataObj = $(this).prop("dataset");
  485. let index = parseInt(dataObj.index);
  486. $(".xq-Table").eq(index).toggleClass("layui-hide");
  487. if ($(this).hasClass("layui-icon-down")) {
  488. $(this).removeClass("layui-icon-down");
  489. $(this).addClass("layui-icon-up");
  490. } else {
  491. $(this).addClass("layui-icon-down");
  492. $(this).removeClass("layui-icon-up");
  493. }
  494. if (showIndex.includes(index)) {
  495. showIndex.splice(showIndex.indexOf(index), 1);
  496. } else {
  497. showIndex.push(index);
  498. }
  499. });
  500. $(".xw-edit").click(function () {
  501. let dataObj = $(this).prop("dataset");
  502. layer.open({
  503. type: 2,
  504. title: [
  505. "修改工程预算",
  506. "color:#333333;background-color:#D8E6F1;",
  507. ],
  508. content:
  509. "{:url('smart_screen_more/project_edit')}?id=" + dataObj.id,
  510. resize: false,
  511. area: ["80%", "80%"],
  512. // btn: ['确定', '取消'],
  513. yes: function (index, layero) {
  514. //点击确认触发 iframe 内容中的按钮提交
  515. // var submit = layero.find('iframe').contents().find("#activity-submit");
  516. // submit.click();
  517. },
  518. });
  519. });
  520. $(".xw-dele").click(function () {
  521. let dataObj = $(this).prop("dataset");
  522. deleteProject(dataObj.id);
  523. });
  524. }, 300);
  525. }
  526. function renderTableHtmls(dataArr) {
  527. let htmls = dataArr
  528. .map((vitem, vindex) => {
  529. return `<tr class="trEle${vitem.id}">
  530. <td>${vitem.category}</td>
  531. <td>${vitem.name}</td>
  532. <td>${vitem.unit}</td>
  533. <td>${vitem.price}</td>
  534. <td>${vitem.content}</td>
  535. <td>${vitem.employee_name || "无"}</td>
  536. <td>
  537. <a class="layui-btn layui-btn-normal layui-btn-xs xw-edit" data-id="${
  538. vitem.id
  539. }">
  540. 编辑
  541. </a>
  542. <a class="layui-btn layui-btn-danger layui-btn-xs xw-dele" data-id="${
  543. vitem.id
  544. }">
  545. 删除
  546. </a>
  547. </td>
  548. </tr>`;
  549. })
  550. .join("");
  551. return htmls;
  552. }
  553. //监听
  554. table.on("tool(company-activity)", function (obj) {
  555. var data = obj.data;
  556. if (obj.event === "edit") {
  557. } else if (obj.event === "del") {
  558. }
  559. });
  560. $(".layui-btn.layuiadmin-btn-course").on("click", function () {
  561. var type = $(this).data("type");
  562. active[type] ? active[type].call(this) : "";
  563. });
  564. });
  565. </script>
  566. {/block}