ttk-app-core
Version:
enterprise develop framework
1,267 lines (1,157 loc) • 45.6 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { TableOperate, Select, Button, Modal, Icon, PrintOption, FormDecorator, Popover } from 'edf-component'
import utils from 'edf-utils'
import sortSearchOption from './utils/sortSearchOption'
import moment from 'moment'
import SortProof from './components/SortProof'
import config from './config'
import { fromJS } from 'immutable'
const Option = Select.Option
import { consts } from 'edf-consts'
import table from '../../../component/components/table/table'
class action {
constructor(option) {
this.metaAction = option.metaAction
this.config = config.current
this.webapi = this.config.webapi
this.voucherAction = option.voucherAction
}
onInit = ({ component, injections }) => {
this.component = component
this.injections = injections
let addEventListener = this.component.props.addEventListener
this.changeSipmleDate = false
if (addEventListener) {
addEventListener('onTabFocus', :: this.onTabFocus)
addEventListener('enlargeClick', () => this.onResize({}))
}
injections.reduce('init')
if (this.component.props.initSearchValue) {
if (this.component.props.initSearchValue.date_end || this.component.props.initSearchValue.date_start) {
this.changeSipmleDate = true
}
this.linkInPage(this.component.props.initSearchValue)
} else {
this.load()
}
}
onTabFocus = async (params) => {
params = params.toJS()
if (params.accessType == 1 && params.initSearchValue) {
this.linkInPage(params.initSearchValue)
} else {
await this.initDate()
this.sortParmas()
}
// this.showPickerDidMount()
}
linkInPage = (initSearchValue) => {
const {
accountId, //--科目ID
endCode, //--终止凭证号
startCode, //--起始凭证号
date_end, //期间终止
date_start, //期间起始
docIds, //--凭证ID列表
summary, //--摘要
voucherState, //--单据状态
sourceVoucherTypeId, //--单据类型 -- 单据来源
simpleCondition //简单查询
} = initSearchValue
this.injections.reduce('update', {
path: 'data.searchValue',
value: {
accountId, //--科目ID
endCode, //--终止凭证号
startCode, //--起始凭证号
date_end, //期间终止
date_start, //期间起始
docIds, //--凭证ID列表
summary, //--摘要
voucherState, //--单据状态
sourceVoucherTypeId, //--单据类型 -- 单据来源
simpleCondition, //简单查询
}
})
this.sortParmas(null, null, null, 'init', true)
const { enabledMonth, enabledYear } = this.metaAction.context.get('currentOrg')
if (enabledMonth && enabledYear) {
this.injections.reduce('update', {
path: 'data.other.enableddate',
value: utils.date.transformMomentDate(`${enabledYear}-${enabledMonth}`)
})
}
}
componentDidMount = () => {
this.onResize()
// this.showPickerDidMount()
const win = window
if (win.addEventListener) {
win.addEventListener('resize', this.onResize, false)
} else if (win.attachEvent) {
win.attachEvent('onresize', this.onResize)
} else {
win.onresize = this.onResize
}
}
getTableScroll = () => {
try {
let tableOption = this.metaAction.gf('data.tableOption').toJS()
let dom = document.getElementsByClassName('app-proof-of-list-Body')[0]
let tableDom
if (!dom) {
return
}
tableDom = dom.getElementsByClassName('ant-table-tbody')[0];
if (tableDom && dom) {
let num = dom.offsetHeight - tableDom.offsetHeight
if (num < 45) {
const width = dom.offsetWidth
const height = dom.offsetHeight
this.injections.reduce('setTableOption', { ...tableOption, y: height - 39, containerWidth: width - 200 })
} else {
delete tableOption.y
this.injections.reduce('update', { path: 'data.tableOption', value: tableOption })
}
}
} catch (err) {
// console.log(err)
}
}
onResize = (type) => {
let keyRandom = Math.floor(Math.random() * 10000)
this.keyRandom = keyRandom
//const tableOption = this.metaAction.gf('data.tableOption').toJS()
setTimeout(() => {
if (this.keyRandom == keyRandom) {
let dom = document.getElementsByClassName('app-proof-of-list-Body')[0]
if (!dom) {
if (type) {
return
}
setTimeout(() => {
this.onResize()
}, 20)
} else {
let tableDom = dom.getElementsByClassName('ant-table-tbody')[0];
let num = dom.offsetHeight - tableDom.offsetHeight
let tableOption = this.metaAction.gf('data.tableOption').toJS()
if (num < 45) {
const width = dom.offsetWidth
const height = dom.offsetHeight
this.injections.reduce('setTableOption', { ...tableOption, y: height - 39, containerWidth: width - 200 })
} else {
delete tableOption.y
this.injections.reduce('update', { path: 'data.tableOption', value: tableOption })
}
}
}
}, 100)
}
refreshBtnClick = () => {
this.sortParmas()
}
getColumnsItem = (type, width) => {
const data = this.metaAction.gf('data').toJS()
const columns = [{
title: {
name: 'sort',
component: 'TableSort',
sortOrder: data.sort.userOrderField == "voucherDate" ? data.sort.order : null,
handleClick: (e) => { this.sortChange("voucherDate", e) },
title: '日期',
},
width: width - 1,
dataIndex: 'voucherDate',
key: 'voucherDate',
className: 'table_center',
render: this.rowSpan
}, {
title: {
name: 'sort',
component: 'TableSort',
sortOrder: data.sort.userOrderField == "docCode" ? data.sort.order : null,
handleClick: (e) => { this.sortChange("docCode", e) },
title: '凭证字号',
},
width: width - 1,
className: 'table_center',
dataIndex: 'docTypeAndCode',
key: 'docTypeAndCode',
render: this.rowSpan2
}]
return columns.find(item => {
return item.dataIndex == type
})
}
needAlignType = (key) => {
const right = ['amountSum', 'origAmount', 'amountDr', 'price', 'amountCr']
const left = ['summary', 'accountCodeName', 'currencyAndExchangeRate', 'sourceVoucherCode', 'creator', 'auditor']
const center = ['quantity', 'attachedNum', 'voucherStateName', 'unitName']
let className = right.includes(key) ? 'right' : left.includes(key) ? 'left' : 'center'
return className
}
renderColumns = () => {
const tableSetting = this.metaAction.gf('data.other.columnDto').toJS()
const tableOption = this.metaAction.gf('data.tableOption').toJS()
const arr = []
let code = this.metaAction.gf('data').toJS().other.code
tableSetting.forEach(data => {
let item = this.getColumnsItem(data.fieldName, data.width)
if (!data.isVisible) {
return
}
if (item) {
arr.push(item)
} else if (data.isHeader == true) {
arr.push({
title: data.caption,
key: data.fieldName,
width: data.width,
code: code,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
render: (text, record, index) => this.rowSpan(text, record, index, data.fieldName)
})
} else {
if (data.fieldName == 'accountCodeName') {
arr.push({
title: data.caption,
key: data.fieldName,
width: data.width,
code: code,
dataIndex: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
render: this.normalTdRender2
})
} else {
arr.push({
title: data.caption,
key: data.fieldName,
width: data.width,
code: code,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
render: (text, record, index) => this.normalTdRender(text, record, index, data.fieldName)
})
}
}
})
arr.push({
title: (
<Icon
name="columnset"
fontFamily='edficon'
className='app-proof-of-list-columnset'
type="youcezhankailanmushezhi"
onClick={() => this.showTableSetting({ value: true })}
/>
),
key: 'voucherState',
dataIndex: 'voucherState',
fixed: 'right',
className: 'table_fixed_width',
width: 87,
render: (text, record, index) => this.operateCol(text, record, index)
})
return arr
}
transformThoundsNumber = (text, key) => {
const arr = ['amountCr', 'amountDr', 'origAmount', 'price', 'amountSum', 'quantity']
if (arr.includes(key)) {
if (!text || parseFloat(text) == 0 || isNaN(parseInt(text))) {
return ''
}
if (key == 'price' || key == 'quantity') {
return utils.number.format(text, 6)
} else {
return utils.number.format(text, 2)
}
} else {
return text
}
}
normalTdRender = (text, record, index, key) => {
return <span className="app-proof-of-list-td-con" title={this.transformThoundsNumber(text, key)}>{this.transformThoundsNumber(text, key)}</span>
}
normalTdRender2 = (text) => {
return <span title={text} className="app-proof-of-list-td-con" title={text}>{text}</span>
}
// 设置表格固定高度
// renderDid = ()=>{
// try{
// let container = document.getElementsByClassName('app-proof-of-list')[0].offsetHeight
// let footer = document.getElementsByClassName('app-proof-of-list-footer')[0].offsetHeight
// let header = document.getElementsByClassName('mk-search')[0].offsetHeight
// let tableHeader = document.getElementsByClassName('ant-table-header')[0].offsetHeight
// // 20是padding值
// let height = container - header - footer - tableHeader - 20
// let prevHeight = this.metaAction.gf('data.tableOption.y')
// if( prevHeight == height ){
// return
// }
// // this.injections.reduce('setTableScroll', height)
// }catch(err){
// // console.log(err) dom 没有发现时会报错
// }
// }
getNormalSearchValue = () => {
const data = this.metaAction.gf('data.searchValue').toJS()
let date = [data.date_start, data.date_end]
return { date, simpleCondition: data.simpleCondition }
}
combineColumnProp = (data) => {
if (!data) return []
let newDataArray = []
data.forEach((ele, index) => {
newDataArray.push({
"isVisible": ele.isVisible,
"id": ele.id,
'ts': ele.ts
})
})
return newDataArray
}
closeTableSetting = () => {
this.injections.reduce('tableSettingVisible', { value: false })
}
resetTableSetting = async () => {
const code = this.metaAction.gf('data').toJS().other.code
let res = await this.webapi.docManage.reInitByUser({ code: code })
await this.sortParmas(null, null, null, 'init')
const data = this.metaAction.gf('data').toJS()
this.injections.reduce('settingOptionsUpdate', { visible: false, data: data.other.columnDto })
}
showTableSetting = async ({ value, data }) => {
this.injections.reduce('update', {
path: 'data.showTableSetting',
value: false
})
const preData = this.metaAction.gf('data.other.columnDto')
if (value === false) {
this.injections.reduce('update', {
path: 'data.other.columnDto',
value: data
})
const columnSolution = await this.webapi.docManage.findByParam({ code: 'docList' })
if (columnSolution) {
let columnSolutionId = columnSolution.id
const ts = this.metaAction.gf('data.other.ts')
const columnDetail = await this.webapi.docManage.updateWithDetail({
"id": columnSolutionId,
"columnDetails": this.combineColumnProp(data),
ts: ts
})
if (columnDetail) {
this.injections.reduce('settingOptionsUpdate', { visible: value, data: columnDetail.columnDetails })
} else {
this.metaAction.sf('data.other.columnDto', preData)
}
} else {
this.metaAction.sf('data.other.columnDto', preData)
}
}
else {
this.injections.reduce('tableSettingVisible', { value, data: data })
}
}
resizeEnd = async (params) => {
const code = this.metaAction.gf('data').toJS().other.code
params.code = code
let res = await this.webapi.docManage.batchUpdate(params)
this.metaAction.sf('data.other.columnDto', fromJS(res[0].columnDetails))
}
load = () => {
const { enabledMonth, enabledYear } = this.metaAction.context.get('currentOrg')
if (enabledMonth && enabledYear) {
this.injections.reduce('update', {
path: 'data.other.enableddate',
value: utils.date.transformMomentDate(`${enabledYear}-${enabledMonth}`)
})
}
// this.initDate(`${enabledYear}-${enabledMonth}`)
this.sortParmas(null, null, null, 'init')
// 获取禁用时间
}
//初始化选择时间
initDate = async () => {
const changeSipmleDate = this.changeSipmleDate
if (!changeSipmleDate) {
const res = await this.webapi.docManage.getDisplayDate()
this.injections.reduce('updateArr', [
{
path: 'data.searchValue.date_start',
value: utils.date.transformMomentDate(res.DisplayDate)
},
{
path: 'data.searchValue.date_end',
value: utils.date.transformMomentDate(res.DisplayDate)
}
])
}
return
}
// 高级搜索确定是简单搜索条件清除
searchValueChange = (value) => {
let actionContent
if (value.accountId) actionContent = actionContent + ' 科目查询'
if (value.summary) actionContent = actionContent + ' 摘要查询'
if (value.startCode || value.endCode) actionContent = actionContent + ' 凭证号查询'
if (value.voucherState) actionContent = actionContent + ' 状态查询'
_hmt && _hmt.push(['_trackEvent', '财务', '填制凭证', '高级查询+' + actionContent])
let prevValue = this.metaAction.gf('data.searchValue').toJS()
//时间是必填项不可清空
if (!value.date_end) {
value.date_end = moment().endOf('month') //期间终止
}
if (!value.date_start) {
value.date_start = moment().startOf('month') //期间开始
}
this.injections.reduce('searchUpdate', { ...prevValue, ...value, simpleCondition: null })
const pages = this.metaAction.gf('data.pagination').toJS()
this.sortParmas({ ...prevValue, ...value, simpleCondition: null }, { ...pages, 'currentPage': 1 })
this.changeSipmleDate = true
}
sortParmas = (search, pages, order, type, noInitDate) => {
// 处理搜索参数
if (!search) {
search = this.metaAction.gf('data.searchValue').toJS()
}
if (!pages) {
pages = this.metaAction.gf('data.pagination').toJS()
}
if (!order) {
order = this.metaAction.gf('data.sort').toJS()
}
const changeData = {
'date_start': {
'startYear': (data) => data ? data.year() : null,
'startPeriod': (data) => data ? data.month() + 1 : null
},
'date_end': {
'endYear': (data) => data ? data.year() : null,
'endPeriod': (data) => data ? data.month() + 1 : null
}
}
const searchValue = sortSearchOption(search, changeData)
const page = sortSearchOption(pages, null, ['total', 'totalCount', 'totalPage'])
// 简单查询没有值得情况下穿null不要穿''
if (searchValue.simpleCondition === '') {
searchValue.simpleCondition = null
}
if (searchValue.endCode === '') {
searchValue.endCode = null
}
if (searchValue.startCode === '') {
searchValue.startCode = null
}
if (type == 'get') {
return { ...searchValue, page, ...order }
}
if (type == 'init') {
this.initData({ ...searchValue, page, ...order }, noInitDate)
}
else {
this.requestData({ ...searchValue, page, ...order })
}
}
requestData = async (params) => {
let loading = this.metaAction.gf('data.loading')
if (!loading) {
this.injections.reduce('tableLoading', true)
}
const response = await this.webapi.docManage.query(params)
this.injections.reduce('tableLoading', false)
this.injections.reduce('load', { response })
this.metaAction.sf('data.tableKey', Math.random())
setTimeout(() => {
this.getTableScroll()
}, 100)
}
initData = async (params, noInitDate) => {
const response = await this.webapi.docManage.init(params)
this.injections.reduce('tableLoading', false)
this.injections.reduce('load', { response, noInitDate })
this.metaAction.sf('data.tableKey', Math.random())
setTimeout(() => {
this.getTableScroll()
}, 100)
return response
}
//排序发生变化
sortChange = (key, value) => {
let params = {
'userOrderField': value == false ? null : key,
'order': value == false ? null : value
}
const pages = this.metaAction.gf('data.pagination').toJS()
this.sortParmas(null, { ...pages, 'currentPage': 1 }, params)
this.injections.reduce('sortReduce', params)
}
//分页发生变化
pageChanged = (current, pageSize) => {
let page = this.metaAction.gf('data.pagination').toJS()
const len = this.metaAction.gf('data.list').toJS().length
if (pageSize) {
page = {
...page,
'currentPage': len == 0 ? 1 : current,
'pageSize': pageSize
}
} else {
page = {
...page,
'currentPage': len == 0 ? 1 : current
}
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
this.sortParmas(null, page)
}
// 指定table 以什么字段作为key值
renderRowKey = (record) => {
return record.docId
}
tableOnchange = async (pagination, filters, sorter) => {
// const { columnKey, order } = sorter
// const response = await this.webapi.report.query(sorter)
// this.injections.reduce('tableOnchange', response.value.details)
}
rowSelection = (text, row, index) => {
return undefined
}
checkboxChange = (arr, itemArr) => {
let newArr = []
arr.forEach(item => {
if (item) {
newArr.push(item)
}
})
let newItemArr = []
itemArr.map(item => {
if (item) {
newItemArr.push(item)
}
})
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: newArr,
selectedOption: newItemArr
}
})
this.selectedOption = newItemArr
}
moreActionOpeate = (e) => {
this[e.key] && this[e.key]()
}
delTableItemClick = async () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '更多+删除'])
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS()
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要删除的数据')
return
}
const ret = await this.metaAction.modal('confirm', {
title: '删除凭证',
content: '确定删除所选凭证?'
})
//console.log(ret)
if (!ret) {
return
}
let mapData = new Map()
// 去下重复 (以防万一)
selectedOption.forEach(item => {
if (!mapData.has(item.docId)) {
mapData.set(item.docId, { docId: item.docId, ts: item.ts })
}
})
let data = []
for (let value of mapData.values()) {
data.push(value)
}
const res = await this.webapi.docManage.delProof(data)
if (res.allSuccess) {
this.metaAction.toast('success', '删除成功!')
} else {
this.metaAction.toast('error', `${res.msg}`)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
// 审核
auditClick = async () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '审核'])
const selectedOption = this.getNewData()
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要审核的数据!')
return
}
let flag = false
let data = selectedOption.map(item => {
if (item.voucherState != consts.VOUCHERSTATUS_Approved) {
flag = true
}
return {
docId: item.docId,
ts: item.ts
}
})
if (!flag) {
return this.metaAction.toast('warn', '当前没有可审核数据!')
}
const res = await this.webapi.docManage.auditProof(this.delRepeat(data, 'docId'))
if (res) {
this.metaAction.toast('success', res)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
getNewData = () => {
const checkboxValue = this.metaAction.gf('data.tableCheckbox.checkboxValue').toJS()
const list = this.metaAction.gf('data.list').toJS()
let arr = []
list.map(item => {
if (checkboxValue.includes(item.docId)) {
arr.push(item)
}
})
return arr
}
//凭证去重
delRepeat = (data, code) => {
const arr = new Map()
data.map(item => {
if (!arr.has(item[code])) {
arr.set(item[code], item)
}
})
const sum = []
for (let value of arr.values()) {
sum.push(value)
}
return sum
}
//提交整理凭证信息信息
submitSortProof = async (form, target) => {
const data = form.getValue()
let params = {
year: data.date.year(),
period: data.date.month() + 1,
reorganizeType: data.radio
}
const res = await this.webapi.docManage.reorganizeDocCode(params)
this.sortParmas()
return this.metaAction.toast('success', '整理凭证号成功!')
}
//整理凭证号
sortProofClick = () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '更多+整理凭证号'])
let _this = this
const { date_end } = this.metaAction.gf('data.searchValue').toJS()
this.metaAction.modal('show', {
title: '整理凭证号',
width: 320,
iconType: null,
className: 'mk-app-proof-of-list-modal-container',
children: <SortProof time={date_end} callBack={_this.submitSortProof} />,
footer: null
})
}
//反审核
versaAuditClick = async () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '更多+反审核'])
const selectedOption = this.getNewData()
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要反审核的数据!')
return
}
let flag = false
let data = selectedOption.map(item => {
if (item.voucherState == consts.VOUCHERSTATUS_Approved) {
flag = true
}
return {
docId: item.docId,
ts: item.ts
}
})
if (!flag) {
return this.metaAction.toast('warn', '当前没有反审核的数据!')
}
const res = await this.webapi.docManage.unAuditBatch(this.delRepeat(data, 'docId'))
if (res) {
this.metaAction.toast('success', res)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
newAddProofClick = () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '新增凭证'])
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS()
let item = selectedOption[0]
this.component.props.setPortalContent &&
this.component.props.setPortalContent(
'填制凭证',
'app-proof-of-charge',
{ accessType: 1, initData: { newCertificate: true } }
)
}
insertProofConfirm = (item) => {
this.component.props.setPortalContent &&
this.component.props.setPortalContent(
'填制凭证',
'app-proof-of-charge',
{ accessType: 1, initData: { code: item.docCode, voucherDate: item.voucherDate } }
)
}
getInsertItem = () => {
const checkboxValue = this.metaAction.gf('data.tableCheckbox.checkboxValue').toJS()
const list = this.metaAction.gf('data.list').toJS()
let index = list.find(item => {
return checkboxValue.includes(item.docId)
})
return index
}
insertProofClick = () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '更多+插入凭证'])
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS()
if (selectedOption.length > 0) {
let item = this.getInsertItem()
const _this = this
this.metaAction.modal('confirm', {
title: '插入凭证',
content: `您确定要在凭证[${item.docTypeAndCode}]处插入凭证吗?`,
onOk() {
return _this.insertProofConfirm(item)
},
onCancel() { }
})
} else {
this.metaAction.toast('warning', '请选择您要插入凭证的位置!')
}
}
delDocId = async (docId, ts) => {
const res = await this.webapi.docManage.delSingleDocId({ docId, ts })
if (res) {
this.metaAction.toast('success', '删除成功')
}
let { checkboxValue, selectedOption } = this.metaAction.gf('data.tableCheckbox').toJS()
checkboxValue = checkboxValue.filter(item => item != docId)
selectedOption = selectedOption.filter(item => item.docId != docId)
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: checkboxValue,
selectedOption: selectedOption
}
})
this.sortParmas()
}
delModal = async (docId, ts) => {
const _this = this
const ret = await this.metaAction.modal('confirm', {
title: '删除',
content: '你确定要删除吗?',
onOk() {
return _this.delDocId(docId, ts)
},
onCancel() { }
})
if (ret) {
//console.log(ret)
}
}
openMoreContent = async (docId, edit) => {
this.component.props.setPortalContent &&
this.component.props.setPortalContent('填制凭证', 'app-proof-of-charge', { accessType: 1, initData: { id: docId } })
}
operateNote = (value) => {
return value
// setTimeout(() => {
// if(document.getElementById('noteInput')){
// document.getElementById('noteInput').value = value
// document.getElementById('statisticsNum').innerHTML = value.length
// }
// },100)
}
submitNote = async (docId, ts, note) => {
let data
if (note.length > 100) {
return
}
data = await this.webapi.docManage.updateNote({
note: note,
ts: ts,
docId: docId
})
this.sortParmas()
}
operateCol = (text, record, index) => {
const { voucherState, docId } = record
const num = this.calcRowSpan(docId, 'docId', index)
const obj = {
children: (
<span>
<TableOperate
viewClick={() => this.openMoreContent(docId, false)}
editClick={() => this.openMoreContent(docId, true)}
deleteClick={() => this.delModal(docId, record.ts)}
noteClick={() => this.operateNote(record.note ? record.note : '')}
submitNote={(value) => this.submitNote(docId, record.ts, value)}
status={voucherState == consts.VOUCHERSTATUS_Approved ? 1 : 2}
/>
</span>
),
props: {
rowSpan: num,
}
}
return obj
}
componentWillUnmount = () => {
if (this.dateDom) {
this.dateDom.removeEventListener('click', this.rangePickerClick)
}
if (this.props && this.props.isFix === true) return
const win = window
if (win.removeEventListener) {
win.removeEventListener('resize', this.onResize, false)
} else if (win.detachEvent) {
win.detachEvent('onresize', this.onResize)
} else {
win.onresize = undefined
}
}
rangePickerClick = () => {
this.injections.reduce('update', {
path: 'data.showPicker',
value: true
})
}
normalSearchDateChange = (value) => {
//console.log('简单时间搜索')
this.changeSipmleDate = true
}
normalSearchChange = (path, value, initSearchValue, type) => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '简单查询'])
let params = this.metaAction.gf('data.searchValue').toJS()
if (initSearchValue) {
params = { ...params, ...initSearchValue }
}
if (path == 'date') {
params.date_start = value[0]
params.date_end = value[1]
} else {
params[path] = value
}
this.injections.reduce('searchUpdate', params)
const pages = this.metaAction.gf('data.pagination').toJS()
this.sortParmas(params, { ...pages, 'currentPage': 1 })
//console.log('简单搜索')
this.changeSipmleDate = true
}
rowSpan2 = (text, row, index) => {
const num = this.calcRowSpan(row.docId, 'docId', index)
const obj = {
children: (
<span className="app-proof-of-list-td-con">
<a
href="javascript:;"
onClick={() => this.openMoreContent(row.docId, false)}
className="table-needDel"
title={text}
data-rol={num}>
{text}
</a>
</span>
),
props: {
rowSpan: num,
},
}
return obj
}
rowSpan = (text, row, index, key) => {
const obj = {
children: <span className="app-proof-of-list-td-con"><span title={this.transformThoundsNumber(text, key)}>{this.transformThoundsNumber(text, key)}</span></span>,
props: {
rowSpan: this.calcRowSpan(row.docId, 'docId', index),
},
}
return obj
}
export = async () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '导出'])
const params = this.sortParmas(null, null, null, 'get')
const list = this.metaAction.gf('data.list').toJS()
if (list.length == 0) {
this.metaAction.toast('warn', '当前没有可导出数据')
return
}
params.docIdsStr = this.getPrintDocId()
await this.webapi.docManage.export(params)
}
print = async () => {
_hmt && _hmt.push(['_trackEvent', '财务', '凭证管理', '打印'])
let ret, form
let _this = this
const list = this.metaAction.gf('data.list').toJS()
if (list.length == 0) {
this.metaAction.toast('warn', '当前没有可打印数据')
return
}
const {
height,
maxLineNum,
printAuxAccCalc,
type,
width
} = await this.webapi.docManage.getPrintConfig()
this.metaAction.modal('show', {
title: '打印',
width: 400,
footer: null,
iconType: null,
okText: '打印',
className: 'mk-app-proof-of-list-modal-container',
children: <PrintOption
height={height}
maxLineNum={maxLineNum}
printAuxAccCalc={printAuxAccCalc}
type={type}
width={width}
callBack={_this.submitPrintOption}
/>
})
}
getPrintDocId = () => {
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS()
if (selectedOption.length == 0) {
return ''
}
let arr = selectedOption.map(item => {
return item.docId
})
return arr.join(',')
}
submitPrintOption = async (form, target) => {
let params = this.sortParmas(null, null, null, 'get')
delete params.page
let option = {
"type": parseInt(form.state.value),
"printAuxAccCalc": form.state.printAccountChecked,
"docIdsStr": this.getPrintDocId()
}
if (form.state.value == "0") {
Object.assign(option, { "maxLineNum": form.state.pageSize }, params)
} else if (form.state.value == "2") {
Object.assign(option, { "height": form.state.height, "width": form.state.width }, params)
} else {
Object.assign(option, params)
}
//console.log(option)
let res = await this.webapi.docManage.print(option)
}
calcRowSpan(text, columnKey, currentRowIndex) {
const list = this.metaAction.gf('data.list')
if (!list) return
const rowCount = list.size
if (rowCount == 0 || rowCount == 1) return 1
if (currentRowIndex > 0
&& currentRowIndex <= rowCount
&& text == list.getIn([currentRowIndex - 1, columnKey])) {
return 0
}
let rowSpan = 1
for (let i = currentRowIndex + 1; i < rowCount; i++) {
if (text == list.getIn([i, columnKey]))
rowSpan++
else
break
}
return rowSpan
}
checkSearchValue = (value, form) => {
let flagCode = this.checkSearchValueCode(value, form)
return flagCode
}
checkSearchValueCode = (value, form) => {
const { endCode, startCode } = value
if (!endCode && !startCode) {
form.setFields({
startCode: {
value: '',
errors: null,
},
endCode: {
value: '',
errors: null,
}
})
return true
}
if ((!endCode && startCode)) {
let startCodeNum = parseInt(value.startCode ? value.startCode : 0)
if (isNaN(startCodeNum) || startCodeNum > 9999 || startCodeNum < 0) {
form.setFields({
startCode: {
errors: [new Error('请输入正确的凭证号')],
}
})
return false
}
form.setFields({
startCode: {
value: this.padStart(startCodeNum),
errors: null,
},
endCode: {
value: 9999,
errors: null,
}
})
value.startCode = this.padStart(startCodeNum)
value.endCode = 9999
return true
} else {
let startCodeNum = parseInt(value.startCode ? value.startCode : 0)
let endCodeNum = parseInt(value.endCode)
let flag = true
if (isNaN(startCodeNum) || startCodeNum > 9999 || startCodeNum < 0) {
flag = false
form.setFields({
startCode: {
errors: [new Error('请输入正确的凭证号')],
}
})
}
if (isNaN(endCodeNum) || endCodeNum > 9999 || startCodeNum < 0) {
flag = false
form.setFields({
endCode: {
errors: [new Error('请输入正确的凭证号')],
}
})
}
if (flag) {
form.setFields({
startCode: {
value: endCodeNum > startCodeNum ? this.padStart(startCodeNum) : this.padStart(endCodeNum),
errors: null,
},
endCode: {
value: endCodeNum > startCodeNum ? this.padStart(endCodeNum) : this.padStart(startCodeNum),
errors: null,
}
})
value.startCode = endCodeNum > startCodeNum ? this.padStart(startCodeNum) : this.padStart(endCodeNum)
value.endCode = endCodeNum > startCodeNum ? this.padStart(endCodeNum) : this.padStart(startCodeNum)
}
return flag
}
return true
}
padStart = (num) => {
return num.toString().padStart(4, '0')
}
/**
* current 每个月份
* pointTime 指定比较的时间
* type 'pre' 前 'next' 后
* return 返回 true 代表禁用
*/
disabledDate = (current, pointTime, type) => {
const enableddate = this.metaAction.gf('data.other.enableddate')
// const enableddateNum = this.transformDateToNum(enableddate)
if (type == 'pre') {
let currentMonth = this.transformDateToNum(current)
let enableddateMonth = this.transformDateToNum(enableddate)
return currentMonth < enableddateMonth
} else {
let currentMonth = this.transformDateToNum(current)
let pointTimeMonth = this.transformDateToNum(pointTime)
let enableddateMonth = this.transformDateToNum(enableddate)
return currentMonth < pointTimeMonth || currentMonth < enableddateMonth
}
}
transformDateToNum = (date) => {
try {
if (!date) {
return 0
}
let time = date
if (typeof date == 'string') {
time = utils.date.transformMomentDate(date)
}
return parseInt(`${time.year()}${time.month() < 10 ? `0${time.month()}` : `${time.month()}`}`)
} catch (err) {
//console.log(err)
return 0
}
}
disabledRangePicker = (current) => {
const { enabledMonth, enabledYear } = this.metaAction.context.get('currentOrg')
return true
}
// normalSelectDate = () => {
// const showPicker = this.metaAction.gf('data.showPicker')
// if( showPicker ){
// this.injections.reduce('update',{
// path: 'data.showPicker',
// value: false
// })
// }
// const params = this.metaAction.gf('data.searchValue').toJS()
// this.injections.reduce('searchUpdate', params)
// const pages = this.metaAction.gf('data.pagination').toJS()
// this.sortParmas(params, { ...pages, 'currentPage': 1 })
// }
// renderDatePickerExtraFooter = () => {
// return (
// <Button type="primary" style={{ float: 'right' }} size='small' onClick={this.normalSelectDate}>确定</Button>
// )
// }
filterOptionSummary = (input, option) => {
if (option && option.props && option.props.label) {
return option.props.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
return true
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
voucherAction = FormDecorator.actionCreator({ ...option, metaAction }),
o = new action({ ...option, metaAction, voucherAction }),
ret = { ...metaAction, ...voucherAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}