| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 | 'use strict';/** * 变更令公司编辑js * * @author EllisRan. * @date 2018/11/26 * @version */$(document).ready(() => {    //提出单位编辑    $('#addcompany').click(function(){        let newinput = '<div class="form-group"><input type="text" class="form-control" placeholder="请输入名称"></div>';        $('#companyadddiv').append(newinput);    });    $('#updatecompany').click(function(){        $(this).attr('disabled','disabled');        let addcompanyArr = new Array();        $('#companyadddiv').find('.form-control').each(function(){            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('');                addCompanyHtml(result);                selectCOmpanyHtml(result);                $('#editcompany').modal('hide');                toastr.success('变更单位已更新');                $('#updatecompany').attr('disabled',false);            });        }else{            toastr.error('变更单位不能同名');            $('#updatecompany').attr('disabled',false);        }    });});function isRepeat(arr){    let hash = {};    for(let i in arr) {        if(hash[arr[i]])            return true;        hash[arr[i]] = true;    }    return false;}function addCompanyHtml(data) {    const html = [];    for (const a of data.add) {        html.push('<div class="form-group">');        html.push('<input type="text" id="' + a.id +'" class="form-control" value="'+ a.name +'">');        html.push('</div>');    }    $('#companyshow').append(html.join(''));}function selectCOmpanyHtml(data) {    const html = [];    for (const s of data.select) {        html.push('<option>'+ s.name +'</option>');    }    $('#company').html(html);}
 |