setting_modal.ejs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <% if (ctx.session.sessionUser.is_admin) { %>
  2. <!--标段设置-标段属性-->
  3. <div class="modal fade" id="bd-set-1" data-backdrop="static">
  4. <div class="modal-dialog" role="document">
  5. <div class="modal-content">
  6. <div class="modal-header">
  7. <h5 class="modal-title">合同设置</h5>
  8. </div>
  9. <div class="modal-height-500" style="overflow-y: auto">
  10. <div class="modal-body">
  11. <ul class="nav nav-tabs nav-item mb-2">
  12. <li class="nav-item">
  13. <a class="nav-link active" data-toggle="tab" href="#htxx" role="tab" aria-selected="true">合同类型</a>
  14. </li>
  15. </ul>
  16. <div class="tab-content">
  17. <div class="tab-pane active" id="htxx">
  18. <div class="my-2">
  19. <a href="javascript:void(0);" class="" id="addType">新增类型</a>
  20. </div>
  21. <table class="table table-bordered">
  22. <thead><tr class="text-center">
  23. <th width="60%">名称</th>
  24. <th>操作</th>
  25. </tr>
  26. </thead>
  27. <tbody class="text-center" id="type-table">
  28. </tbody>
  29. </table>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="modal-footer">
  35. <button type="button" class="btn btn-sm btn-secondary" data-dismiss="modal">取消</button>
  36. <button type="button" class="btn btn-sm btn-primary" id="set-type-btn">确认</button>
  37. </div>
  38. </div>
  39. </div>
  40. </div>
  41. <script>
  42. $(function () {
  43. function setTypeTable(types) {
  44. $('#type-table').empty();
  45. types.forEach(type => {
  46. const typeRow = `<tr>
  47. <td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value="${type}"></td>
  48. <td>
  49. <a href="javascript:void(0);" class="btn btn-sm text-danger remove-type-btn"><i class="fa fa-remove"></i></a>
  50. </td>
  51. </tr>`;
  52. $('#type-table').append(typeRow);
  53. });
  54. }
  55. $('#bd-set-1').on('show.bs.modal', function () {
  56. $('#type-table').empty();
  57. // 看url上是否带有tender
  58. const is_tender = window.location.pathname.includes('tender') ? 1 : 0;
  59. console.log(window.location, is_tender);
  60. postData(`/sp/${spid}/contract/audit/save`, { type: 'get-contract-type', is_tender }, function (types) {
  61. setTypeTable(types);
  62. });
  63. });
  64. $('#addType').click(function(){
  65. const newType = `<tr>
  66. <td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value=""></td>
  67. <td>
  68. <a href="javascript:void(0);" class="btn btn-sm text-danger remove-type-btn"><i class="fa fa-remove"></i></a>
  69. </td>
  70. </tr>`;
  71. $('#type-table').append(newType);
  72. });
  73. $('body').on('click', '.remove-type-btn', function() {
  74. const input = $(this).parents('td').siblings('td').eq(0).children('input');
  75. input.attr('disabled', true);
  76. // 文字加删除线并移除foucs
  77. if (input.val() === '') {
  78. input.removeAttr('placeholder');
  79. }
  80. input.css('text-decoration', 'line-through');
  81. input.blur();
  82. $(this).remove();
  83. });
  84. $('#set-type-btn').click(function() {
  85. const types = [];
  86. $('#type-table tr').each(function () {
  87. const input = $(this).find('input[name="value"]');
  88. if (!input.prop('disabled')) {
  89. const value = input.val().trim();
  90. if (value) {
  91. types.push(value);
  92. }
  93. }
  94. });
  95. console.log(types);
  96. const is_tender = window.location.pathname.includes('tender') ? 1 : 0;
  97. postData(`/sp/${spid}/contract/audit/save`, { type: 'set-contract-type', contract_type: types, is_tender }, function (res) {
  98. toastr.success('设置成功');
  99. $('#bd-set-1').modal('hide');
  100. });
  101. });
  102. })
  103. </script>
  104. <% } %>