ttk-app-core
Version:
enterprise develop framework
169 lines (152 loc) • 5.16 kB
JavaScript
import React from 'react'
import {action as MetaAction, AppLoader} from 'edf-meta-engine'
import {Menu, Checkbox, DataGrid, Icon} from 'edf-component'
import utils from 'edf-utils';
import Message from './components/Message.js'
import extend from './extend'
import config from './config'
import data from '../../scm/ttk-scm-app-inventory-documents/utils/gridItem';
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
injections.reduce('init')
this.load()
// 再次进入 refresh
let addEventListener = this.component.props.addEventListener;
if (addEventListener) {
addEventListener('onTabFocus', :: this.load);
}
}
load = async (page, option) => {
if (!page) {
const form = this.metaAction.gf('data.pagination').toJS()
page = {currentPage: form.current, pageSize: form.pageSize}
}
this.metaAction.sf('data.other.loading', true)
this.getData(page).then((res) => {
this.injections.reduce('load', res)
this.metaAction.sf('data.other.loading', false)
})
}
heightCount = () => {
let name = ''
if (this.component.props.modelStatus && (this.component.props.modelStatus == 1 || this.component.props.modelStatus == 2)) {
name = "ttk-omp-app-message-list-contentHeight"
}
return name
}
getListRowsCount = () => {
return this.metaAction.gf('data.list').size
}
selectRow = (rowIndex) => (e) => {
this.injections.reduce('selectRow', rowIndex, e.target.checked)
}
//分页修改
pageChanged = (currentPage, pageSize) => {
if (pageSize == null || pageSize == undefined) {
pageSize = this.metaAction.gf('data.pagination').toJS().pageSize
}
let page = {currentPage, pageSize}
const data = this.metaAction.gf('data.searchValue').toJS()
this.metaAction.sf('data.other.loading', true)
this.getData(page, data).then((res) => {
this.injections.reduce('load', res)
this.metaAction.sf('data.other.loading', false)
})
}
//获取列表内容
getData = async (pageInfo, searchValue) => {
let response,
pagination = this.metaAction.gf('data.pagination'),
page = {
pageSize: pagination.toJS().pageSize
}
if (pageInfo && pageInfo['currentPage']) {
page.currentPage = pageInfo.currentPage
page.pageSize = pageInfo.pageSize
}
for (var attr in searchValue){
if(!searchValue[attr]){
delete searchValue[attr]
}
}
response = await this.webapi.message.queryList({page, ...searchValue})
return response
}
// search = () => {
// const data = this.metaAction.gf('data.searchValue').toJS()
// this.metaAction.sf('data.other.loading', true)
// this.getData({pageSize: 50, currentPage: 1}, data).then((res) => {
// this.injections.reduce('load', res)
// this.metaAction.sf('data.other.loading', false)
// })
// }
// dateSelect = (value) => {
// let selectNode = document.getElementsByClassName('selectDate')
// selectNode && selectNode[1] && selectNode[1].firstChild.firstChild.click()
// this.metaAction.sf('data.searchValue.beginDate', this.metaAction.momentToString(value, 'YYYY-MM-DD'));
// }
//
// dateSelect2 = (value) => {
// this.metaAction.sf('data.searchValue.endDate', this.metaAction.momentToString(value, 'YYYY-MM-DD'));
// }
export = () => {
this.metaAction.toast('warn', '功能暂未实现!')
}
//预览
preview = (data, index) => {
let msgContent = data.content, modalTitle = data.title;
let setContent = this.component.props.setPortalContent
this.metaAction.sf('data.showModal', true);
this.metaAction.sf('data.modalData', <Message setContent={setContent} msgText={msgContent} />);
this.metaAction.sf('data.modalTitle', modalTitle);
}
//隐藏预览
hideModal = () => {
this.metaAction.sf('data.showModal', false)
}
//删除消息
delete = async (data) => {
let response, obj = {id: data.id, ts: data.ts}
response = await this.webapi.message.delete(obj)
if(response){
this.metaAction.toast('success', '删除成功');
this.load();
}
}
//编辑消息
edit = async (data) => {
const ret = await this.metaAction.modal('show', {
title: '编辑消息',
className: 'ttk-omp-app-message-list-editMessage',
width: 800,
height: 673,
cancelText: '取消',
okText: '保存',
children: this.metaAction.loadApp('ttk-omp-app-message', {
store: this.component.props.store,
messsageData: data,
buttonList: false
})
});
if (ret) {
this.load();
}
}
}
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
}