|
|
@@ -7,66 +7,109 @@
|
|
|
* @date 2019/3/19
|
|
|
* @version
|
|
|
*/
|
|
|
-function setTypeTable(types, type) {
|
|
|
- $('#'+ type + '-type-table').empty();
|
|
|
+function setTypeTable(types, type, fun = 'type') {
|
|
|
+ $('#'+ type + '-'+ fun +'-table').empty();
|
|
|
+ if (fun === 'used') {
|
|
|
+ $('#' + type + '-' + fun + '-table').append(`<tr>
|
|
|
+ <td>合同</td>
|
|
|
+ <td></td>
|
|
|
+ </tr>`);
|
|
|
+ }
|
|
|
types.forEach(t => {
|
|
|
const typeRow = `<tr>
|
|
|
<td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value="${t}"></td>
|
|
|
<td>
|
|
|
- <a href="javascript:void(0);" class="btn btn-sm text-danger remove-type-btn"><i class="fa fa-remove"></i></a>
|
|
|
+ <a href="javascript:void(0);" class="btn btn-sm text-danger remove-${fun}-btn"><i class="fa fa-remove"></i></a>
|
|
|
</td>
|
|
|
</tr>`;
|
|
|
- $('#'+ type + '-type-table').append(typeRow);
|
|
|
+ $('#'+ type + '-'+ fun +'-table').append(typeRow);
|
|
|
});
|
|
|
}
|
|
|
$(document).ready(() => {
|
|
|
autoFlashHeight();
|
|
|
- // setTypeTable(types_from === 'subProject' ? subProject_types : tender_types);
|
|
|
- // $('#bd-set-1').on('show.bs.modal', function () {
|
|
|
- // $('#type-table').empty();
|
|
|
- // // 看url上是否带有tender
|
|
|
- // const is_tender = window.location.pathname.includes('tender') ? 1 : 0;
|
|
|
- // console.log(window.location, is_tender);
|
|
|
- // postData(`/sp/${spid}/contract/audit/save`, { type: 'get-contract-type', is_tender }, function (types) {
|
|
|
- // setTypeTable(types);
|
|
|
- // });
|
|
|
- // });
|
|
|
- $('#addType').click(function(){
|
|
|
- const type = $('#types-tabs a.active').attr('type');
|
|
|
- const newType = `<tr>
|
|
|
+ const funs = ['type', 'used'];
|
|
|
+ for (const fun of funs) {
|
|
|
+ $('#add-' + fun + '-btn').click(function(){
|
|
|
+ const type = $('#' + fun + '-tabs a.active').attr('type');
|
|
|
+ const newType = `<tr>
|
|
|
<td><input class="form-control form-control-sm" name="value" placeholder="请输入值" value=""></td>
|
|
|
<td>
|
|
|
- <a href="javascript:void(0);" class="btn btn-sm text-danger remove-type-btn"><i class="fa fa-remove"></i></a>
|
|
|
+ <a href="javascript:void(0);" class="btn btn-sm text-danger remove-${fun}-btn"><i class="fa fa-remove"></i></a>
|
|
|
</td>
|
|
|
</tr>`;
|
|
|
- $('#'+ type + '-type-table').append(newType);
|
|
|
- });
|
|
|
+ $('#'+ type + '-' + fun + '-table').append(newType);
|
|
|
+ });
|
|
|
|
|
|
- $('body').on('click', '.remove-type-btn', function() {
|
|
|
- const input = $(this).parents('td').siblings('td').eq(0).children('input');
|
|
|
- input.attr('disabled', true);
|
|
|
- // 文字加删除线并移除foucs
|
|
|
- if (input.val() === '') {
|
|
|
- input.removeAttr('placeholder');
|
|
|
- }
|
|
|
- input.css('text-decoration', 'line-through');
|
|
|
- input.blur();
|
|
|
- $(this).remove();
|
|
|
- checkAndShowTypesBtn();
|
|
|
- });
|
|
|
+ $('body').on('click', '.remove-' + fun + '-btn', function() {
|
|
|
+ const input = $(this).parents('td').siblings('td').eq(0).children('input');
|
|
|
+ input.attr('disabled', true);
|
|
|
+ // 文字加删除线并移除foucs
|
|
|
+ if (input.val() === '') {
|
|
|
+ input.removeAttr('placeholder');
|
|
|
+ }
|
|
|
+ input.css('text-decoration', 'line-through');
|
|
|
+ input.blur();
|
|
|
+ $(this).remove();
|
|
|
+ checkAndShowTypesBtn(fun);
|
|
|
+ });
|
|
|
|
|
|
- $('body').on('blur', '#contract-types-set input[name="value"]', function() {
|
|
|
- checkAndShowTypesBtn();
|
|
|
- });
|
|
|
+ $('body').on('blur', '#contract-' + fun + '-set input[name="value"]', function() {
|
|
|
+ checkAndShowTypesBtn(fun);
|
|
|
+ });
|
|
|
|
|
|
- function checkAndShowTypesBtn(return_type = false) {
|
|
|
+ $('#set-' + fun + '-btn').click(function() {
|
|
|
+ const { new_subProject_types, new_tender_types } = checkAndShowTypesBtn(fun, true);
|
|
|
+ const data = {
|
|
|
+ type: 'set-contract-' + fun,
|
|
|
+ }
|
|
|
+ if (fun === 'type') {
|
|
|
+ data.contract_type = {
|
|
|
+ contract_type: new_subProject_types,
|
|
|
+ tender_contract_type: new_tender_types
|
|
|
+ };
|
|
|
+ } else if (fun === 'used') {
|
|
|
+ data.contract_used = {
|
|
|
+ contract_used: new_subProject_types,
|
|
|
+ tender_contract_used: new_tender_types
|
|
|
+ }
|
|
|
+ }
|
|
|
+ postData(`/sp/${spid}/contract/audit/save`, data, function (res) {
|
|
|
+ toastr.success('设置成功');
|
|
|
+ if (fun === 'type') {
|
|
|
+ tender_type = new_tender_types;
|
|
|
+ subProject_type = new_subProject_types;
|
|
|
+ } else if (fun === 'used') {
|
|
|
+ tender_used = new_tender_types;
|
|
|
+ subProject_used = new_subProject_types;
|
|
|
+ }
|
|
|
+ setTypeTable(new_tender_types, 'tender', fun);
|
|
|
+ setTypeTable(new_subProject_types, 'subProject', fun);
|
|
|
+ checkAndShowTypesBtn(fun);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ $('#cancel-' + fun + '-btn').click(function() {
|
|
|
+ toastr.warning('已取消改动');
|
|
|
+ if (fun === 'type') {
|
|
|
+ setTypeTable(tender_type, 'tender', fun);
|
|
|
+ setTypeTable(subProject_type, 'subProject', fun);
|
|
|
+ } else if (fun === 'used') {
|
|
|
+ setTypeTable(tender_used, 'tender', fun);
|
|
|
+ setTypeTable(subProject_used, 'subProject', fun);
|
|
|
+ }
|
|
|
+ checkAndShowTypesBtn(fun);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function checkAndShowTypesBtn(fun, return_type = false) {
|
|
|
const new_subProject_types = [];
|
|
|
const new_tender_types = [];
|
|
|
const type = ['subProject', 'tender'];
|
|
|
for (const t of type) {
|
|
|
- $('#'+ t + '-type-table tr').each(function () {
|
|
|
+ $('#'+ t + '-' + fun + '-table tr').each(function () {
|
|
|
const input = $(this).find('input[name="value"]');
|
|
|
- if (!input.prop('disabled')) {
|
|
|
+ console.log(input.val());
|
|
|
+ if (input && input.val() !== undefined && !input.prop('disabled')) {
|
|
|
const value = input.val().trim();
|
|
|
if (value) {
|
|
|
if (t === 'subProject') {
|
|
|
@@ -78,12 +121,19 @@ $(document).ready(() => {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- console.log(new_tender_types, tender_types, new_subProject_types, subProject_types);
|
|
|
- // 用lodash对比数组内容是否相同
|
|
|
- if (_.isEqual(new_tender_types.sort(), tender_types.sort()) && _.isEqual(new_subProject_types.sort(), subProject_types.sort())) {
|
|
|
- $('#show-type-btn').hide();
|
|
|
- } else {
|
|
|
- $('#show-type-btn').show();
|
|
|
+ if (fun === 'type') {
|
|
|
+ // 判断数组是否相同,但别改变原数组顺序
|
|
|
+ if (_.isEqual(_.sortBy(new_tender_types), _.sortBy(tender_type)) && _.isEqual(_.sortBy(new_subProject_types), _.sortBy(subProject_type))) {
|
|
|
+ $('#show-'+ fun +'-btn').hide();
|
|
|
+ } else {
|
|
|
+ $('#show-' + fun + '-btn').show();
|
|
|
+ }
|
|
|
+ } else if (fun === 'used') {
|
|
|
+ if (_.isEqual(_.sortBy(new_tender_types), _.sortBy(tender_used)) && _.isEqual(_.sortBy(new_subProject_types), _.sortBy(subProject_used))) {
|
|
|
+ $('#show-'+ fun +'-btn').hide();
|
|
|
+ } else {
|
|
|
+ $('#show-' + fun + '-btn').show();
|
|
|
+ }
|
|
|
}
|
|
|
if (return_type) {
|
|
|
return {
|
|
|
@@ -93,26 +143,6 @@ $(document).ready(() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $('#set-type-btn').click(function() {
|
|
|
- const { new_subProject_types, new_tender_types } = checkAndShowTypesBtn(true);
|
|
|
- postData(`/sp/${spid}/contract/audit/save`, { type: 'set-contract-type', contract_type: { contract_type: new_subProject_types, tender_contract_type: new_tender_types } }, function (res) {
|
|
|
- toastr.success('设置成功');
|
|
|
- tender_types = new_tender_types;
|
|
|
- subProject_types = new_subProject_types;
|
|
|
- setTypeTable(tender_types, 'tender');
|
|
|
- setTypeTable(subProject_types, 'subProject');
|
|
|
- checkAndShowTypesBtn();
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- $('#cancel-type-btn').click(function() {
|
|
|
- toastr.warning('已取消改动');
|
|
|
- // const is_tender = $('#types-tabs a.active').attr('type') === 'subPorjct' ? 0 : 1;
|
|
|
- setTypeTable(tender_types, 'tender');
|
|
|
- setTypeTable(subProject_types, 'subProject');
|
|
|
- checkAndShowTypesBtn();
|
|
|
- });
|
|
|
-
|
|
|
$('#contract-shenpi-set input[type="checkbox"]').change(function() {
|
|
|
postData(`/sp/${spid}/contract/setting/update`, { type: 'page_show',
|
|
|
openContractSubProjectShenpi: $('#openContractSubProjectShenpi')[0].checked,
|