12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- '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 form-control-sm" placeholder="请输入名称"></div>';
- $('#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('<div class="form-group">');
- html.push('<input type="text" id="' + a.id +'" class="form-control form-control-sm" value="'+ a.name +'">');
- html.push('</div>');
- }
- $('#companyshow').html(html.join(''));
- }
- function selectCompanyHtml(data) {
- const html = [];
- for (const s of data.select) {
- html.push('<option>'+ s.name +'</option>');
- }
- $('#company').html(html);
- }
|