ttk-app-core
Version:
enterprise develop framework
503 lines (470 loc) • 19 kB
JavaScript
import React from 'react'
import { action as MetaAction, AppLoader } from 'edf-meta-engine'
import {Icon} from 'edf-component'
import renderColumns from './utils/renderColumns'
import config from './config'
import {Tree, Form, Select, Input} from 'edf-component'
import extend from './extend'
import { fromJS } from 'immutable'
import utils from 'edf-utils'
import img from '../../../component/assets/img/noContent.png'
class action {
constructor(option) {
this.metaAction = option.metaAction
this.extendAction = option.extendAction
this.config = config.current
this.webapi = this.config.webapi
}
onInit = ({ component, injections }) => {
this.extendAction.gridAction.onInit({ component, injections })
this.component = component
this.injections = injections
if (this.component.props.setOkListener) {
this.component.props.setOkListener(this.onOk)
}
let addEventListener = this.component.props.addEventListener
if (addEventListener) {
addEventListener('onTabFocus', :: this.onTabFocus)
addEventListener('enlargeClick', () => this.onResize({}))
}
injections.reduce('init')
let tabEdit = this.component.props.tabEdit
this.load(tabEdit)
}
load = async (tabEdit) => {
let query = await this.webapi.inventory.query()
if(query == '0'){ // 未启用,获取开账时间
const currentOrg = this.metaAction.context.get("currentOrg")
const enabledPeriod = currentOrg.enabledYear + '-' + `${currentOrg.enabledMonth}`.padStart(2, '0') //'2018-01'
const ret = await this.metaAction.modal('show', {
title: '存货核算',
wrapClassName: 'inventory-card',
width: 400,
okText: '确定',
bodyStyle: {padding: '10px 50px'},
children: this.metaAction.loadApp('ttk-scm-app-inventory-card', {
store: this.component.props.store,
enabledPeriod,
tabEdit
}),
})
if(ret){
this.initLoad()
}else {
// 关闭弹框和页面
}
}else{
this.injections.reduce('upDateStart', 'data.other.enableTime', query)
this.queryTime = query
this.initLoad() // 启用存货核算
}
}
initLoad = async(inventoryPropertyId) => {
this.metaAction.sf('data.other.loading', true)
const { enabledMonth, enabledYear, periodDate } = this.metaAction.context.get('currentOrg') //获取全局的启用日期
if(periodDate) {
let a = this.queryTime.replace('-',''), b = periodDate.replace('-',''), searchTime
if(a < b){
searchTime = periodDate
}else{
searchTime = this.queryTime
}
const date = utils.date.transformMomentDate(searchTime)
this.injections.reduce('upDateStart', 'data.searchValue.startDate', date)
}
let startDate
if(periodDate){
startDate = periodDate
}else{
let search = this.metaAction.gf('data.searchValue').toJS()
startDate = this.metaAction.momentToString(search.startDate,'YYYY-MM')
}
let filter = {
beginAccountingYear: startDate && startDate.slice(0,4),
beginAccountingPeriod: startDate && startDate.substring(5),
endAccountingYear: startDate && startDate.slice(0,4),
endAccountingPeriod: startDate && startDate.substring(5),
inventoryPropertyId
}
let initSummaryRpt = await this.webapi.inventory.initSummaryRpt(filter) //初始化
this.metaAction.sf('data.other.loading', false)
this.injections.reduce('load', initSummaryRpt)
}
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-inventory-table')[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('updateOption', { 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('ttk-scm-app-inventory-table')[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('updateOption', { path: 'data.tableOption', value: tableOption })
}
}
}
}, 100)
}
componentWillUnmount = () => {
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
}
}
renderEmpty = () => {
return (
<div className='emptyList'>
<img class="mk-nodata-img" src={img} />
<span class="mk-nodata-message">暂无数据</span>
</div>)
}
onTabFocus = async (props) => {
this.refresh()
}
filterOptionSummary = (input, option) => {
if (option && option.props && option.props.children) {
return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
return true
}
//获取时间选项
getNormalDateValue = () => {
const data = this.metaAction.gf('data.searchValue').toJS()
return data.startDate
}
handleDisabledDate = (current) => {
if (current) {
let enableTime = this.metaAction.gf('data.other.enableTime'), currentDate = current.format('YYYY-MM')
if (enableTime) enableTime = enableTime.replace(/-/g, '')
if (currentDate) currentDate = currentDate.replace(/-/g, '')
return currentDate && currentDate < enableTime
}
}
// 普通查询时间改变
changeDate = (value) => {
let date = utils.moment.stringToMoment(value).endOf('month')
this.metaAction.sf('data.searchValue.startDate',date)
this.metaAction.sf('data.form.startDate',date)
let type = this.metaAction.gf('data.form.typeId')
let filter
if(type){
filter = {
beginAccountingYear: value.slice(0,4),
beginAccountingPeriod: value.substring(5),
endAccountingYear: value.slice(0,4),
endAccountingPeriod: value.substring(5),
inventoryPropertyId: type,
}
}else{
filter = {
beginAccountingYear: value.slice(0,4),
beginAccountingPeriod: value.substring(5),
endAccountingYear: value.slice(0,4),
endAccountingPeriod: value.substring(5),
}
}
this.getSearchList(filter)
}
getSearchCard = (childrenRef) => {
this.searchCard = childrenRef
}
// 高级查询
searchValueChange = (value) => {
this.injections.reduce('searchUpdate', value)
this.getSearchList()
}
// 存货属性修改
selectType = (v) => {
let value
if(v) value = v.value
this.injections.reduce('upDate', value)
this.getSearchList()
}
refresh = () => {
let type = this.metaAction.gf('data.form.typeId')
if(type){
this.initLoad(type)
}else{
this.initLoad()
}
}
// 查询方法
getSearchList = async() => {
let searchValue = this.metaAction.gf('data.searchValue').toJS(),
startDate = this.metaAction.momentToString(searchValue.startDate,'YYYY-MM')
let inventoryPropertyId = searchValue.type
let filter = {
beginAccountingYear: startDate.slice(0,4),
beginAccountingPeriod: startDate.substring(5),
endAccountingYear: startDate.slice(0,4),
endAccountingPeriod: startDate.substring(5),
inventoryPropertyId
}
this.metaAction.sf('data.other.loading', true)
const res = await this.webapi.inventory.getInventory(filter)
if(res) this.injections.reduce('load', {getList: res})
this.metaAction.sf('data.other.loading', false)
setTimeout(() => {
this.onResize()
}, 100)
}
noCell = (text, row, index) => {
if(!text) return
text = utils.number.format(text,2)
let obj
obj = {
children: <span title={text}>{text}</span>,
props: {
colSpan: 1
}
}
return obj
}
noCell2 = (text, row, index) => {
if(!text) return
text = utils.number.format(text,6)
let obj
obj = {
children: <span title={text}>{text}</span>,
props: {
colSpan: 1
}
}
return obj
}
cellSum = (text, row, index) => {
let obj
if (row && !row.inventoryName) {
obj = {
props: {
colSpan: 0,
}
}
} else {
obj = {
children: <span title={text}>{text}</span>,
props: {
colSpan: 1
}
}
}
return obj
}
cellName = (text, row, index) => { //存货名称
let obj
if (row && !row.inventoryName) {
obj = {
children: <span title='合计' style={{textAlign:'center !important'}}>合计</span>,
props: {
colSpan: 4,
}
}
} else {
obj = {
children: <a onClick={()=>this.toDetail(row.inventoryId)} title={text}>{text}</a>,
props: {
colSpan: 1
}
}
}
return obj
}
// 跳转到明细表
toDetail = (id) => {
this.detailTable('detail',id)
}
tableColumns = () => {
let cellArr = [this.noCell, this.cellName, this.cellSum, this.noCell2]
return renderColumns(...cellArr)
}
// 生成凭证
getVoucher = ()=> {
}
// 成本计算
// 1、如果存在生成凭证的单据的月份,不能进行成本计算
// 2、已经月结的月份,不能进行计算成本
// 3、点击计算成本,如果上月未结账,提示“上月未结账,不能计算成本!”
calculateCost = async() =>{
let searchValue = this.metaAction.gf('data.searchValue').toJS(),
startDate = this.metaAction.momentToString(searchValue.startDate,'YYYY-MM'),
enableTime = this.metaAction.gf('data.other.enableTime')
// let filter = {
// beginAccountingYear: startDate.slice(0,4),
// beginAccountingPeriod: startDate.substring(5),
// endAccountingYear: startDate.slice(0,4),
// endAccountingPeriod: startDate.substring(5),
// }
let res = await this.webapi.inventory.reCalcCost()
if(res) {
this.metaAction.toast('success', '计算成功')
this.refresh()
}
}
// 设置
setting = async() => {
const ret = await this.metaAction.modal('show', {
title: '设置',
wrapClassName: 'inventory-card',
width: 400,
okText: '确定',
bodyStyle: {padding: '10px 25px 10px 50px'},
children: this.metaAction.loadApp('ttk-scm-app-inventory-setting', {
store: this.component.props.store,
// enabledPeriod,
// tabEdit
}),
})
}
// 导出
export = async() => {
let list = this.metaAction.gf('data.other.tableList')
list = list.size ? list.toJS() : list
if(list.length){
let searchValue = this.metaAction.gf('data.searchValue').toJS(),
startDate = this.metaAction.momentToString(searchValue.startDate,'YYYY-MM')
let inventoryPropertyId = searchValue.type
let filter = {
beginAccountingYear:startDate.slice(0,4),
beginAccountingPeriod: startDate.substring(5),
endAccountingYear:startDate.slice(0,4),
endAccountingPeriod:startDate.substring(5),
inventoryPropertyId
}
let res = await this.webapi.inventory.export(filter)
if(res) this.metaAction.toast('success', '导出成功')
}else{
this.metaAction.toast('warning', '当前没有可导出数据')
return false
}
}
//打印
print = async() => {
let list = this.metaAction.gf('data.other.tableList')
list = list.size ? list.toJS() : list
if(list.length){
let searchValue = this.metaAction.gf('data.searchValue').toJS(),
startDate = this.metaAction.momentToString(searchValue.startDate,'YYYY-MM')
let inventoryPropertyId = searchValue.type
let filter = {
beginAccountingYear:startDate.slice(0,4),
beginAccountingPeriod: startDate.substring(5),
endAccountingYear:startDate.slice(0,4),
endAccountingPeriod:startDate.substring(5),
inventoryPropertyId
}
let res = await this.webapi.inventory.print(filter)
if(res) this.metaAction.toast('success', '打印成功')
}else{
this.metaAction.toast('warning', '当前没有可打印数据')
return false
}
}
detailTable = async (name,id) => { // 出入库明细表
if (!this.config.apps['ttk-scm-app-warehouse-detail']) {
throw '依赖ttk-scm-app-warehouse-detail app,请使用mk clone ttk-scm-app-warehouse-detail命令添加'
}
if(name == 'detail'){
this.component.props.setPortalContent('出入库明细表', 'ttk-scm-app-warehouse-detail', {accessType: id})
}else{
this.component.props.setPortalContent('出入库明细表', 'ttk-scm-app-warehouse-detail')
}
}
addInventory = async () => { // 库存单据
if (!this.config.apps['ttk-scm-app-inventory-documents']) {
throw '依赖ttk-scm-app-inventory-documents app,请使用mk clone ttk-scm-app-inventory-documents命令添加'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('库存单据', 'ttk-scm-app-inventory-documents')
}
addAAAAA = async () => { // 存货期初
if (!this.config.apps['ttk-scm-app-warehouse-beginning']) {
throw '依赖ttk-scm-app-warehouse-beginning app,请使用mk clone ttk-scm-app-warehouse-beginning'
}
this.component.props.setPortalContent &&
this.component.props.setPortalContent('存货期初', 'ttk-scm-app-warehouse-beginning')
}
linkToEstimateList = () => {
this.component.props.setPortalContent &&
this.component.props.setPortalContent('暂估存货', 'ttk-scm-app-estimate-list')
}
}
export default function creator(option) {
const metaAction = new MetaAction(option),
extendAction = extend.actionCreator({ ...option, metaAction }),
o = new action({ ...option, metaAction, extendAction }),
ret = { ...metaAction, ...extendAction.gridAction, ...o }
metaAction.config({ metaHandlers: ret })
return ret
}
// const EditableCell = ({ value, onBlur, onEnter}) => {
// return (
// <div style={{textAlign: 'right'}}>
// <Input.Number
// // key={Math.random()}
// style={{ margin: '-5px 0' }}
// // customAttribute={customAttribute}
// // className='app-account-beginbalance-tableClass'
// // onPressEnter={(e) => onEnter(e)}
// value={value}
// // onBlur={(value) => onBlur(value)}
// regex='^(-?[0-9]+)(?:\.[0-9]{1,2})?$'/>
// }
// </div>
// )
// }