'use strict'; /** * * * @author Mai * @date 2018/8/21 * @version */ // 向后端请求中间计量号 function getNewCode() { postData('/tender/'+ tenderId +'/change/newCode', { type: rulesType }, function (code) { if (code !== '') { $('#bj-code').val(code); } }); } class codeRuleSet { constructor (obj) { this.body = obj; // 切换规则组件类型 $('.rule-change', obj).change(function () { const codeType = this.selectedIndex-1; if (codeType === ruleConst.ruleType.addNo) { $('#format', obj).show(); $('#text', obj).show(); $('#text>label', obj).text('起始编号'); $('#text>input', obj).val('001'); const s = '0000000000' + 1; $('#text>input', obj).val(s.substr(s.length - $('#format>input', obj).val())); } else if (codeType === ruleConst.ruleType.text) { $('#format', obj).hide(); $('#text', obj).show(); $('#text>label', obj).text('文本'); $('#text>input', obj).val('').attr('placeholder', '请在这里输入需要的文本'); } else { $('#format', obj).hide(); $('#text', obj).hide(); } }); // 修改编号位数 $('#format>input', obj).change(function () { const s = '0000000000' + parseInt($('#text>input', obj).val()); $('#text>input', obj).val(s.substr(s.length - $(this).val())); }); // 修改连接符 $('.connector-change', obj).change(function () { const connectorType = this.options[this.selectedIndex].text; const rules = $('span>span', obj), ruleText = []; for (const r of rules) { ruleText.push($.trim(r.innerText)); } if (connectorType === '无') { $('#preview', obj).text(ruleText.join('')); } else { $('#preview', obj).text(ruleText.join(connectorType)); } connectorRule = this.options[this.selectedIndex].value; }); // 新增规则组件 $('#addRule', obj).click(function () { const codeType = $('select', obj)[1].selectedIndex-1; const rule = {rule_type: codeType}, html = []; let preview; switch (codeType) { case ruleConst.ruleType.dealCode: { if (dealCode === '') { toastr.error('当前标段合同编号为空,请选择其他组件。'); return false; } preview = dealCode; break; } case ruleConst.ruleType.tenderName: { preview = tenderName; break; } case ruleConst.ruleType.text: { rule.text = $('#text>input', obj).val(); if (rule.text === '') { toastr.error('文本内容不允许为空。'); return false; } preview = rule.text; break; } case ruleConst.ruleType.inDate: { preview = moment().format('YYYY'); break; } case ruleConst.ruleType.addNo: { rule.format = parseInt($('#format>input', obj).val()); rule.start = parseInt($('#text>input', obj).val()); if ($('#text>input', obj).val().length !== rule.format) { toastr.error('起始编号位数和自动编号位数不一致。'); return false; } const s = '0000000000'; preview = s.substr(s.length - rule.format); break; } default: { toastr.error('请选择组件再添加'); return false; } } // 更新规则 codeRule.push(rule); // 更新规则显示 html.push(''); html.push('' + preview + ''); html.push(''); html.push(''); const part = $('#ruleParts', obj).append(html.join('')); // 更新规则预览 const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : ''; const previewtext = $.trim($('#preview', obj).text()) === '' ? preview : $.trim($('#preview', obj).text()) + connectorType + preview; $('#preview', obj).text(previewtext); }); // 删除规则组件 $($('#ruleParts', obj)).on('click', 'a', function () { const index = $('a', obj).index(this); codeRule.splice(index-1, 1); $(this).parent().remove(); const rules = $('span>span', obj), ruleText = []; for (const r of rules) { ruleText.push($.trim(r.innerText)); } const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : ''; $('#preview', obj).text(ruleText.join(connectorType)); }); } } $(document).ready(() => { // 首次进入设置 let showNoNeed = false; if (cRuleFirst) { codeRule = []; showNoNeed = true; $('#setting').modal('show'); } // 设置 const ruleSet = new codeRuleSet($('div.modal-body', '#setting')); $('#setRule', '#setting').bind('click', function () { const data = { rule: ruleType, type: rulesType, connector: connectorRule, data: JSON.stringify(codeRule), }; if (codeRule.length !== 0) { $('#autoCodeShow').show(); } postData('/tender/rule', data, function () { if (cRuleFirst && showNoNeed) { $('#changeFirst').click(); $('.ml-auto a[href="#add-bj"]').click(); } else { $('#setting').modal('hide'); } }); }) $('.ml-auto').on('click', 'a', function () { const content = $(this).attr('href'); if (content === '#add-bj') { $('#add-bj-modal').modal('show') getNewCode(); if ($('#changeList').children.length === 0) { $('#addCancel').hide(); } else { $('#addCancel').show(); } $('#bj-code').removeClass('is-invalid'); } }); // 获取最新可用变更令号 $('#autoCode').click(getNewCode); // 新增变更令 确认 $('#addOk').click(function () { $(this).attr('disabled', true); if ($('#check_item').val().length === 0) { $('#check_item').addClass('is-invalid'); $('#name_error_msg').show(); $('#name_error_msg').text('检查项不能为空。'); $(this).attr('disabled', false); setTimeout(function () { $('#check_item').removeClass('is-invalid'); $('#name_error_msg').hide(); }, 2000); return; } if ($('#check_item').val().length > 255) { $('#chek_item').addClass('is-invalid'); $('#name_error_msg').show(); $('#name_error_msg').text('检查项超过255个字,请缩减。'); $(this).attr('disabled', false); setTimeout(function () { $('#check_item').removeClass('is-invalid'); $('#name_error_msg').hide(); }, 2000); return; } if ($('#check_date').val() === '') { $('#check_date').addClass('is-invalid'); $('#check_date').siblings('.invalid-feedback').show(); $('#check_date').siblings('.invalid-feedback').text('检查日期不能为空。'); $(this).attr('disabled', false); setTimeout(function () { $('#check_date').removeClass('is-invalid'); $('#check_date').siblings('.invalid-feedback').hide(); }, 2000); return; } else { // 判断日期格式 const reg = /^\d{4}-\d{2}-\d{2}$/; if (!reg.test($('#check_date').val())) { $('#check_date').addClass('is-invalid'); $('#check_date').siblings('.invalid-feedback').show(); $('#check_date').siblings('.invalid-feedback').text('检查日期格式错误,应为YYYY-MM-DD。'); $(this).attr('disabled', false); setTimeout(function () { $('#check_date').removeClass('is-invalid'); $('#check_date').siblings('.invalid-feedback').hide(); }, 2000); return; } } const data = { type: 'add', code: $('#bj-code').val(), check_item: $('#check_item').val(), check_date: $('#check_date').val(), }; if (data.code || data.code !== '') { postData(`/sp/${spid}/quality/tender/${tenderId}/inspection/save`, data, function (rst) { $('#bj-code').removeClass('is-invalid'); $('#add-bj-modal').modal('hide'); $(this).attr('disabled', false); window.location.href = `/sp/${spid}/quality/tender/${tenderId}/inspection/${rst.id}/information`; }, function () { $('#bj-code').addClass('is-invalid'); $('#bjHint').show(); $(this).attr('disabled', false); }); } }); //状态切换 $('#status_select a').on('click', function () { const status = $(this).data('val'); let url = `/sp/${spid}/quality/tender/${tenderId}/inspection`; const filterString = setChangeFilterData('quality-inspection-'+ tenderId +'-list-order', status !== 0 ? '?status='+ status : ''); if (filterString) url = url + filterString; window.location.href = url; }); // 不再显示首次使用 $('#changeFirst').click(function () { showNoNeed = false; $('#changeFirst').remove(); $('#hide_modal').show(); $('#setting').modal('hide'); postData('/tender/'+ tenderId +'/rule/first', { type: rulesType }, function () { }); }); // 排序初始化 let orderSetting = getLocalCache('quality-inspection-'+ tenderId +'-list-order'); if (!orderSetting) orderSetting = 'time|desc'; const orders = orderSetting.split('|'); $("#sort-radio input[value='"+ orders[0] +"']").prop('checked', true); $("#order-radio input[value='"+ orders[1] +"']").prop('checked', true); if (orders[0] === 'time') { $('#bpaixu').text('排序:创建时间'); } else { $('#bpaixu').text('排序:编号'); } $('#sort-radio input[name="paizhi"]').click(function () { const orderStr = $(this).val() + '|' + $('#order-radio input[name="paixu"]:checked').val(); setLocalCache('quality-inspection-'+ tenderId +'-list-order', orderStr); let link = window.location.origin + window.location.pathname; const filterData = []; if ($('#zhankai').data('status') !== '0') { filterData.push('status=' + $('#zhankai').data('status')); } filterData.push('sort='+ $(this).val()); filterData.push('order=' + $('#order-radio input[name="paixu"]:checked').val()); if (getLocalCache('account-pageSize')) { filterData.push('pageSize=' + getLocalCache('account-pageSize')); } if (filterData.length > 0) { link += '?' + filterData.join('&'); } window.location.href = link; }); $('#order-radio input[name="paixu"]').click(function () { const orderStr = $('#sort-radio input[name="paizhi"]:checked').val() + '|' + $(this).val(); setLocalCache('quality-inspection-'+ tenderId +'-list-order', orderStr); let link = window.location.origin + window.location.pathname; const filterData = []; if ($('#zhankai').data('status') !== '0') { filterData.push('status=' + $('#zhankai').data('status')); } filterData.push('sort='+ $('#sort-radio input[name="paizhi"]:checked').val()); filterData.push('order=' + $(this).val()); if (getLocalCache('account-pageSize')) { filterData.push('pageSize=' + getLocalCache('account-pageSize')); } if (filterData.length > 0) { link += '?' + filterData.join('&'); } window.location.href = link; }); $('.show-files').on('click', function () { const id = parseInt($(this).data('id')); const info = _.find(inspectionList, { id: id }); console.log(info); handleFileList(info.attList || []); }); function handleFileList(files = []) { $('#file-content').empty(); let html = ''; files.forEach((file, idx) => { html += `${file.filename}${file.username}${moment(file.upload_time).format('YYYY-MM-DD HH:mm:ss')}` }) $('#file-content').append(html); } $.subMenu({ menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list', toMenu: '#to-menu', toMiniMenu: '#to-mini-menu', key: 'menu.1.0.0', miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1', callback: function (info) { if (info.mini) { $('.panel-title').addClass('fluid'); $('#sub-menu').removeClass('panel-sidebar'); } else { $('.panel-title').removeClass('fluid'); $('#sub-menu').addClass('panel-sidebar'); } autoFlashHeight(); } }); });