import React from "react"; import _ from 'lodash'; import $ from 'jquery'; import * as API from '../apis/prjReportApi'; import {Row, Col, Progress, Tooltip, message, InputNumber, Popover, Button } from 'antd'; import {observable, action, toJS} from "mobx"; import {WeaDatePicker, WeaInput, WeaBrowser, WeaLocaleProvider, WeaInputNumber, WeaError} from "ecCom"; import {FeedBackInfoStore} from "./portal/feedBackInfoStore" import {FeedBackSettingStore} from "./portal/feedBackSettingStore" const getLabel = WeaLocaleProvider.getLabel; export class ReportStore { @observable prjid = ""; @observable modeInfo = {};wEAver2018 @observable projInfo = {}; @observable columns = []; @observable tableDatas = []; @observable tableForamtDatas = []; @observable dialogVisible = false; @observable dialogData = {}; @observable dialogSource = {}; @observable columnsWidth = true; @observable submitHash = {}; @observable submitData = []; @observable expandedRowKeys = []; @observable nowVersionSelected = '0'; @observable monthOptions = []; @observable canSave = true; @observable submitLoading = false; @observable submitTip = "正在生成流程视图数据,请稍后..."; @observable remind1 = new Array(); @observable remind2 = new Array(); @observable remind3 = new Array(); @observable remind4 = new Array(); @observable feedBackInfoStore = new FeedBackInfoStore(); @observable feedBackSettingStore = new FeedBackSettingStore(); @observable prjstatus = ""; @observable type = ""; //反馈周期 @observable activity = ""; //当前活动周期 @action init = (prjid) => { this.prjid = prjid; this.onQueryData(true); this.nowVersionSelected = '0'; } @action onQueryData = (isInit) => { if (!this.prjid) return; this.tableDatas = []; this.tableForamtDatas = []; this.remind1 = new Array(); this.remind2 = new Array(); this.remind3 = new Array(); this.remind4 = new Array(); API.getFeedBackData({prjid: this.prjid}).then(({columns, datas, projInfo, month, type, activity}) => { // if (!msg) { // let month = ["201908", "201909"]; // let columns = [{ // dataIndex: "name", // width: 250, // fixed: "left", // title: "任务名称", // key: "name" // }, { // dataIndex: "hrmids", // width: 60, // title: "小组经理", // key: "hrmids" // }, { // dataIndex: "dateRange", // width: 150, // title: "时间段", // key: "dateRange" // }, { // dataIndex: "islandmark", // width: 50, // title: "里程碑", // key: "islandmark" // }, { // dataIndex:"progress", // width: 45, // title: "进度", // key: "progress" // }, { // children: [{ // dataIndex: "planCtx_201908", // width: 170, // title: "计划内容", // key: "planCtx_201908" // }, { // dataIndex: "finishTime_201908", // width: 125, // title: "完成时间", // key: "finishTime_201908" // }, { // dataIndex: "assistUser_201908", // width: 125, // title: "配合人员", // key: "assistUser_201908" // }, { // dataIndex: "progress_201908", // width: 50, // title: "进度", // key: "progress_201908" // }, { // dataIndex: "finishCtx_201908", // width: 180, // title: "完成情况", // key: "finishCtx_201908" // }, { // dataIndex: "unFinishReason_201908", // width: 80, // title: "未完成原因", // key: "unFinishReason_201908" // }], // title: "2019年8月" // }, { // children: [{ // dataIndex: "planCtx_201909", // width: 170, // title: "计划内容", // key: "planCtx_201909" // }, { // dataIndex: "finishTime_201909", // width: 125, // title: "完成时间", // key: "finishTime_201909" // }, { // dataIndex: "assistUser_201909", // width: 125, // title: "配合人员", // key: "assistUser_201909" // }, { // dataIndex: "progress_201909", // width: 50, // title: "进度", // key: "progress_201909" // }, { // dataIndex: "finishCtx_201909", // width: 180, // title: "完成情况", // key: "finishCtx_201909" // }, { // dataIndex: "unFinishReason_201909", // width: 80, // title: "未完成原因", // key: "unFinishReason_201909" // }, { // dataIndex: "caozuo_201909", // width: 80, // title: "操作", // key: "caozuo_201909" // }], // title: "2019年9月" // }] // let datas = [{ // islandmark: "否", // hrmids: [{ // name: "杨文元-tw", // id: "21" // }], // unFinishReason_201908: "111", // finishTime_201909: "", // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: "", // finishTime_201908: "", // unFinishReason_201909: "", // assistUser_201909: "", // assistUser_201908: "", // hbid_201908: "7", // hbid_201909: "45", // children: [{ // islandmark: "否", // unFinishReason_201908: { // viewAttr: 1, // value: "" // }, // finishTime_201909: { // viewAttr: 1, // value: "2019-09-30" // }, // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: { // viewAttr: 1, // value: "test" // }, // finishTime_201908: { // viewAttr: 1, // value: "2019-08-26" // }, // unFinishReason_201909: { // viewAttr: 1, // value: "" // }, // assistUser_201909: { // viewAttr: 1, // value: [] // }, // assistUser_201908: { // viewAttr: 1, // value: [] // }, // hbid_201908: 11, // hbid_201909: 47, // caozuo_201909:"11", // name: "test", // finishCtx_201909: { // viewAttr: 1, // value: [{ // cjsj: "2019-09-11", // attachids: "", // ctx: "ddd", // attach: [], // wcnrid: "26" // }] // }, // progress: "-1%", // planCtx_201909: { // viewAttr: 1, // value: "test" // }, // finishCtx_201908: { // viewAttr: 1, // value: [] // }, // key: 502, // progress_201909: { // viewAttr: 1, // value: 0.0 // }, // progress_201908: { // viewAttr: 1, // value: 0.0 // } // }, { // islandmark: "否", // unFinishReason_201908: { // viewAttr: 1, // value: "" // }, // finishTime_201909: { // viewAttr: 1, // value: "2019-09-30" // }, // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: { // viewAttr: 1, // value: "test2" // }, // finishTime_201908: { // viewAttr: 1, // value: "2019-08-26" // }, // unFinishReason_201909: { // viewAttr: 1, // value: "" // }, // assistUser_201909: { // viewAttr: 1, // value: [] // }, // assistUser_201908: { // viewAttr: 1, // value: [] // }, // hbid_201908: 9, // hbid_201909: 46, // name: "test2", // finishCtx_201909: { // viewAttr: 1, // value: [{ // cjsj: "2019-09-11", // attachids: "", // ctx: "tt", // attach: [], // wcnrid: "25" // }] // }, // progress: "-1%", // planCtx_201909: { // viewAttr: 1, // value: "test2" // }, // finishCtx_201908: { // viewAttr: 1, // value: [] // }, // key: 503, // progress_201909: { // viewAttr: 1, // value: 0.0 // }, // progress_201908: { // viewAttr: 1, // value: 0.0 // } // }], // name: "工作包001", // finishCtx_201909: "", // progress: "15%", // planCtx_201909: "", // finishCtx_201908: "", // key: 1, // progress_201909: { // viewAttr: 3, // value: 15 // }, // progress_201908: { // viewAttr: 1, // value: 15 // } // }, { // islandmark: "否", // hrmids: [{ // name: "杨文元-tw", // id: "21" // }], // unFinishReason_201908: "", // finishTime_201909: "", // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: "", // finishTime_201908: "", // unFinishReason_201909: "", // assistUser_201909: "杨文元-tw", // assistUser_201908: "", // hbid_201908: "8", // hbid_201909: "41", // children: [{ // islandmark: "否", // unFinishReason_201908: { // viewAttr: 1, // value: "" // }, // finishTime_201909: { // viewAttr: 1, // value: "2019-09-30" // }, // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: { // viewAttr: 1, // value: "test3" // }, // finishTime_201908: { // viewAttr: 1, // value: "2019-08-26" // }, // unFinishReason_201909: { // viewAttr: 1, // value: "" // }, // assistUser_201909: { // viewAttr: 1, // value: [] // }, // assistUser_201908: { // viewAttr: 1, // value: [] // }, // hbid_201908: 12, // hbid_201909: 44, // name: "test3", // finishCtx_201909: { // viewAttr: 1, // value: [{ // cjsj: "2019-09-11", // attachids: "", // ctx: "test", // attach: [], // wcnrid: "24" // }] // }, // progress: "-1%", // planCtx_201909: { // viewAttr: 1, // value: "test3" // }, // finishCtx_201908: { // viewAttr: 1, // value: [] // }, // key: 504, // progress_201909: { // viewAttr: 1, // value: 100.0 // }, // progress_201908: { // viewAttr: 1, // value: 0.0 // } // }, { // islandmark: "否", // unFinishReason_201908: { // viewAttr: 1, // value: "" // }, // finishTime_201909: { // viewAttr: 1, // value: "2019-09-30" // }, // dateRange: ["2019-08-26", "2019-08-26"], // planCtx_201908: { // viewAttr: 1, // value: "test4" // }, // finishTime_201908: { // viewAttr: 1, // value: "2019-08-26" // }, // unFinishReason_201909: { // viewAttr: 1, // value: "" // }, // assistUser_201909: { // viewAttr: 1, // value: [] // }, // assistUser_201908: { // viewAttr: 1, // value: [] // }, // hbid_201908: 10, // hbid_201909: 42, // name: "test4", // finishCtx_201909: { // viewAttr: 1, // value: [{ // cjsj: "2019-09-11", // attachids: "", // ctx: "test2", // attach: [], // wcnrid: "23" // }, { // cjsj: "2019-09-11", // attachids: "", // ctx: "test", // attach: [], // wcnrid: "22" // }] // }, // progress: "-1%", // planCtx_201909: { // viewAttr: 1, // value: "test4" // }, // finishCtx_201908: { // viewAttr: 1, // value: [] // }, // key: 505, // progress_201909: { // viewAttr: 1, // value: 100.0 // }, // progress_201908: { // viewAttr: 1, // value: 0.0 // } // }, { // islandmark: "否", // unFinishReason_201908: { // viewAttr: 1, // value: "" // }, // finishTime_201909: { // viewAttr: 1, // value: "2019-09-30" // }, // dateRange: ["2019-10-08", "2019-10-26"], // planCtx_201908: { // viewAttr: 1, // value: "test5" // }, // finishTime_201908: { // viewAttr: 1, // value: "2019-08-26" // }, // unFinishReason_201909: { // viewAttr: 1, // value: "" // }, // assistUser_201909: { // viewAttr: 1, // value: [] // }, // assistUser_201908: { // viewAttr: 1, // value: [] // }, // hbid_201908: 21, // hbid_201909: 43, // name: "test5", // finishCtx_201909: { // viewAttr: 1, // value: [{ // cjsj: "2019-09-11", // attachids: "", // ctx: "test", // attach: [], // wcnrid: "21" // }] // }, // progress: "-1%", // planCtx_201909: { // viewAttr: 1, // value: "test5" // }, // finishCtx_201908: { // viewAttr: 1, // value: [] // }, // key: 1001, // progress_201909: { // viewAttr: 1, // value: 100.0 // }, // progress_201908: { // viewAttr: 1, // value: 0.0 // } // }], // name: "工作包002", // finishCtx_201909: "", // progress: "11%", // planCtx_201909: "", // finishCtx_201908: "", // key: 501, // progress_201909: { // viewAttr: 3, // value: 100 // }, // progress_201908: { // viewAttr: 1, // value: 11 // } // }]; // let projInfo = { // prjstatus: 11, // manager: "1", // jindu: "", // name: "测试项目001", // statusname: "计划变更", // id: 1, // version: [{ // showname: "当前版本", // key: "0", // selected: true // }] // }; this.columns = columns; if (this.columns && this.columns.length <= 1) { this.columns = this.columns.map(col => { col.fixed = ""; return col }); $('.ant-table-content').css('padding-left', '0'); } this.computeColumnsWidth(this.columns); this.tableDatas = datas; this.tableForamtDatas = this.compileByType(this.tableDatas); if (isInit) { this.expandedRowKeys = this.tableForamtDatas.map(f => f.key); } this.projInfo = projInfo; month&&(this.monthOptions=[...month].map((mon) => { return { showname: mon, key: mon } })); projInfo&&(this.prjstatus=projInfo.prjstatus); this.type = type; this.activity = activity; // } else { // message.warning(res.msg) // } }) } @action onExpandedRowKeysChange = (Keys) => { this.expandedRowKeys = Keys; } @action onEditionChange = (key) => { this.nowVersionSelected = key; this.onQueryData(this.prjid, key); } // @action // saveData = (key) => { // let check = true; // if (!this.submitData.length && key === '2') { // message.error("无数据修改"); // return; // } // if (key === '1') { // toJS(this.remind1).map(c => { // if (c && !c.props.children.props.value && c.props.children.props.viewAttr == "3") { // c.showError(); // check = false; // } // }); // toJS(this.remind2).map(c => { // if (c && !c.props.children.props.value && c.props.children.props.viewAttr == "3") { // c.showError(); // check = false; // } // }); // toJS(this.remind3).map(c => { // if(c&&c.props.children.props.replaceDatas&&(c.props.children.props.replaceDatas[0]?!c.props.children.props.replaceDatas[0].id:!c.props.children.props.replaceDatas[0])&&c.props.children.props.viewAttr=="3"){ // c.showError(); // check = false; // } // }); // } // if(!check){ // message.error("请检查必填项"); // return; // } // const jsondata = JSON.stringify(this.submitData) // if (key === '2') { // this.submitTip = "数据保存中,请稍后..."; // this.submitLoading = true; // API.save({jsondata, projId: this.prjid}).then(res => { //保存 // this.submitLoading = false; // if ('' + res.code === '200') { // this.submitData = []; // this.submitHash= []; // message.success(res.msg) // this.onQueryData(this.prjid,{}); // } else { // message.warning(res.msg) // } // }) // } else if (key === '1') { //提交 // this.submitTip = "正在生成流程视图数据,请稍后..."; // this.submitLoading = true; // API.submit({jsondata, projId: this.prjid}).then(res => { // this.submitLoading = false; // if ('' + res.code === '200') { // this.submitData = []; // this.submitHash= []; // message.success(res.msg) // window.open(res.datas.linkUrl, '_blank'); // } else { // message.warning(res.msg) // } // }) // } // } @action computeColumnsWidth = (columns) => { this.columnsWidth = 0; if (!(columns && columns.length)) return '0'; columns.forEach(col => { if (col.children) { col.children.forEach(child => { if (child.width) { this.columnsWidth += child.width } else { this.columnsWidth += 200 } }) } }) } @action compileByType = (datas, parentIndex = null) => { let tempDatas = []; _.forEach(datas, (item, index) => { const tempObj = {}; _.forIn(item, (valueObj, key) => { if (key == 'key') { tempObj[key] = valueObj; } else { let value = valueObj.hasOwnProperty('value') ? valueObj['value'] : valueObj, // viewAttr = valueObj.hasOwnProperty('viewAttr') ? valueObj['viewAttr'] : 1; viewAttr = 1; if (_.startsWith(key, 'progress') && value !== "") { value = parseFloat(value)<0?0:parseFloat(value); if (!_.startsWith(key, 'progress_')) { tempObj[key] = (
) } else { if ('' + viewAttr === '1') { tempObj[key] = (
{value}%
) } else { tempObj[key] = (
{ if (val === '' || val < 0) { val = 0 } this.changeData(val, index, key, parentIndex, item) }} />
) } } } else if (key === 'dateRange' && (value[0] || value[1])) { const beginDate = value[0]?value[0]:'', endDate = value[1]?value[1]:''; const renderDate = (date) => { return date; // const dateArr = date.split("-"); // return `${dateArr[0]}-${dateArr[1]}-${dateArr[2]}` } tempObj[key] = (
{renderDate(beginDate)} - {renderDate(endDate)}
) } else if (key === 'hrmids') { tempObj[key] = () } else if (_.startsWith(key, 'assistUser_')) { //配合人员 tempObj[key] = ( { // this.changeData(data, index, key, parentIndex, item) // }} />) }else if (_.startsWith(key, 'finishTime_')) { //完成时间 // tempObj[key] = ( { // this.remind1.push(ref); // }} // error={getLabel(385869,"此项必填")} // tipPosition="left" // > { // this.changeData(val, index, key, parentIndex, item) // }} // />) tempObj[key] = ( { this.changeData(val, index, key, parentIndex, item) }} />) } else if (_.startsWith(key, 'planCtx_')) { //计划内容 const tempArr = key.split("_"); const total = tempArr[0] + 'Total_' + tempArr[1]; tempObj[key] = ( {/* { this.remind1.push(ref); }} error={getLabel(385869,"此项必填")} tipPosition="left" > { this.changeData(val, index, key, parentIndex, item) }} /> */} { this.changeData(val, index, key, parentIndex, item) }} />
{item[total] && item[total] > 0 && { this.onToggleDialog(true, value, { type: 'plan', index, key, parentIndex, item, modeInfo: this.modeInfo }) }} title={item[total]}>{item[total]}} {viewAttr > 1 && { this.onToggleDialog(true, value, { type: 'plan', index, key, parentIndex, item, modeInfo: this.modeInfo }) }} />}
) } else if (_.startsWith(key, 'finishCtx_')) { //完成情况 const planCtx = `planCtx_${key.split("_")[1]}`; const viewAttrCopy = item[planCtx] && item[planCtx]['viewAttr'] ? item[planCtx]['viewAttr'] : 1; const len = value.length || 0; value = _.isArray(toJS(value)) && value.length ? value : []; const showData = len == 0 ? "" : value[len - 1]['ctx']; let showDatas = ""; let content = []; value.length > 0 && value.map((item,index)=>{ content.push(

{index+1}.{item.ctx && item.ctx} {item.cjsj && item.cjsj}

) }) value.map(item=>{ showDatas += (item.ctx+"\r\n") }); tempObj[key] = ( {/* {content}} placement="left" trigger="hover"> */} { viewAttr == 3 && { this.remind1.push(ref); }} error={getLabel(385869,"此项必填")} tipPosition="left" > { value[len - 1] = {...value[len - 1], ctx: val} this.changeData(value, index, key, parentIndex, item) }}/> } { viewAttr == 1 && {showData} } {/* */} {/* */}
{len > 0 && item[key.replace('finishCtx','caozuo')] && { // console.log(111,item[key.replace('finishCtx','caozuo')],item) this.onToggleDialog(true, value, { type: 'condition', index, key, parentIndex, item, mainid:item[key.replace('finishCtx','caozuo')] }) }} title={len}>{len} } {viewAttrCopy > 1 && { this.onToggleDialog(true, value, { type: 'condition', index, key, parentIndex, item }) }} />}
) } else if (_.startsWith(key, 'unFinishReason_')) { //未完成原因 let content={value} tempObj[key] = ( {content}} placement="left" trigger="hover"> { this.changeData(val, index, key, parentIndex, item) }} />) } else if (_.startsWith(key, 'caozuo_')) { //操作项 let content={value} tempObj[key] = ( ); } else if (!item['children']) { tempObj[key] = ({value}); } else { if (key === 'children' && value.length) { //递归解析树形结构 tempObj[key] = this.compileByType(item.children, index + '') } else { //纯文本显示值 tempObj[key] = ({value}); } } } }) tempDatas.push(tempObj) }) // console.log(tempDatas); return tempDatas; } @action openDialog = (value) => { this.feedBackInfoStore.handleFeedBackInfoDialog(true,{id:value}); } @action changeData = (value, index, key, parentIndex, item) => { this.onDataChange(value, index, key, parentIndex, item) } @action onDataChange = (value, index, key, parentIndex, item) => { // console.log(value, index, key, parentIndex, item); //处理数据显示 if (parentIndex) { if (_.startsWith(key, 'planCtxTotal_')) { const data = this.tableDatas[parentIndex].children[index][key]; const viewAttr = data.hasOwnProperty('viewAttr') ? data.viewAttr : ""; //获取数据原本的viewAttr this.tableDatas[parentIndex].children[index][key] = viewAttr ? {value, viewAttr} : value; } else if (_.startsWith(key, 'finishCtx_')){ // console.log(toJS(this.tableDatas[parentIndex].children[index][key])); const data = this.tableDatas[parentIndex].children[index][key]; const viewAttr = data.hasOwnProperty('viewAttr') ? data.viewAttr : ""; //获取数据原本的viewAttr let finshCtxs = []; value.map(item=>{ let attachids = []; let attachs = item.attach; attachs.length > 0 && attachs.map(attach=>{ attachids.push(attach['fileid']); }) let newitem = { ...item, attachids : attachids } finshCtxs.push(newitem); }); this.tableDatas[parentIndex].children[index][key] = viewAttr ? {value : finshCtxs, viewAttr} : finshCtxs; }else { const data = this.tableDatas[parentIndex].children[index][key]; const viewAttr = data.hasOwnProperty('viewAttr') ? data.viewAttr : ""; //获取数据原本的viewAttr // if (viewAttr == '3' && !('' + value)) { // return; // } this.tableDatas[parentIndex].children[index][key] = viewAttr ? {value, viewAttr} : {value}; } } else { this.tableDatas[index][key].value = value; } this.tableForamtDatas = this.compileByType(this.tableDatas) //处理数据保存 const id = item['hbid_' + key.split('_')[1]]; const formatKey = key.split("_")[0]; //配合人员特殊处理 if (formatKey == "assistUser") { let value_ = value; let assistUserIds = []; if (value_.length > 0) { value_.map(item => { assistUserIds.push(parseInt(item.id)); }); } value = assistUserIds; } let finshCtxs = []; let param = { id, key: item['key'], [formatKey]: value, }; //完成情况相关附件特殊处理 if (_.startsWith(key, 'finishCtx_')){ value.map(item=>{ let attachids = []; let attachs = item.attach; attachs.length > 0 && attachs.map(attach=>{ attachids.push(attach['fileid']); }) let newitem = { ...item, attachids : attachids } finshCtxs.push(newitem); }); param = { id, key: item['key'], [formatKey]: finshCtxs, }; } if (!this.submitHash[""+id]) { this.submitData.push(param); this.submitHash = { ...this.submitHash, [id] : '' + (this.submitData.length - 1) } } else { this.submitData[this.submitHash[""+id]] = Object.assign(this.submitData[this.submitHash[id]], param); } } @action onToggleDialog = (bool, data, dialogSource = {}) => { this.dialogVisible = bool; this.dialogData = data; this.dialogSource = dialogSource; } @action getLineClass = () => { this.lineindex ++ ; if(this.lineindex % 2 == 1){ return "dark-row" }else{ return "light-row" } } @action setDialogData = (v) => { this.dialogData = v; } @action saveMxDatas = () =>{ const mxParams = JSON.stringify({mxdatas:toJS(this.dialogData)}); const params = {mainid:this.dialogSource.mainid,mxdatas:mxParams} API.saveMxDatas(params).then(data=>{ if(data.success){ message.success(getLabel(18758,"保存成功")); this.onToggleDialog(false); this.onQueryData(true); }else{ message.error(getLabel('507580','出现错误!对不起,您暂时没有权限!!')); } }) } } export default new ReportStore();