UNPKG

ttk-app-core

Version:
656 lines (642 loc) 21.5 kB
import { Map, List, fromJS } from 'immutable' import * as data from './data' import { fetch } from 'edf-utils' //import utils from 'edf-utils' export function getMeta() { return { name: 'root', component: 'Layout', className: 'ttk-voucher-app-document', id: 'ttk-voucher-app-document', onMouseDown: '{{function(e){$onMouseDown(e)}}}', children: [{ name: 'header', component: 'Layout', className: 'ttk-voucher-app-document-header', children: [{ name: 'left', component: 'Layout', className: 'ttk-voucher-app-document-header-left', children: [{ name: 'common', component: 'Popover', trigger: 'hover', placement: 'bottom', className: 'Popover-ttk-voucher-app-document', content: { name: 'menu', component: 'Menu', onClick: '{{$commonMenuClick}}', className: 'Popover-ttk-voucher-app-document-useCommon', children: [{ name: 'useCommon', component: 'Menu.Item', key: 'useCommon', className: 'common', disabled: '{{$isCommonTemplateDisabled()}}', children: '常用模版' }, { name: 'saveCommon', component: 'Menu.Item', className: 'common', key: 'saveCommon', children: '存为模版' }] }, children: { name: 'internal', component: 'Button', className: 'ttk-voucher-app-document-header-left-useCommon', children: ['凭证模版', { name: 'down', component: 'Icon', fontFamily: 'edficon', type: 'xia', }] } }, { name: 'saveAndNew', component: 'Button', type: 'primary', refs: 'saveAndNew', onClick: '{{$saveAndNew}}', disabled: "{{data.other.btnStatus}}", _visible: "{{$isDisplayButton('save')}}", children: '保存并新增' }, { name: 'save', component: 'Button', onClick: '{{$save}}', disabled: "{{data.other.btnStatus}}", _visible: "{{$isDisplayButton('save')}}", children: '保存' }, { name: 'add', type: 'primary', component: 'Button', onClick: '{{$newCertificate}}', _visible: "{{$isDisplayButton('add')}}", children: '新增' }, { name: 'audit', component: 'Button', _visible: "{{$isDisplayButton('audit')}}", onClick: '{{$audit}}', children: '{{$getAuditText()}}' }, { name: 'print', component: 'Button', _visible: "{{$isDisplayButton('print')}}", children: '打印', onClick: '{{$print}}' }, { name: 'more', component: 'Dropdown', _visible: "{{$isDisplayButton('more')}}", overlay: { name: 'menu', component: 'Menu', className: 'ttk-voucher-app-document-header-left-useCommon', onClick: '{{$moreMenuClick}}', children: [{ name: 'del', component: 'Menu.Item', key: 'del', disabled: "{{$isDisplayButton('del')}}", children: '删除' }, { name: 'insert', component: 'Menu.Item', key: 'insert', _visible: "{{data.other.editStatus != data.STATUS_VIEW ? true : false}}", children: '插入凭证' }] }, children: { name: 'internal', component: 'Button', className: 'ttk-voucher-app-document-header-left-more', children: ['更多', { name: 'down', component: 'Icon', fontFamily: 'edficon', type: 'xia' }] } }] }, { name: 'right', component: 'Layout', className: 'ttk-voucher-app-document-header-right', children: [{ name: 'shortcut', component: 'Popover', placement: "bottom", className: 'ttk-voucher-app-document-header-right-jianpan', arrowPointAtCenter: true, content: { name: 'keys', component: 'ShortKey' }, title: null, children: { component: 'Icon', className: 'ttk-voucher-app-document-header-right-iconbutton', fontFamily: 'edficon', type: 'jianpan', // iconFontFamily: 'edficon', // type: 'jianpan', //icon: 'key', title: '快捷键', } }, { name: 'moreVoucher', component: 'Button', onClick: '{{$certificateManagement}}', children: '凭证管理' }, { name: 'page', component: 'Button.Group', className: 'page-prev-next', children: [{ name: 'prev', component: 'Button', icon: 'left', disabled: '{{data.form.prevDisalbed}}', onClick: '{{$loadPrevCertificate}}' }, { name: 'next', component: 'Button', icon: 'right', disabled: '{{data.form.nextDisalbed}}', onClick: '{{$loadNextCertificate}}' }] }] }] }, { name: 'title', component: 'Layout', className: 'ttk-voucher-app-document-title', children: [{ name: 'left', component: 'Layout', className: 'ttk-voucher-app-document-title-left', }, { name: 'center', component: '::div', className: 'ttk-voucher-app-document-title-center', children: { name: 'title', component: '::h1', children: '记账凭证', } }, { name: 'right', component: 'Layout', className: 'ttk-voucher-app-document-title-right', children: [] },{ name: 'audited', component: '::img', className: 'ttk-voucher-app-document-title-right-tag', src: require('./img/audited.png'), _visible: '{{$getAudited()}}' }] }, { name: 'formHeader', component: 'Layout', className: 'ttk-voucher-app-document-form-header', children: [{ name: 'code', component: 'Layout', className: 'ttk-voucher-app-document-form-header-code', children: ['记字第', { name: 'code', component: 'Input', disabled: '{{ data.form.codeDisabled }}', value: '{{data.form.code}}', regex: '^[0-9]+$', maxlength: '4', onPressEnter: "{{function(){$onPressEnter('code')}}}", //onChange: "{{function(e){$sf('data.form.code',e.target.value)}}}", onChange: "{{function(e){/\^[0-9]+$/.test(e.target.value+'') ? $sf('data.form.code',e.target.value) : '';$onFieldChange(_ctrlPath, data.form.code, e.target.value)}}}" }] }, { name: 'date', component: 'Layout', className: 'ttk-voucher-app-document-form-header-date', children: ['日期', { name: 'date', component: 'DatePicker', allowClear: false, className: 'ttk-voucher-app-document-form-header-date-picker', value: '{{$stringToMoment(data.form.date)}}', onChange: `{{function(d){$sf('data.form.date',$momentToString(d,'YYYY-MM-DD')); $onFieldChange(_ctrlPath, data.form.date, $momentToString(d,'YYYY-MM-DD'))}}}`, disabledDate: `{{function(current){ var disabledDate = new Date(data.other.disabledDate) return current && current.valueOf() < disabledDate }}}`, disabled: '{{ data.form.dateDisabled }}' }] }, { name: 'titleshow', component: 'Layout', _visible: false, className: 'ttk-voucher-app-document-form-header-titleshow', children: '{{$renderFormHeaderTitleShow(data.form.date)}}' }, { name: 'attachment', component: 'Layout', className: 'ttk-voucher-app-document-form-header-attachment', children: ['附单据', { name: 'attachment', component: 'Input.Number', defaultValue: 0, maxlength: 2, className: 'ttk-voucher-app-document-form-header-attachment-number', regex: '^([0-9]+)$', disabled: '{{ data.form.attachmentDisabled }}', value: '{{ data.form.attachCount }}', onPressEnter: "{{function(){$onPressEnter('attachment')}}}", onBlur: "{{function(v){$onFieldChange(_ctrlPath, data.form.attachCount, v)}}}" //onChange: "{{function(v){$sf('data.form.attachCount',v)}}}" }, '张', { name: 'attachmentItem', component: 'Attachment', //placement: 'right', status: '{{data.form.attachmentStatus}}', data: '{{data.form.attachmentFiles}}', onDownload: '{{$download}}', loading: '{{data.form.attachmentLoading}}', visible: '{{data.form.attachmentVisible}}', onDel: '{{$delFile}}', uploadProps: { action: '/v1/edf/file/upload', //上传地址, beforeUpload:'{{function(){return false}}}', //mock 上传数据 headers: '{{$getAccessToken()}}', accept: '', //接受的上传类型 //attachementVisible: '{{$attachementVisible}}' data: { "fileClassification": "ATTACHMENT" }, onChange: '{{$attachmentChange}}', } }] }] }, { name: 'details', component: 'DataGrid', className: 'ttk-voucher-app-document-form-details', headerHeight: 49, rowHeight: 60, footerHeight: 60, showBtnWidth: true, isFix: true, // height: '410px', rowsCount: '{{data.form.details.length}}', enableAddDelrow: '{{$isRowOperation()}}', onAddrow: "{{$addRow('details')}}", onDelrow: "{{$delRow('details')}}", enableUpDownrow: '{{$isRowOperation()}}', onUprow: "{{$upRow('details')}}", onDownrow: "{{$downRow('details')}}", startSequence: 1, readonly: false, onKeyDown: '{{$selfGridKeydown}}', scrollToRow: '{{data.other.detailsScrollToRow}}', columns: [{ name: 'summary', component: 'DataGrid.Column', columnKey: 'summary', width: 60, flexGrow: 1, header: { name: 'header', component: 'DataGrid.Cell', children: [{ name: 'label', component: '::label', className: 'ttk-voucher-app-document-form-details-label', children: '摘要' }] }, cell: { name: 'cell', component: "{{$isReadOnly(_ctrlPath) ? 'DataGrid.TextCell' : $isFocus(_ctrlPath)?'Select':'DataGrid.TextCell' }}", mode: 'combobox', className: "{{$getCellClassName(_ctrlPath)+' summaryleft'}}", getPopupContainer:'{{function(){return document.querySelector(".ttk-voucher-app-document")}}}', filterOption: "{{$filterOptionSummary}}", defaultActiveFirstOption: false, showArrow: false, align: 'left', value: `{{{ if(!data.form.details[_rowIndex].summary) return var ret = (data.form.details[_rowIndex].summary.name || data.form.details[_rowIndex].summary) return ret }}}`, onChange: `{{$onSummaryChange(_rowIndex)}}`, onSelect: `{{$onSummarySelect(_ctrlPath,_rowIndex, data.form.details[_rowIndex], data.other.summarys)}}`, onFocus: "{{function(){$onFieldFocus(_ctrlPath)}}}", children: { name: 'option', component: 'Select.Option', className: 'ttk-voucher-app-document-form-details-account', key: "{{ data.other.summarys && data.other.summarys[_lastIndex].name }}", children: '{{data.other.summarys && data.other.summarys[_lastIndex].name }}', _power: 'for in data.other.summarys' }, _excludeProps: "{{$isFocus(_ctrlPath)? ['onClick'] : ['children'] }}", _power: '({rowIndex})=>rowIndex' }, footer: { name: 'footer', component: '::span', className: 'total-footer', children: "{{ $getTotal(data.form.details)}}" } }, { name: 'accountingSubject', component: 'DataGrid.Column', columnKey: 'accountingSubject', width: 60, flexGrow: 1, header: { name: 'header', component: 'DataGrid.Cell', children: [{ name: 'label', component: '::label', className: 'ttk-voucher-app-document-form-details-label', children: '会计科目' }] }, cell: { name: 'cell', component: "{{$getDynamicComponent(_ctrlPath)}}", className: "{{$isReadOnly(_ctrlPath) == false ? $getCellClassName(_ctrlPath) : ''}}", getPopupContainer:'{{function(){return document.querySelector(".ttk-voucher-app-document")}}}', filterOption: '{{$filterOption}}', showArrow: false, style: { overflowY: 'auto' }, align: 'left', value: `{{{ if(!data.form.details[_rowIndex].accountingSubject) return return data.form.details[_rowIndex].accountingSubject.id }}}`, onFocus: "{{function(){$onFieldFocus(_ctrlPath)} }}", onSelect: "{{$onSubjectSelect(_ctrlPath, _rowIndex, data.other.accountingSubjects)}}", children: { name: 'option', component: 'Select.Option', className: 'ttk-voucher-app-document-form-details-account', value: "{{ data.other.accountingSubjects && data.other.accountingSubjects[_lastIndex].id }}", title: '{{data.other.accountingSubjects && data.other.accountingSubjects[_lastIndex].codeAndName }}', children: '{{data.other.accountingSubjects && data.other.accountingSubjects[_lastIndex].codeAndName }}', _power: 'for in data.other.accountingSubjects' }, dropdownFooter: { name: 'add', type: 'default', component: 'Button', className: 'ttk-voucher-app-document-form-details-account-add', style: { width: '100%', borderRadius: '0', height: '50px' }, children: [{ name: 'addIcon', component: 'Icon', className: 'ttk-voucher-app-document-form-details-account-add-icon', fontFamily: 'edficon', type: 'xinzengkemu' }, '新增科目'], onClick: '{{$addSubject(_rowIndex)}}' }, _excludeProps: "{{$isFocus(_ctrlPath)? ['onClick'] : ['children'] }}", _power: '({rowIndex})=>rowIndex', }, }, { name: 'quantityAndForeignCurrency', component: 'DataGrid.Column', columnKey: 'quantityAndForeignCurrency', _visible: '{{!!data.other.isDisplayQuantityColumn}}', disabled: true, width: '{{data.other.quantityAndForeignCurrencyWidth}}', header: { name: 'header', component: 'DataGrid.Cell', children: [{ name: 'label', component: '::label', className: 'ttk-voucher-app-document-form-details-label', children: '{{data.other.quantityAndCurrencyTitle}}' }] }, cell: { name: 'cell', component: "QuanAndForeCurrency", noTabKey: true, className: "{{$getCellClassName(_ctrlPath) }}", value: '{{data.form.details[_rowIndex].quantityAndForeignCurrency}}', _power: '({rowIndex})=>rowIndex', } }, { name: 'debitAmount', component: 'DataGrid.Column', columnKey: 'debitAmount', width: 250, numberOnly: true, header: { name: 'header', component: 'MoneyCellHeader', className: 'ttk-voucher-app-document-form-details-label', title: '借方金额' }, cell: { name: 'cell', component: "{{$isReadOnly(_ctrlPath) ? 'MoneyCell' :($isFocus(_ctrlPath)?'Input.Number':'MoneyCell')}}", className: "{{$getCellClassName(_ctrlPath) }}", value: "{{(data.form.details[_rowIndex].debitAmount!=undefined && data.form.details[_rowIndex].debitAmount.toString()=='0') ? '' : data.form.details[_rowIndex].debitAmount}}", onChange: "{{$amountChange(_ctrlPath)}}", onFocus: "{{function(){$onFieldFocus(_ctrlPath)}}}", onBlur: "{{$amountBlur(_ctrlPath)}}", executeBlur: true, precision: 2, numberOnly: true, interceptTab: true, //regex: '^(-?[0-9]+)(?:\.[0-9]{1,2})?$', _power: '({rowIndex})=>rowIndex', }, footer: { name: 'footer', component: 'MoneyCell', value: "{{$sum(data.form.details, 'debitAmount')}}" } }, { name: 'creditAmount', component: 'DataGrid.Column', columnKey: 'creditAmount', width: 250, header: { name: 'header', component: 'MoneyCellHeader', className: 'ttk-voucher-app-document-form-details-label', title: '贷方金额' }, cell: { name: 'cell', component: "{{$isReadOnly(_ctrlPath) ? 'MoneyCell' :($isFocus(_ctrlPath)?'Input.Number':'MoneyCell')}}", className: "{{$getCellClassName(_ctrlPath) }}", value: "{{(data.form.details[_rowIndex].creditAmount!=undefined && data.form.details[_rowIndex].creditAmount.toString() == '0') ? '' : data.form.details[_rowIndex].creditAmount}}", onChange: "{{$amountChange(_ctrlPath)}}", onFocus: "{{function(){$onFieldFocus(_ctrlPath)}}}", onBlur: "{{$amountBlur(_ctrlPath)}}", executeBlur: true, precision: 2, numberOnly: true, interceptTab: true, //regex: '^(-?[0-9]+)(?:\.[0-9]{1,2})?$', _power: '({rowIndex})=>rowIndex' }, footer: { name: 'footer', component: 'MoneyCell', value: "{{$sum(data.form.details, 'creditAmount')}}" } }] }, { name: 'footer', component: 'Layout', className: 'ttk-voucher-app-document-footer', children: [{ name: 'left', component: 'Layout', className: 'ttk-voucher-app-document-footer-left', children: [{ name: 'creator', component: '::h3', children: "{{ '制单人:' + (data.form.creator ? data.form.creator : '') }}", style: { marginRight: 150 } }, { name: 'approver', component: '::h3', children: "{{ '审核人:' + (data.form.auditor ? data.form.auditor : '') }}", }] }, { name: 'right', component: 'Layout', className: 'ttk-voucher-app-document-footer-right', children: [{ name: 'saveAndNew', component: 'Button', type: 'primary', onClick: '{{$saveAndNew}}', disabled: "{{data.other.btnStatus}}", _visible: "{{$isDisplayButton('save')}}", children: '保存并新增' }, { name: 'save', component: 'Button', onClick: '{{$save}}', disabled: "{{data.other.btnStatus}}", _visible: "{{$isDisplayButton('save')}}", children: '保存', style: { width: 80 } }] }] }] } } //空的"数量/外币"字段 export const blankQuantityAndForeignCurrency = { isCalcQuantity: false, isCalcMulti: false, quantity: 0, price: 0, origAmount: 0, exchangeRate: 1, amount: 0, currency: undefined, unitName: '' } //空的凭证分录 export const blankVoucherItem = { summary: '', accountingSubject: undefined, debitAmount: undefined, creditAmount: '' } export function getInitState() { return { data: { form: { details: [ blankVoucherItem, blankVoucherItem, blankVoucherItem, blankVoucherItem, blankVoucherItem ], adjunctInfo: { album: [], isVisible: false, adjunctSize: 0, }, isAttachCount: true, //是否增加附件的数量(自动修改附件文本框的值) attachCount: 0, enclosures: [], attachmentFiles: fromJS([]), attachmentStatus: 0, //附件status 0: 上传 1: 只读 docType: '记', certificateStatus: data.STATUS_VOUCHER_NOT_AUDITED, //单据状态 审核或未审核 codeDisabled: false, dateDisabled: false, attachmentDisabled: false, prevDisalbed: false, nextDisalbed: false, attachmentLoading: false, //附件上传状态 attachmentVisible: false //附件popover显示状态 }, total: { }, other: { accountingSubjects: [], summarys: [], editStatus: data.ADD_STATUS, //默认为新增 mouseHoverRow: undefined, //鼠标当前悬停的行信息 isShow: false, //控制数量外币列显隐 index: 0, //当前操作行 quantityAndForeignCurrencyTitle: '数量/外币', quantityAndForeignCurrencyWidth: 120, isDisplayQuantityColumn: false, hidePopover:false, summaryWidth: 100, isInsert: false, //是否为插入凭证 templates: [], btnStatus: false, //按钮置灰,防止重复提交 detailsScrollToRow: 0, isClickCancelBtn: false, // 是否点击会计科目列的辅助取消按钮 defaultLength: 5 //默认初始行数 } } } } export const STATUS_VOUCHER_NOT_AUDITED = 1000020001 //未审核 export const STATUS_VOUCHER_AUDITED = 1000020002 //已审核 export const STATUS_VOUCHER_REJECTED = 1000020003 //已驳回 export const ADD_STATUS = 1 //新增 export const VIEW_STATUS = 2 //查看 export const EDIT_STATUS = 3 //编辑 export const MOVEROW_UP = 0 //向上移动行 export const MOVEROW_DOWN = 1 //向下移动行 export const ARROWUP = 38 //上键 export const ARROWDOWN = 40 //下键 export const ARROWLEFT = 37 //左键 export const ARROWRIGHT = 39 //右键 export const MAX_ATTACH_COUNT = 100 //附件数上限 export const ALREADY_FIRST_CERTIFICATE = 70080 //已经是第一张凭证 export const ALREADY_LAST_CERTIFICATE = 70081 //已经是最后一张凭证 export const NOT_FOUND_CERTIFICATE = 70037 //没有找到对应凭证 export const ACCOUNTTYPE_ASSETS = 5000010001 //资产 export const ACCOUNTTYPE_LIABILITIES = 5000010002 //负债 export const ACCOUNTTYPE_COMMON = 5000010003 //共同 export const ACCOUNTTYPE_RIGHTSANDINTERSETS = 5000010004 //权益 export const ACCOUNTTYPE_COST = 5000010005 //成本 export const ACCOUNTTYPE_PROFITANDLOSS = 5000010006 //损益