'use strict'; /** * 变更令公司编辑js * * @author EllisRan. * @date 2018/11/26 * @version */ $(document).ready(() => { //提出单位编辑 $('#addcompany').click(function(){ let newinput = '
'; $('#companyadddiv').append(newinput); }); $('#updatecompany').click(function(){ $(this).attr('disabled','disabled'); let addcompanyArr = new Array(); $('#companyadddiv').find('.form-control').each(function(){ if ($.trim($(this).val()) !== '') { addcompanyArr.push($(this).val()); } }); var updatecompanyArr = new Array(); var updatecompanyidArr = new Array(); $('#companyshow').find('.form-control').each(function(){ updatecompanyArr.push($(this).val()); updatecompanyidArr.push($(this).attr('id')); }); //判断是否有重名情况再提交 let flag = isRepeat(addcompanyArr.concat(updatecompanyArr)); if(!flag){ const data = { tid: $('#tenderId').val(), uci:updatecompanyidArr.length !== 0 ? updatecompanyidArr : '', uc:updatecompanyArr.length ? updatecompanyArr : '', ac:addcompanyArr.length !== 0 ? addcompanyArr : '' }; postData('/change/update/company', data, function (result) { $('#companyadddiv').html(''); updateCompanyHtml(result); selectCompanyHtml(result); $('#editcompany').modal('hide'); toastr.success('变更单位已更新'); $('#updatecompany').attr('disabled',false); changeInfo.company = $('#company').val(); judgeChange(); }); }else{ toastr.error('变更单位不能同名'); $('#updatecompany').attr('disabled',false); } }); }); function isRepeat(arr){ let hash = {}; for(let i in arr) { if($.trim(arr[i]) !== '' && hash[arr[i]]) return true; hash[arr[i]] = true; } return false; } function updateCompanyHtml(data) { const html = []; for (const a of data.select) { html.push('