ttk-app-core
Version:
enterprise develop framework
1,306 lines (1,233 loc) • 106 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import { Select, Button, Modal, Icon, PrintOption, FormDecorator, Checkbox, Popover, Menu } from 'edf-component'
import utils from 'edf-utils'
import { fromJS } from 'immutable'
import sortSearchOption from './utils/sortSearchOption' //格式化搜索条件
import moment from 'moment'
import config from './config'
const Option = Select.Option
import { consts } from 'edf-consts'
import table from '../../../component/components/table/table'
const ARRIVAL_NotApprove = 1000020001, // 单据状态: 1000020001: 未审核
ARRIVAL_Approved = 1000020002, // 单据状态: 1000020002: 已审核
ARRIVAL_Rejected = 1000020003; // 单据状态: 1000020003: 已驳回
const checkboxKey = 'id';//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');
//let { id, accessType } = this.component.props;
// if (this.component.props.initSearchValue) {
// this.linkInPage(this.component.props.initSearchValue)
// } else {
this.load()
//}
}
load = async () => {
const { enabledMonth, enabledYear, periodDate } = this.metaAction.context.get('currentOrg') //获取全局的启用日期
//默认日期
if (periodDate) {
const currentDate = moment().format('YYYY-MM');//当前月
const lastMonth = moment().subtract(1, "months").format('YYYY-MM');//上月
let dateRangeKey
if (periodDate == currentDate) {
dateRangeKey = 'thisMonth';
} else if (periodDate == lastMonth) {
dateRangeKey = 'lastMonth';
} else {
dateRangeKey = 'custom';
}
this.injections.reduce('dateRangeChange',
{
'data.other.dateRangeKey': dateRangeKey,
'data.searchValue.beginDate': moment(periodDate).startOf('month'),
'data.searchValue.endDate': moment(periodDate).endOf('month'),
'data.other.date': moment(periodDate).startOf('month'),
})
}
if (enabledMonth && enabledYear) {
const enbledMoment = utils.date.transformMomentDate(`${enabledYear}-${enabledMonth}`)
const enbledDate = enbledMoment.format("YYYY-MM");//启用月
// if (enbledDate < currentDate) {
// this.injections.reduce('dateRangeChange',
// {
// 'data.other.dateRangeKey': 'lastMonth',
// 'data.searchValue.beginDate': moment().subtract(1, "months").startOf('month'),
// 'data.searchValue.endDate': moment().subtract(1, "months").endOf('month'),
// 'data.other.date': moment().subtract(1, "months").startOf('month'),
// })
// } else if (enbledDate == currentDate) {
// this.injections.reduce('dateRangeChange',
// {
// 'data.other.dateRangeKey': 'thisMonth',
// 'data.searchValue.beginDate': moment().startOf('month'),
// 'data.searchValue.endDate': moment().endOf('month'),
// 'data.other.date': moment().startOf('month')
// })
// } else {
// this.injections.reduce('dateRangeChange',
// {
// 'data.other.dateRangeKey': 'custom',
// 'data.searchValue.beginDate': moment(enbledDate).startOf('month'),
// 'data.searchValue.endDate': moment(enbledDate).endOf('month'),
// 'data.other.date': moment(enbledDate).startOf('month'),
// })
// }
this.injections.reduce('update', {
path: 'data.other.enableddate',
value: enbledMoment
})
}
await this.tplusConfig();//tplus
this.sortParmas(null, null, null, 'init')
//this.getClass()
}
//获取到页签焦点时调用
onTabFocus = async (params) => {
// await this.initDate()
// params = params.toJS();
// if (params.accessType != 0) {
// if (params.optName == 'collect') {
// this.oneKeyCollectClick();
// } else if (params.optName === 'import') {
// this.importInvoice();
// }
// }
const { enabledMonth, enabledYear, periodDate } = this.metaAction.context.get('currentOrg') //获取全局的启用日期
//默认日期
if (periodDate) {
this.injections.reduce('update', { path: 'data.other.date', value: moment(periodDate).startOf('month') })
}
//启用日期
if (enabledMonth && enabledYear) {
const enbledMoment = utils.date.transformMomentDate(`${enabledYear}-${enabledMonth}`)
this.injections.reduce('update', {
path: 'data.other.enableddate',
value: enbledMoment
})
}
await this.tplusConfig();//tplus
this.sortParmas(null, null, null, 'init')
// this.getClass()
}
tplusConfig = async () => {
const isExist = await this.webapi.tplus.configExist();//是否已绑定
const tplusconfig = await this.webapi.tplus.configQuery();//查询配置信息
if (isExist && tplusconfig) {
this.injections.reduce('tplusConfig', tplusconfig)
}
}
moreActionOpeate = (e) => {
this[e.key] && this[e.key]()
}
// 生成凭证
getVoucher = async () => {
let selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
let dataSource = this.metaAction.gf('data.list').toJS()//列表
if (selectedOption.length == 0) {
return this.metaAction.toast('error', '请选择您要生成凭证的数据')
}
let flag = false
let data = []
//需要将选中的数据按照列表的顺序排序
dataSource.forEach(item => {
let sc = selectedOption.find(ele => ele.id == item.id);
if (sc) {
if (item.status != ARRIVAL_Approved) {
flag = true
data.push(
{
id: item.id,
ts: item.ts
}
)
}
}
})
// selectedOption.forEach(item => {
// if (item.status != ARRIVAL_Approved) {
// //flag = true
// data.push(
// {
// id: item.id,
// ts: item.ts
// }
// )
// }
// // return {
// // id: item.id,
// // ts: item.ts
// // }
// })
if (!flag) {
this.metaAction.toast('warn', '当前没有可生成凭证的数据')
return
}
// const ret = await this.metaAction.modal('confirm', {
// title: '生成凭证',
// content: '确定生成凭证?'
// })
// if (!ret) {
// return
// }
data = this.delRepeat(data, 'id');
let loading = this.metaAction.gf('data.loading')
if (!loading) {
this.injections.reduce('tableLoading', true)
}
const res = await this.webapi.getAudit(data)
this.injections.reduce('tableLoading', false)
if (res) {
if (res.fail.length > 0) {
this.showError('生成凭证结果', res.success, res.fail);
} else {
this.metaAction.toast('success', '生成凭证成功')
}
} else {
this.metaAction.toast('error', `${res.msg}`)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
//生成凭证到T+
getVoucherToTJ = async () => {
let selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
let dataSource = this.metaAction.gf('data.list').toJS()
if (selectedOption.length == 0) {
return this.metaAction.toast('error', '请选择您要生成凭证的数据')
}
let flag = false
let data = [];
//需要将选中的数据按照列表的顺序排序
dataSource.forEach(item => {
let sc = selectedOption.find(ele => ele.id == item.id);
if (sc) {
if (item.status != ARRIVAL_Approved) {
flag = true
data.push(
{
id: item.id,
ts: item.ts
}
)
}
}
})
if (!flag) {
this.metaAction.toast('warn', '当前没有可生成凭证的数据')
return
}
data = this.delRepeat(data, 'id');
// let loading = this.metaAction.gf('data.loading')
// if (!loading) {
// this.injections.reduce('tableLoading', true)
// }
const baseUrl = this.metaAction.gf('data.tplus.baseUrl');
const res = await this.metaAction.modal('show', {
title: '生成凭证',
width: 720,
okText: '确定',
footer: null,
bodyStyle: { padding: '10px 12px' },
children: this.metaAction.loadApp('ttk-scm-get-voucher-to-tj', {
store: this.component.props.store,
vatOrEntry: 1,
selectedData: data,
baseUrl
}),
})
if (res) {
// if (res.fail.length > 0) {
// this.showError('生成凭证结果', res.success, res.fail);
// } else {
// this.metaAction.toast('success', '生成凭证成功')
// }
} else {
// this.metaAction.toast('error', `${res.msg}`)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
// 删除凭证
delVoucher = async () => {
let selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
if (selectedOption.length == 0) {
return this.metaAction.toast('error', '请选择您要删除凭证的数据')
}
// let flag = false
let data = []
selectedOption.forEach(item => {
if (item.status == ARRIVAL_Approved) {
// flag = true
data.push(
{
id: item.id,
ts: item.ts
}
)
}
// return {
// id: item.id,
// ts: item.ts
// }
})
if (data.len == 0) {
this.metaAction.toast('warn', '当前没有可删除凭证的数据')
return
}
// const ret = await this.metaAction.modal('confirm', {
// title: '删除凭证',
// content: '确定删除凭证?'
// })
// if (!ret) {
// return
// }
data = this.delRepeat(data, 'id');
let loading = this.metaAction.gf('data.loading')
if (!loading) {
this.injections.reduce('tableLoading', true)
}
const res = await this.webapi.delAudit(data)
this.injections.reduce('tableLoading', false)
if (res) {
if (res.fail.length > 0) {
this.showError('删除凭证结果', res.success, res.fail);
} else {
this.metaAction.toast('success', '删除凭证成功')
}
} else {
this.metaAction.toast('error', `${res.msg}`)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
showError = (title, successArr, failArr) => {
const ret = this.metaAction.modal('show', {
title,
width: 585,
// footer: null,
bodyStyle: { padding: '2px 0 10px 24px' },
children: this.metaAction.loadApp('ttk-scm-app-error-list', {
store: this.component.props.store,
successArr,
failArr
}),
})
}
//生成凭证并导出到T+
auditAndExportBatch = async () => {
// const selectedOption = this.getNewData()
let selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要生成凭证并导出的数据')
return
}
let flag = false
let data = selectedOption.map(item => {
if (item.status != ARRIVAL_Approved) {
flag = true
}
return {
id: item.id,
ts: item.ts
}
})
if (!flag) {
this.metaAction.toast('warn', '当前没有可生成凭证并导出的数据')
return
}
const ret = await this.metaAction.modal('confirm', {
title: '生成凭证并导出',
content: '确定生成凭证并导出?'
})
if (!ret) {
return
}
data = this.delRepeat(data, 'id');
const res = await this.webapi.auditAndExportBatch({ vouchers: data });
//清空选中
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
setTimeout(() => {
this.sortParmas()
}, 1000)
}
//生成凭证并导出到U8
auditAndExportBatchU8 = async () => {
// const selectedOption = this.getNewData()
let selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要生成凭证并导出的数据')
return
}
let flag = false
let data = selectedOption.map(item => {
if (item.status != ARRIVAL_Approved) {
flag = true
}
return {
id: item.id,
ts: item.ts
}
})
if (!flag) {
this.metaAction.toast('warn', '当前没有可生成凭证并导出的数据')
return
}
const ret = await this.metaAction.modal('confirm', {
title: '生成凭证并导出',
content: '确定生成凭证并导出?'
})
if (!ret) {
return
}
data = this.delRepeat(data, 'id');
const res = await this.webapi.auditAndExportBatchU8({ vouchers: data });
//清空选中
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
setTimeout(() => {
this.sortParmas()
}, 1000)
}
// 现结
settlement = async () => {
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要现结的数据')
return
}
let flag = false
let data = selectedOption.map(item => {
if (item.notSettleAmount != 0) {
flag = true
}
return {
id: item.id,
ts: item.ts
}
})
if (!flag) {
this.metaAction.toast('warn', '当前没有可现结的数据')
return
}
const res = await this.metaAction.modal('show', {
title: '现结账户',
width: 720,
okText: '确定',
bodyStyle: { padding: '10px 12px' },
children: this.metaAction.loadApp('ttk-scm-currentAccount-card', {
store: this.component.props.store,
selectedOption,
settleOnOk: async (params) => {
return await this.webapi.settleBatch(params);
},
vatOrEntry: 1
})
})
if (res) {
if (res.fail.length > 0) {
this.showError('现结结果', res.success, res.fail);
} else {
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
this.metaAction.toast('success', '现结成功')
}
this.sortParmas()
}
}
// 批量修改
supplement = async () => {
const selectedOption = this.metaAction.gf('data.tableCheckbox.selectedOption').toJS() //选中的
if (selectedOption.length == 0) {
this.metaAction.toast('error', '请选择您要批量修改的数据')
return
}
let data = [];
let flag = false;
selectedOption.forEach(item => {
if (item.status != ARRIVAL_Approved) {
flag = true;
data.push({
id: item.id,
ts: item.ts
})
}
})
if (!flag) {
this.metaAction.toast('warn', '已生成凭证的发票,不能修改,如需修改,请删除凭证')
return
}
data = this.delRepeat(data, 'id');
const res = await this.metaAction.modal('show', {
title: '批量修改数据',
width: 400,
okText: '确定',
wrapClassName: 'piliang',
bodyStyle: { padding: '10px 65px' },
children: this.metaAction.loadApp('ttk-scm-supplyData-card', {
store: this.component.props.store,
selectedOption: data,
type: 'addSupplier',
properties: this.metaAction.gf('data.properties').toJS()
}),
})
if (res) {
if (res.fail.length > 0) {
this.showError('批量修改结果', res.success, res.fail);
} else {
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
this.metaAction.toast('success', '批量修改成功')
}
this.sortParmas()
}
}
// 凭证习惯
voucherHabit = async () => {
const ret = await this.metaAction.modal('show', {
title: '凭证习惯设置',
width: 480,
okText: '确定',
bodyStyle: { padding: '10px 24px' },
children: this.metaAction.loadApp('ttk-scm-voucherHabit-card', {
store: this.component.props.store,
type: 'arrival',
}),
})
// if (ret) this.metaAction.toast('success', '设置成功')
}
// 科目设置
subManage = () => {
if (!this.config.apps['edfx-business-subject-manage']) {
throw '依赖app-asset-management-list app,请使用mk clone app-asset-management-list命令添加'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('科目设置', 'edfx-business-subject-manage', { accessType: 'purchase' })
}
// 生成档案规则设置
fileRules = async () => {
const ret = await this.metaAction.modal('show', {
title: '生成档案规则设置',
width: 570,
okText: '确定',
bodyStyle: { padding: '12px 24px 12px' },
children: this.metaAction.loadApp('ttk-scm-fileRules-card', {
store: this.component.props.store,
inventoryType: 'arrival',
}),
})
// if (ret) this.metaAction.toast('success', '设置成功')
}
bookkeeping = async () => {
const ret = await this.metaAction.modal('show', {
title: '设置记账方式',
width: 368,
okText: '确定',
// footer: false,
bodyStyle: { padding: '14px 24px 12px' },
children: this.metaAction.loadApp('ttk-scm-app-set-bookkeeping', {
store: this.component.props.store,
vatOrEntry: 1
}),
})
if (ret.id) this.metaAction.toast('success', '设置成功')
}
collectset = async () => {
const ret = await this.metaAction.modal('show', {
title: '采集发票设置',
width: 580,
className: 'ttk-scm-collect-set-modal',
children: this.metaAction.loadApp('ttk-scm-collect-set', {
store: this.component.props.store,
vatOrEntry: 1
})
})
}
//批量删除
deleteBatchClick = async () => {
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: '确定删除所选进项发票?'
})
if (!ret) {
return
}
let data = selectedOption.map(item => {
return {
id: item.id,
ts: item.ts
}
})
data = this.delRepeat(data, 'id');
const res = await this.webapi.deleteBatch(data)
if (res) {
if (res.fail.length > 0) {
this.showError('删除发票结果', res.success, res.fail);
} else {
this.metaAction.toast('success', '删除成功')
}
} else {
this.metaAction.toast('error', `${res.msg}`)
}
this.injections.reduce('update', {
path: 'data.tableCheckbox',
value: {
checkboxValue: [],
selectedOption: []
}
})
// 重新请求列表数据
this.sortParmas()
}
//跳转到采购单
insertProofConfirm = (id) => {
this.component.props.setPortalContent &&
this.component.props.setPortalContent(
'进项发票',
'ttk-scm-app-pu-invoice-card',
{ accessType: 1, id }
)
}
towrzx = (id) => {
this.component.props.setPortalContent &&
this.component.props.setPortalContent(
'未认证进项清单',
'ttk-scm-app-unauthorized-list',
{ accessType: 1, id }
)
}
dateChange = async () => {
// alert(1)
}
// getClass = () => {
// return
// let drop = document.getElementsByClassName("anticon-ellipsis")
// if (drop.length) {
// drop[0].className = 'anticon anticon-down'
// drop[0].className = 'anticon anticon-down'
// }
// }
//下载模板
exporttemplate = () => {
// if(res){
// this.metaAction.toast('success', '下载模版成功')
// }
}
//导入excel
importInvoice = async () => {
const ret = await this.metaAction.modal('show', {
title: '进项发票导入',
okText: '导入',
children: this.metaAction.loadApp('ttk-scm-app-import', {
store: this.component.props.store,
exporttemplate: this.exporttemplate, //下载模板
imports: async (file) => {
return await this.webapi.import({ ...file.toJS(), orgId: this.getOrgId(), isIncome: false })
}
})
})
if (ret) {
this.injections.reduce('changeDate', { beginDate: moment(), endDate: moment() });//初始化日期
this.sortParmas();
}
}
//弹出采集发票
onCollectModal = async () => {
const ret = await this.metaAction.modal('show', {
title: '采集发票',
width: 280,
okText: '采集',
// footer: false,
children: this.metaAction.loadApp('ttk-scm-app-collect', {
store: this.component.props.store,
collectOnOk: async (params) => {
return await this.webapi.collecteData({ ...params, vatOrEntry: 1 });
},
enableddate: this.metaAction.gf('data.other.enableddate'),//启用时间
defaultdate: this.metaAction.gf('data.other.date')//默认查询日期
})
})
if (ret) {
// ret.invoiceInventoryList=[
// {}
// ]
if (ret.cancel) {
//点击取消
}
else if (ret.invoiceInventoryList && ret.invoiceInventoryList.length > 0) {
//匹配存货
const retss = await this.metaAction.modal('show', {
title: '发票货物或劳务名称匹配档案存货名称',
width: 600,
okText: '确定',
bodyStyle: { padding: '22px 24px 12px' },
children: this.metaAction.loadApp('ttk-scm-matchInventory-card', {
store: this.component.props.store,
invoiceInventoryList: ret.invoiceInventoryList,
invoice: ret.invoice,
inventoryType: 'arrival',
}),
})
if (retss) {
this.matchDateRange(ret.collectDate);
this.injections.reduce('changeDate', { beginDate: ret.collectDate[0], endDate: ret.collectDate[1] });//初始化日期
this.onCollectResultModal2(ret);
}
}
else if (ret.list && ret.list.length > 0) {
this.metaAction.toast('success', '发票采集成功')
this.matchDateRange(ret.collectDate);
this.injections.reduce('changeDate', { beginDate: ret.collectDate[0], endDate: ret.collectDate[1] });//初始化日期
this.onCollectResultModal2(ret);
} else if (ret.message) {
this.metaAction.toast('error', ret.message)
}
}
}
//税局信息
CheckTaxInfoModal = async () => {
const ret = await this.metaAction.modal('show', {
title: '税局信息',
width: 600,
okText: '确定',
bodyStyle: { padding: '10px' },
children: this.metaAction.loadApp('ttk-scm-app-tax-info', {
store: this.component.props.store,
taxOnOk: async (params) => {
return await this.webapi.checkAccountInfo(params);
}
})
})
//采集
if (ret) {
this.onCollectModal();
}
}
onCollectResultModal2 = async (option) => {
const ret = await this.metaAction.modal('show', {
title: '本次采集发票清单',
width: 820,
okText: '确认',
footer: null,
className: 'collect-result-modal',
children: this.metaAction.loadApp('ttk-scm-app-collect-result', {
store: this.component.props.store,
dateVisible: false,
resultData: option.list,
vatOrEntry: 1,
enableddate: this.metaAction.gf('data.other.enableddate')
})
})
if (ret) {
this.sortParmas();
}
}
onCollectResultModal = async () => {
const ret = await this.metaAction.modal('show', {
title: '发票汇总表',
width: 820,
okText: '确定',
cancelText: '取消',
footer: null,
className: 'collect-result-modal',
children: this.metaAction.loadApp('ttk-scm-app-collect-result', {
store: this.component.props.store,
dateVisible: true,
vatOrEntry: 1,
enableddate: this.metaAction.gf('data.other.enableddate'),
defaultdate: this.metaAction.gf('data.other.date')//默认查询日期
}),
})
}
renderRowClassName = (record, index) => {
if (!record[checkboxKey]) {
return 'tr_heji'
} else if (record.discarded == true) {
return 'tr_zuofei'
}
// else if (record.isDraft == true) {
// return 'tr_draft'
// }
else {
return 'tr_normal'
}
}
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('ttk-scm-app-pu-invoice-list-Body')[0]
let tableDom
if (!dom) {
return
}
tableDom = dom.getElementsByClassName('ant-table-tbody')[0];
tableDom.scrollTop = 0;
tableDom.scrollLeft = 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) {
}
}
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('ttk-scm-app-pu-invoice-list-Body')[0]
if (!dom) {
if (type) {
return
}
setTimeout(() => {
this.onResize()
}, 20)
} else {
let tableDom = dom.getElementsByClassName('ant-table-tbody')[0];
tableDom.scrollTop = 0;
tableDom.scrollLeft = 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()
}
/*********--region start--*********** */
//渲染列
renderColumns = () => {
const columns = this.metaAction.gf('data.other.columnDto').toJS() //header
// const tableOption = this.metaAction.gf('data.tableOption').toJS() // x y
let code = this.metaAction.gf('data').toJS().other.code
const arr = [];
columns.forEach(data => {
let sortColumns = this.getSortColumnsItem(data.fieldName, data.width) //需要排序操作的单独处理
if (!data.isVisible) {
return
}
if (sortColumns) {
arr.push(sortColumns)
}
else if (data.fieldName == 'seq') {
const dt = this.metaAction.gf('data.list').toJS();
let hasDraft = false;
dt.forEach(item => {
if (item.isDraft || item.discarded) {
hasDraft = true;
}
})
if (!hasDraft) {
//所有的列都没有草稿状态
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_center`,
dataIndex: data.fieldName,
width: data.width,
code: code,
render: this.rowSpan
})
}
else {
//有草稿状态时
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_left`,
dataIndex: data.fieldName,
width: data.width,
code: code,
render: (text, record, index) => { return this.renderRowSpanSeq(text, record, index, 'seq') }
})
}
}
else if (data.fieldName == 'settleCodes') {
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
render: (text, record, index) => {
let length = text.length;
if (length == 0) {
const obj = {
children: null,
props: {
rowSpan: this.calcRowSpan(record[checkboxKey], checkboxKey, index),
},
}
return obj
}
else if (length == 1) {
const obj = {
children: <span className="ttk-table-app-list-td-con">
<a
href="javascript:;"
onClick={() => this.openMoreContent(text[0].id, 'settleCodes')}
className="table-needDel"
title={text[0].code}
data-rol={1}>
{text[0].code}
</a>
</span>,
props: {
rowSpan: this.calcRowSpan(record[checkboxKey], checkboxKey, index),
},
}
return obj
} else {
const obj = {
children: <span className="ttk-table-app-list-td-con">
<Popover content={<Menu>
{text.map((item, index) => {
return <Menu.Item key={index}>
<a
href="javascript:;"
onClick={() => this.openMoreContent(item.id, 'settleCodes')}
className="table-needDel pu_invoice_list_green"
data-rol={1}>
{item.code}
</a>
</Menu.Item>
})}
</Menu>} title="付款列表" placement='left'>
<a
href="javascript:;"
className="table-needDel"
onClick={() => this.openMoreContent(text[0].id, 'settleCodes')}
title={text[0].code}
data-rol={1}>
{text[0].code}
</a>
</Popover>
</span>,
props: {
rowSpan: this.calcRowSpan(record[checkboxKey], checkboxKey, index),
},
}
return obj
}
}
})
}
else if (data.fieldName == 'docCode') {
arr.push({
title: data.caption,
key: data.fieldName,
dataIndex: data.fieldName,
width: data.width,
code: code,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
render: (text, record, index) => {
let isTplus = false;
if (!text) {
}
else if (/T/.test(text)) {
isTplus = true;
} else {
text = `记-${text}`
}
const obj = {
children: <span className="ttk-table-app-list-td-con">
<a
href="javascript:;"
onClick={() => this.openDocContent(record.docId, isTplus)}
className="table-needDel"
title={text}
data-rol={1}>
{text}
</a>
</span>,
props: {
rowSpan: this.calcRowSpan(record[checkboxKey], checkboxKey, index),
},
}
return obj
}
})
}
else if (data.fieldName == 'supplierName') {
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
onCell: (record) => {
if (!record[checkboxKey]) {
return
}
const list = this.metaAction.gf('data.list');
if (!list.size) return
const ds = list.toJS();
if (!ds || !ds.length) return
const index = list.indexOf(fromJS(record));
//是否为第一行
if (index == 0 && !record['supplierName']) {
return {
style: {
border: 'solid red 1px'
}
}
} else {
if (!record['supplierName']) {
//判断本行是否为空
return {
style: {
borderColor: 'red',
borderLeft: 'solid 1px red'
}
}
} else if (index < ds.length - 1 && ds[index + 1][checkboxKey]) {
//获取[]中相同docId的{}数
let rowSpan = 1
for (let i = index + 1; i < list.size; i++) {
if (record[checkboxKey] == list.getIn([i, checkboxKey]))
rowSpan++
else
break
}
if ((index + rowSpan) < ds.length && !ds[index + rowSpan]['supplierName'] && ds[index + rowSpan][checkboxKey]) {
return {
style: {
borderBottomColor: 'red'
}
}
}
}
}
},
render: (text, record, index) => this.rowSpan(text, record, index, data.fieldName)
})
}
else if (data.fieldName == 'inventoryName') {
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
onCell: (record) => {
if (!record[checkboxKey]) {
return
}
const list = this.metaAction.gf('data.list');
const ds = list.toJS();
const index = list.indexOf(fromJS(record));
//是否为第一行
if (index == 0 && !record.inventoryName) {
return {
style: {
border: 'solid red 1px'
}
}
} else {
if (!record.inventoryName) {
//判断本行是否为空
return {
style: {
borderColor: 'red',
borderLeft: 'solid 1px red'
}
}
} else if (index < ds.length - 1 && !ds[index + 1].inventoryName && ds[index + 1][checkboxKey]) {
//判断下一行是否为空
return {
style: {
borderBottomColor: 'red'
}
}
}
}
},
render: (text, record, index) => this.normalTdRender(text, record, index, data.fieldName)
})
}
else if (data.fieldName == 'propertyName') {
//业务类型
arr.push({
title: <span style={{ marginLeft: '-20.5px' }}>{data.caption}<Popover content='点 更多/批量修改,修改业务类型' placement='rightTop' overlayClassName='ttk-scm-app-pu-invoice-list-helpPopover' >
<Icon className='helpIcon' fontFamily='edficon' type="bangzhutishi" />
</Popover></span>,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
onCell: (record) => {
if (!record[checkboxKey]) {
return
}
const list = this.metaAction.gf('data.list');
const ds = list.toJS();
const index = list.indexOf(fromJS(record));
//是否为第一行
if (index == 0 && !record.propertyName) {
// if (!record.inventoryName) {
// return {
// style: {
// borderColor: 'red',
// borderTop: 'solid 1px red',
// }
// }
// } else {
return {
style: {
// borderColor: 'red',
// borderTop: 'solid 1px red',
// borderLeft: 'solid 1px red',
border: 'solid 1px red'
}
}
// }
} else {
if (!record.propertyName) {
//判断本行是否为空
// if (!record.inventoryName) {
// return {
// style: {
// borderColor: 'red',
// }
// }
// } else {
return {
style: {
borderColor: 'red',
borderLeft: "solid 1px red"
}
}
// }
} else if (index < ds.length - 1 && !ds[index + 1].propertyName && ds[index + 1][checkboxKey]) {
return {
style: {
borderBottomColor: 'red',
}
}
}
}
},
render: (text, record, index) => this.normalTdRender(text, record, index, data.fieldName)
})
}
else if (data.isHeader == true) {
//作为表头 需要跨行 需要表头时 才跨行
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
render: (text, record, index) => this.rowSpan(text, record, index, data.fieldName)
})
}
else {
arr.push({
title: data.caption,
key: data.fieldName,
className: `table_td_align_${this.needAlignType(data.fieldName)}`,
dataIndex: data.fieldName,
width: data.width,
code: code,
render: (text, record, index) => this.normalTdRender(text, record, index, data.fieldName)
})