quota_info.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. const quota_modal_template = `
  2. <div class="modal fade" id="modal_quota" tabindex="-1" aria-hidden="true">
  3. <div class="modal-dialog modal-lg modal-dialog-centered">
  4. <div class="modal-content rounded">
  5. <div class="modal-header">
  6. <h3 class="modal-title"><span class="prefix"></span>定额</h3>
  7. <div class="btn btn-sm btn-icon btn-active-color-primary" data-bs-dismiss="modal">
  8. <i class="ki-duotone ki-cross fs-1">
  9. <span class="path1"></span>
  10. <span class="path2"></span>
  11. </i>
  12. </div>
  13. </div>
  14. <div class="modal-body">
  15. <form>
  16. <div class="form-group">
  17. <input type="hidden" name="id" value="">
  18. <input type="hidden" name="budget_id" value="">
  19. <input type="hidden" name="project_id" value="">
  20. <input type="hidden" name="item_id" value="">
  21. <input type="hidden" name="item_code" value="">
  22. <input type="hidden" name="quota_id" value="">
  23. <input type="hidden" name="task_id" value="">
  24. <div>
  25. <dl class="d-flex mb-1">
  26. <dt class="" style="white-space: nowrap">源内容:</dt>
  27. <dd id="ex_row" class="ms-3 mb-0"></dd>
  28. </dl>
  29. <div class="d-flex flex-wrap">
  30. <dl class="d-flex mb-1 w-25">
  31. <dt class="" style="white-space: nowrap">源数量:</dt>
  32. <dd id="ex_amount" class="ms-3 mb-0"></dd>
  33. </dl>
  34. <dl class="d-flex mb-1 w-25">
  35. <dt class="" style="white-space: nowrap">源数量位置:</dt>
  36. <dd id="ex_cell" class="ms-3 mb-0"></dd>
  37. </dl>
  38. <dl class="d-flex mb-1 w-25">
  39. <dt class="" style="white-space: nowrap">源数量单位:</dt>
  40. <dd id="ex_unit" class="ms-3 mb-0"></dd>
  41. </dl>
  42. </div>
  43. </div>
  44. <span class="separator my-5"></span>
  45. <div class="fv-row form-group mb-3">
  46. <label for="entry_name" class="form-label required">工程或费用项目名称</label>
  47. <input type="text" class="form-control" name="entry_name" id="entry_name" placeholder="请输入工程或费用项目名称" required />
  48. </div>
  49. <div class="fv-row form-group mb-3">
  50. <label for="units" class="form-label required">单位</label>
  51. <input type="text" class="form-control" name="units" id="units" placeholder="请输入单位" required />
  52. </div>
  53. <div class="fv-row form-group mb-3">
  54. <label for="amount" class="form-label required">工程数量</label>
  55. <input type="text" class="form-control" name="amount" id="amount" placeholder="请输入工程数量" required />
  56. </div>
  57. <div class="fv-row form-group mb-3">
  58. <label for="quota_code" class="form-label">定额编号</label>
  59. <input type="text" class="form-control" name="quota_code" id="quota_code" placeholder="请输入定额编号" />
  60. </div>
  61. <div class="fv-row form-group mb-3">
  62. <label for="quota_code" class="form-label">章节条目</label>
  63. <select type="text" class="form-select" name="chapter" id="chapter">
  64. <option value="">请选择章节条目</option>
  65. </select>
  66. </div>
  67. <div class="d-flex pt-3 justify-content-center">
  68. <div class="form-check form-check-custom form-check-solid form-check-danger mb-3 is_cover_box">
  69. <input class="form-check-input" type="radio" checked value="1" name="is_cover" id="is_cover_1"/>
  70. <label class="form-check-label ms-3 text-danger" for="is_cover_1">覆盖(修改)源数据</label>
  71. </div>
  72. <div class="form-check form-check-solid ms-5 mb-3 is_cover_box">
  73. <input class="form-check-input" type="radio" value="0" name="is_cover" id="is_cover_2"/>
  74. <label class="form-check-label ms-3 text-primary" for="is_cover_2">新增源数据</label>
  75. </div>
  76. </div>
  77. </div>
  78. </form>
  79. </div>
  80. <div class="modal-footer">
  81. <button type="button" class="btn btn-light" data-bs-dismiss="modal">取消</button>
  82. <button type="button" class="btn btn-light-success" onclick="SaveQuota(true)">提交</button>
  83. <button type="button" class="btn btn-primary" onclick="SaveQuota()">保存草稿</button>
  84. </div>
  85. </div>
  86. </div>
  87. </div>`
  88. $('.app-main .app-container').append(quota_modal_template)
  89. const nav_template = `<ul id="nav_tab" class="nav nav-tabs nav-line-tabs nav-line-tabs-2x fs-6"></ul><div class="tab-content" id="tab_content" style="height: calc(100% - 80px);"></div>`,
  90. nav_tab_template = `
  91. <li class="nav-item" data-id="{0}">
  92. <button type="button" class="nav-link {2} btn-light-primary btn-active-color-primary" data-id="{0}" data-bs-toggle="tab" data-bs-target="#iwb_tab_{0}">{1}</button>
  93. </li>`,
  94. tab_content_template = `<div class="tab-pane h-100" id="iwb_tab_{0}" role="tabpanel">{1}</div>`,
  95. table_add_quota_btn_template = `<button type="button" class="quota_add_btn btn btn-primary btn-sm" onclick="Send_Quota_Batch('{0}')">批量推送</button>` //`<button type="button" class="quota_add_btn btn btn-primary btn-sm" onclick="Add_Quota('{0}')">添加定额</button>`,
  96. table_run_select_template = `<select class="form-select form-select-sm me-5" name="process_status">
  97. <option value="">全部运行状态</option>
  98. <option value="0">草稿</option>
  99. <option value="1">等待运行</option>
  100. <option value="2">运行中</option>
  101. <option value="200">运行成功</option>
  102. <option value="4">取消运行</option>
  103. <option value="5">运行失败</option>
  104. <!--<option value="4">已修改</option>-->
  105. </select>`,
  106. table_send_select_template = `<select class="form-select form-select-sm me-5" name="send_status">
  107. <option value="">全部推送状态</option>
  108. <option value="0">未推送</option>
  109. <!-- <option value="1">推送中</option>-->
  110. <option value="200">推送成功</option>
  111. <option value="2">推送失败</option>
  112. <!-- <option value="3">数据变更</option>-->
  113. </select>`,
  114. table_template = `<div class="table-box table-responsive" data-id="{0}" id="table_box_{0}">
  115. <div class="d-flex justify-content-between my-5">
  116. <div class="">{1}</div>
  117. <form class="search-box d-flex">
  118. <div class="d-flex">
  119. {2}
  120. <input type="text" class="form-control form-control-sm w-200px" placeholder="请输入关键字" name="keyword" />
  121. </div>
  122. <div class="btn-group ms-5">
  123. <button type="button" class="btn btn-primary btn-sm" onclick="IwbTableSearch(this)">查询</button>
  124. <button type="button" class="btn btn-danger btn-sm" onclick="IwbTableResetSearch(this)">重置</button>
  125. </div>
  126. </form>
  127. </div>
  128. <table class="table table-striped table-bordered table-hover table-rounded" id="table_{0}">
  129. </table>
  130. <div class="pagination-row"></div>
  131. </div>`
  132. const $modalQuota = $('#modal_quota')
  133. let $rightBox, $rightBoxHeader, $rightBoxBody, $taskBox, $quotaBox, budget_id, item_code
  134. console.log(`加载项目:${project_id}`)
  135. InitBody()
  136. $(function () {
  137. BuildChapterInfo()
  138. $(window).on('resize', AdjustBoxHeight)
  139. })
  140. function InitBody() {
  141. $('#body_box').html(`<div class="d-flex flex-row project-box w-100">
  142. <div class="flex-row-auto h-100 left-box">
  143. <div class="tree-dom w-300px h-100 overflow-auto" id="js-tree"></div>
  144. </div>
  145. <div class="flex-row-fluid flex-column right-box" style="display: none">
  146. <div class="my-2 d-flex align-items-center box-header mt-5 flex-column-auto">
  147. <section class="d-none">
  148. <input type="hidden" name="budget_id" value="{0}">
  149. <input type="hidden" name="project_id" value="">
  150. <input type="hidden" name="item_id" value="">
  151. <input type="hidden" name="item_code" value="">
  152. </section>
  153. <span class="fw-bolder me-5 title fs-2"></span>
  154. <span class="badge badge-primary fs-6 me-5"></span>
  155. <div class="d-flex table_radio_box" >
  156. <div class="form-check form-check-custom form-check-primary form-check-solid">
  157. <input class="form-check-input" name="table_radio" type="radio" value="task" id="task_radio"/>
  158. <label class="form-check-label fw-bolder text-primary" for="task_radio">
  159. 任务列表
  160. </label>
  161. </div>
  162. <div class="form-check form-check-custom form-check-success form-check-solid ms-5">
  163. <input class="form-check-input" name="table_radio" type="radio" value="quota" id="quota_radio"/>
  164. <label class="form-check-label fw-bolder text-success" for="quota_radio">
  165. 定额输入
  166. </label>
  167. </div>
  168. </div>
  169. </div>
  170. <div class="box-body flex-column-fluid">
  171. <div class="task w-100 h-100" style="display: none"></div>
  172. <div class="quota w-100 h-100" style="display: none"></div>
  173. </div>
  174. </div>
  175. </div>`)
  176. AdjustBoxHeight()
  177. $rightBox = $('#body_box .right-box'),
  178. $rightBoxHeader = $('#body_box .right-box .box-header'),
  179. $rightBoxBody = $('#body_box .right-box .box-body'),
  180. $taskBox = $rightBoxBody.find('.task'),
  181. $quotaBox = $rightBoxBody.find('.quota')
  182. }
  183. function AdjustBoxHeight() {
  184. const h = $('.app-wrapper').height() - $('.app-body-header').height() - $('.app-footer').height() - 5
  185. $('#body_box .project-box').height(h)
  186. }
  187. function BuildChapterInfo() {
  188. const $tree = $(`#js-tree`)
  189. const opt = {
  190. core: {
  191. themes: {
  192. responsive: false,
  193. },
  194. strings: {
  195. 'Loading ...': '加载中...',
  196. },
  197. check_callback: true,
  198. data: function (node, callback) {
  199. // console.log('TREE_NODE', node)
  200. IwbAjax_1({
  201. url: `/api/project/chapter/${project_id}?c=${node?.data?.item_code || ''}`,
  202. success: res => {
  203. if (res.success) {
  204. console.log('TREE', res.data)
  205. callback(res.data)
  206. } else {
  207. console.error(res.message)
  208. }
  209. },
  210. })
  211. },
  212. },
  213. types: {
  214. default: {
  215. icon: 'ki-outline ki-folder text-primary',
  216. },
  217. file: {
  218. icon: 'ki-outline ki-file text-primary',
  219. },
  220. },
  221. plugins: ['dnd', 'types'],
  222. }
  223. // $tree.jstree('destroy')
  224. $tree.on('loaded.jstree', function (e, data) {
  225. // console.log('TREE_LOADED', e, data)
  226. const inst = data.instance;
  227. const obj = inst.get_node(e.target.firstChild.firstChild.firstChild);
  228. inst.select_node(obj);
  229. })
  230. $tree.on('select_node.jstree', function (e, data) {
  231. console.log('TREE_SELECTED', e, data)
  232. RenderRightBox(data.node?.data)
  233. })
  234. $tree.jstree(opt)
  235. }
  236. function RenderRightBox(data) {
  237. console.log('RenderRightBox', arguments)
  238. $rightBoxBody.data('data', data)
  239. $rightBox.find('input[name="budget_id"]').val(data.budget_id);
  240. $rightBox.find('input[name="project_id"]').val(project_id);
  241. $rightBox.find('input[name="item_id"]').val(data.item_id);
  242. $rightBox.find('input[name="item_code"]').val(data.item_code);
  243. const title = data.chapter ? `${data.chapter}、${data.project_name}` : data.section ? `${data.section}.${data.project_name}` : data.project_name
  244. $rightBoxHeader.find('.title').text(title)
  245. RenderRightBox_Custom(data)
  246. $rightBox.show()
  247. }
  248. function RenderRightBox_Custom(data) {
  249. $('.table_radio_box .form-check').hide()
  250. $quotaBox.data("table-url", `/api/quota/list/task/${task_id}`)
  251. QuotaNavTab(data)
  252. }
  253. function QuotaNavTab() {
  254. $taskBox.hide()
  255. if (!$quotaBox.find('#nav_tab').length) {
  256. $quotaBox.html(nav_template)
  257. BuildBudgetInfo()
  258. } else {
  259. const budget = $quotaBox.find('#nav_tab').data('budget-info') || {}
  260. $quotaBox.html(nav_template)
  261. RenderTabs(budget)
  262. }
  263. $quotaBox.find('.table-box').hide()
  264. $quotaBox.show()
  265. }
  266. function BuildBudgetInfo() {
  267. IwbAjax_1({
  268. url: `/api/project/budget/${project_id}`,
  269. success: function (res) {
  270. if (res.success) {
  271. RenderTabs(res.data)
  272. } else {
  273. console.error(res.message)
  274. }
  275. },
  276. })
  277. }
  278. function RenderTabs(data) {
  279. console.log('RenderTabs', data)
  280. let str1 = '',
  281. str2 = ''
  282. if (data && data.length) {
  283. for (let i = 0; i < data.length; i++) {
  284. const item = data[i]
  285. str1 += nav_tab_template.format(item.budget_id, item.budget_code)
  286. const tableStr = table_template.format(item.budget_id, table_add_quota_btn_template.format(item.budget_id), table_send_select_template)
  287. const tabContent = tab_content_template.format(item.budget_id, tableStr)
  288. // console.log('TAB_CONTENT', tabContent)
  289. str2 += tabContent
  290. }
  291. }
  292. const $tab = $('#nav_tab'), $content = $('#tab_content')
  293. $tab.html(str1).data('budget-info', data)
  294. $content.html(str2)
  295. const $tab_btn = $tab.find('li button[data-bs-toggle="tab"]')
  296. $tab_btn.on('shown.bs.tab', (e) => {
  297. console.log('TAB', e)
  298. const tab_id = $(e.target).data('id'),
  299. data = $("#body_box .right-box .box-body").data('data')
  300. budget_id = tab_id
  301. item_code = data.item_code
  302. RenderQuotaTable(data)
  303. })
  304. const firstTab = new bootstrap.Tab($tab_btn.eq(0))
  305. firstTab.show()
  306. }
  307. function RenderQuotaTable(data) {
  308. console.log('RenderQuotaTable', budget_id, data)
  309. const $table = $quotaBox.find(`#table_${budget_id}`)
  310. LoadQuotaTable($table)
  311. }
  312. function LoadQuotaTable(table) {
  313. const url = `${$quotaBox.data("table-url")}/${budget_id}/${project_id}/${item_code}`
  314. IwbTable(table, {
  315. url,
  316. checkBox: true,
  317. columns: [
  318. {
  319. title: '序号',
  320. data: 'id',
  321. width: '80px',
  322. },
  323. {
  324. title: '工程或费用项目名称',
  325. data: 'entry_name',
  326. width: '210px',
  327. render: (row) => {
  328. return `<span class="one-line mw-200px" data-bs-toggle="tooltip" data-bs-placement="top" title="${row.entry_name}" >${row.entry_name}</span>`
  329. }
  330. },
  331. {
  332. title: '工程数量',
  333. data: 'amount',
  334. width: '100px',
  335. },
  336. {
  337. title: '单位',
  338. data: 'units',
  339. width: '80px',
  340. },
  341. {
  342. title: '定额编号',
  343. data: 'quota_code',
  344. width: '100px',
  345. render: (row) => {
  346. if (row.quota_id) {
  347. return `<span class="badge badge-light-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="可覆盖系统数据:${row.quota_id}" >${row.quota_code}</span>`
  348. } else {
  349. return `<span class="badge badge-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="未关联系统数据" >${row.quota_code}</span>`
  350. }
  351. }
  352. },
  353. {
  354. title: 'Excel文件',
  355. data: 'ex_file',
  356. width: '150px',
  357. render: (row) => {
  358. const path = row.ex_file
  359. if (!path) {
  360. return '-'
  361. }
  362. const names = path.split('/')
  363. const file_name = names[names.length - 1]
  364. return `<span class="one-line mw-150px"><a href="#" onclick="DownloadFile('/api/task/download?filename=${encodeURIComponent(path)}','${file_name}')" class="link link-info px-2">${file_name}</a></span>`
  365. }
  366. },
  367. {
  368. title: 'Excel整行内容',
  369. data: 'ex_row',
  370. width: 'auto',
  371. render: (row) => {
  372. return `<span class="one-line w-300px" data-bs-toggle="tooltip" data-bs-placement="top" title="${row.ex_row}" >${row.ex_row}</span>`
  373. }
  374. },
  375. {
  376. title: 'Excel数量',
  377. data: 'ex_amount',
  378. width: '100px',
  379. },
  380. {
  381. title: '数量位置',
  382. data: 'ex_cell',
  383. width: '80px',
  384. },
  385. {
  386. title: '数量单位',
  387. data: 'ex_unit',
  388. width: '80px',
  389. },
  390. {
  391. title: '状态',
  392. data: 'status',
  393. width: '100px',
  394. render: (row) => {
  395. let str = ''
  396. // if(row.process_status === 0){
  397. // str+= `<span class="badge badge-primary">未处理</span>`
  398. // }else if (row.process_status === 1){
  399. // str+= `<span class="badge badge-warning">处理中</span>`
  400. // }else if (row.process_status === 2){
  401. // str+= `<span class="badge badge-success">已处理</span>`
  402. // }else if (row.process_status === 3){
  403. // str+= `<span class="badge badge-danger">处理失败</span>`
  404. // }else if (row.process_status === 4){
  405. // str+= `<span class="badge badge-danger">数据变更</span>`
  406. // }
  407. if (row.send_status === 0) {
  408. str += `<span class="badge badge-primary ms-3">未推送</span>`
  409. } else if (row.send_status === 1) {
  410. str += `<span class="badge badge-warning ms-3">推送中</span>`
  411. } else if (row.send_status === 200) {
  412. str += `<span class="badge badge-success ms-3">推送成功</span>`
  413. } else if (row.send_status === 2) {
  414. str += `<span class="badge badge-danger ms-3" data-bs-toggle="tooltip" data-bs-placement="top" title="${row.send_error}">推送失败</span>`
  415. } else if (row.send_status === 3) {
  416. str += `<span class="badge badge-danger ms-3">数据变更</span>`
  417. }
  418. return str
  419. }
  420. },
  421. {
  422. title: '操作',
  423. data: 'id',
  424. width: '120px',
  425. render: (row) => {
  426. let str = ''
  427. // if (row.process_status === 0) {
  428. // str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="开始处理" onclick="StartProcessQuota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-book-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i></button>`
  429. // } else if (row.process_status === 2) {
  430. // str += `<button type="button" class="btn btn-icon btn-sm btn-light-warning" data-bs-toggle="tooltip" data-bs-placement="top" title="重新处理" onclick="ReStartProcessQuota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-book-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i></button>`
  431. //
  432. // } else if (row.process_status === 3) {
  433. // str += `<button type="button" class="btn btn-icon btn-sm btn-light-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="重新处理" onclick="ReStartProcessQuota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-book-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i></button>`
  434. // } else if (row.process_status === 4) {
  435. // str += `<button type="button" class="btn btn-icon btn-sm btn-light-info" data-bs-toggle="tooltip" data-bs-placement="top" title="重新处理" onclick="ReStartProcessQuota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-book-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span></i></button>`
  436. // }
  437. if (row.send_status === 0) {
  438. str += `<button type="button" class="btn btn-icon btn-sm ${row.quota_id ? 'btn-primary' : 'btn-light-primary'}" data-bs-toggle="tooltip" data-bs-placement="top" title="开始推送" onclick="StartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
  439. } else if (row.send_status === 200) {
  440. // str += `<button type="button" class="btn btn-icon btn-sm ${row.quota_id ? 'btn-warning' : 'btn-light-warning'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
  441. } else if (row.send_status === 2) {
  442. str += `<button type="button" class="btn btn-icon btn-sm ${row.quota_id ? 'btn-danger' : 'btn-light-danger'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
  443. } else if (row.send_status === 3) {
  444. str += `<button type="button" class="btn btn-icon btn-sm ${row.quota_id ? 'btn-info' : 'btn-light-info'}" data-bs-toggle="tooltip" data-bs-placement="top" title="重新推送" onclick="ReStartSendQuota(${row.id}, ${row.budget_id}, ${row.quota_id})"><i class="ki-duotone ki-send fs-3"><span class="path1"></span><span class="path2"></span></i></button>`
  445. }
  446. if (row.send_status !== 200) {
  447. str += `<button type="button" class="btn btn-icon btn-sm btn-light-primary" data-bs-toggle="tooltip" data-bs-placement="top" title="编辑" onclick="Edit_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-message-edit fs-1"><span class="path1"></span><span class="path2"></span></i></button>`
  448. str += `<button type="button" class="btn btn-icon btn-sm btn-light-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="删除" onclick="Delete_Quota(${row.id}, ${row.budget_id})"><i class="ki-duotone ki-trash-square fs-1"><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></i></button>`
  449. }
  450. return str
  451. }
  452. },
  453. ]
  454. }, true)
  455. }
  456. function SetBudgetData($el) {
  457. const $tableBox = $(`.table-box`)
  458. $el.find('[name="project_id"]').val($tableBox.find('input[name="project_id"]').val());
  459. $el.find('[name="item_id"]').val($tableBox.find('input[name="item_id"]').val());
  460. $el.find('[name="item_code"]').val($tableBox.find('input[name="item_code"]').val());
  461. }
  462. function Add_Quota(budget_id,) {
  463. AddModal($modalQuota, () => {
  464. SetBudgetData($modalQuota)
  465. $modalQuota.find('[name="id"]').val('0');
  466. $modalQuota.find('[name="quota_id"]').val('0');
  467. $modalQuota.find('[name="task_id"]').val('0');
  468. $modalQuota.find('[name="budget_id"]').val(budget_id);
  469. $modalQuota.find('[name="is_cover"]').val('0')
  470. $modalQuota.find('.is_cover_box').hide()
  471. })
  472. }
  473. function Edit_Quota(id) {
  474. $modalQuota.find('.is_cover_box').hide()
  475. EditModal($modalQuota, () => {
  476. IwbAjax_1({
  477. url: `/api/quota/get/${id}`,
  478. success: res => {
  479. if (!res.success) {
  480. console.error(res.message)
  481. return
  482. }
  483. const data = res.data,
  484. // SetBudgetData(budget_id)
  485. quota_id = data.quota_id
  486. $modalQuota.find('[name="id"]').val(data.id);
  487. $modalQuota.find('[name="quota_id"]').val(quota_id);
  488. $modalQuota.find('[name="task_id"]').val(data.task_id);
  489. $modalQuota.find('[name="budget_id"]').val(data.budget_id);
  490. $modalQuota.find('[name="project_id"]').val(data.project_id);
  491. $modalQuota.find('[name="item_id"]').val(data.item_id);
  492. $modalQuota.find('[name="item_code"]').val(data.item_code);
  493. $modalQuota.find('[name="entry_name"]').val(data.entry_name);
  494. $modalQuota.find('[name="amount"]').val(data.amount);
  495. $modalQuota.find('[name="units"]').val(data.units);
  496. $modalQuota.find('[name="quota_code"]').val(data.quota_code);
  497. $modalQuota.find('#ex_row').html(data.ex_row);
  498. $modalQuota.find('#ex_amount').html(data.ex_amount);
  499. $modalQuota.find('#ex_cell').html(data.ex_cell);
  500. $modalQuota.find('#ex_unit').html(data.ex_unit);
  501. $modalQuota.find('[name="is_cover"][value="0"]').prop('checked', true)
  502. if (quota_id) {
  503. $modalQuota.find('.is_cover_box').show()
  504. }
  505. }
  506. })
  507. })
  508. }
  509. function SaveQuota(isSubmit) {
  510. const id = $modalQuota.find('[name="id"]').val(),
  511. quota_id = $modalQuota.find('[name="quota_id"]').val(),
  512. task_id = $modalQuota.find('[name="task_id"]').val(),
  513. budget_id = $modalQuota.find('[name="budget_id"]').val(),
  514. project_id = $modalQuota.find('[name="project_id"]').val(),
  515. item_id = $modalQuota.find('[name="item_id"]').val(),
  516. item_code = $modalQuota.find('[name="item_code"]').val(),
  517. entry_name = $modalQuota.find('[name="entry_name"]').val(),
  518. amount = $modalQuota.find('[name="amount"]').val(),
  519. units = $modalQuota.find('[name="units"]').val(),
  520. quota_code = $modalQuota.find('[name="quota_code"]').val(),
  521. is_cover = $modalQuota.find('[name="is_cover"]:checked').val()
  522. IwbAjax({
  523. url: `/api/quota/save`,
  524. data: {
  525. id,
  526. quota_id,
  527. task_id,
  528. budget_id,
  529. project_id,
  530. item_id,
  531. item_code,
  532. entry_name,
  533. amount,
  534. units,
  535. quota_code,
  536. run_now: isSubmit ? 'true' : 'false',
  537. is_cover: is_cover === '1' || is_cover === 1 ? 'true' : 'false',
  538. },
  539. modal: $modalQuota,
  540. table: `#table_${budget_id}`
  541. })
  542. }
  543. function Delete_Quota(id, budget_id) {
  544. ConfirmUrl('确定删除吗?', `/api/quota/delete/${id}`, `#table_${budget_id}`)
  545. }
  546. function StartSendQuota(ids, budget_id, is_cover) {
  547. SendQuota('确定开始推送数据吗?', ids, budget_id, is_cover)
  548. }
  549. function ReStartSendQuota(ids, budget_id, is_cover) {
  550. SendQuota('确定重新开始推送数据吗?', ids, budget_id, is_cover)
  551. }
  552. function Send_Quota_Batch(budget_id) {
  553. const $table = `#table_${budget_id}`,
  554. selectedRows = IwbTableGetSelectedRows($table)
  555. if (selectedRows.length) {
  556. const ids = [], insert_ids = [], update_ids = []
  557. for (let i = 0; i < selectedRows.length; i++) {
  558. const row = selectedRows[i]
  559. if (row.quota_id > 0) {
  560. update_ids.push(row.id)
  561. } else {
  562. insert_ids.push(row.id)
  563. }
  564. ids.push(row.id)
  565. }
  566. const ids_str = ids.join(','), insert_ids_str = insert_ids.join(','), update_ids_str = update_ids.join(',')
  567. let str = `<div class="">确定批量推送这些数据吗?部分数据只能新增,无法覆盖,请谨慎操作!</div>`
  568. if (insert_ids_str) {
  569. str += `<div class="text-primary d-flex align-items-center"><strong style="white-space: nowrap">新增ID:</strong>${insert_ids_str}</div>`
  570. }
  571. if (update_ids_str) {
  572. str += `<div class="text-danger d-flex align-items-center"><strong style="white-space: nowrap">覆盖(修改)ID:</strong>${update_ids_str}</div>`
  573. }
  574. SendQuota(str, ids_str, budget_id, true, true)
  575. } else {
  576. MsgWarning('没有选择数据,请选择要推送的数据!')
  577. }
  578. }
  579. function SendQuota(title, ids, budget_id, is_cover, is_html) {
  580. const opts = {
  581. text: title,
  582. icon: "info",
  583. buttonsStyling: false,
  584. showCancelButton: true,
  585. showConfirmButton: true,
  586. showDenyButton: !!is_cover,
  587. cancelButtonText: "取消",
  588. confirmButtonText: "新增",
  589. denyButtonText: "覆盖",
  590. customClass: {
  591. cancelButton: "btn btn-light mx-2",
  592. confirmButton: "btn btn-primary mx-2",
  593. denyButton: "btn btn-danger mx-2"
  594. },
  595. toast: false
  596. }
  597. if (is_html) {
  598. opts.html = `${title}`
  599. }
  600. Swal.fire(opts).then((result) => {
  601. console.log("CONFIRM", result)
  602. if (result.isConfirmed) {
  603. _send(false)
  604. } else if (result.isDenied) {
  605. _send(true)
  606. }
  607. });
  608. function _send(is_cover) {
  609. console.log("is_cover", is_cover, ids)
  610. IwbAjax({
  611. url: `/api/quota/start_send`,
  612. data: {
  613. ids: ids + "",
  614. is_cover: is_cover ? 'true' : 'false'
  615. },
  616. modal: $modalQuota,
  617. table: `#table_${budget_id}`
  618. })
  619. }
  620. }