123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476 |
- import { ajax, cardCache, toast } from 'nc-lightapp-front';
- import { REQUEST_URL, CARD, PRIMARY_KEY, CARD_BUTTON, CARD_CACHE, DATASOURCE, STATUS, FIELD, BILL_TYPE_CODE, CARD_ADD_DISABLED_BUTTON } from '../../constant';
- import { buttonVisibilityControl } from './buttonVisibilityControl';
- import { afterHeadEvent } from './afterHeadEvent';
- let { updateCache, addCache, getNextId, deleteCacheById, getCacheById, getCurrentLastId } = cardCache;
- //卡片返回
- export function cardBack(props) {
- props.pushTo(REQUEST_URL.toList, {});
- }
- //卡片新增
- export function cardCreate(props) {
- props.setUrlParam({ status: STATUS.add });
- //单据有主组织,新增时,将其他字段设置为不可编辑
- props.initMetaByPkorg();
- props.button.setButtonDisabled(CARD_ADD_DISABLED_BUTTON, true);
- props.cardTable.setAllCheckboxAble(CARD.table_code, false);
- clearAll(props);
- setByStatus(props);
- let { getDefData } = cardCache;
- let context = getDefData(CARD_CACHE.key, CARD_CACHE.dataSource);
- if (context) {
- let { pk_org, org_Name} = context;
- props.form.setFormItemsValue(CARD.form_id, {
- [FIELD.org]: { value: pk_org, display: org_Name }
- });
- afterHeadEvent(props, CARD.form_id, FIELD.org, { display: org_Name, value: pk_org }, { display: null, value: null });
- }
- }
- /**
- * 根据状态设置卡片
- * @param {*} status
- */
- function setByStatus(props) {
- debugger;
- buttonVisibilityControl(props);
- let status = props.getUrlParam(STATUS.status);
- //设置单据编号
- props.BillHeadInfo.setBillHeadInfoVisible({
- showBackBtn: status === STATUS.browse,
- showBillCode: status === STATUS.browse,
- billCode: props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no).value
-
- });
- let vdef10=props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.vdef10).value;
- if(vdef10==2){
- props.form.setFormItemsValue(CARD.form_id, {
- 'vdef10': { value: '1', display: null },//设置变更状态
- });
- }
-
- debugger;
- if (status !== STATUS.add) {
- props.resMetaAfterPkorgEdit(); //选择主组织以后,恢复其他字段的编辑性
- }
- // orgVersionView(props);//组织版本视图
- }
- /**
- * 组织多版本视图
- * @param {*} props
- * @param {*} headCode
- */
- function orgVersionView(props) {
- let status = props.getUrlParam(STATUS.status);
- //浏览态显示组织版本,编辑态显示组织
- let showflag = status == STATUS.browse;
- let obj = {};
- obj[FIELD.org] = !showflag;
- props.form.setFormItemsVisible(CARD.form_id, obj);
- }
- //清空表头表体数据
- function clearAll(props) {
- props.form.EmptyAllFormValue(CARD.form_id);
- props.cardTable.setTableData(CARD.table_code, { rows: [] });
- }
- //复制时清空数据
- export function copyClear(props) {
- debugger;
- if (props.getUrlParam('isCopy')) {
- props.form.setFormItemsValue(CARD.form_id, {
- [PRIMARY_KEY.head_id]: { value: null, display: null },
- [PRIMARY_KEY.bill_no]: { value: null, display: null },
- [FIELD.billStatus]: { value: STATUS.NOSTATE, display: '自由' },
- [PRIMARY_KEY.vdef3]: { value: true, display: '是' },
- [PRIMARY_KEY.vdef4]: { value: null, display: null },
- [PRIMARY_KEY.vdef2]: { value: '1', display: null },
- [PRIMARY_KEY.vdef10]: { value: '0', display: null }
- });
- props.cardTable.setColValue(CARD.table_code, PRIMARY_KEY.head_id, { value: null, display: null });
- props.cardTable.setColValue(CARD.table_code, PRIMARY_KEY.body_id, { value: null, display: null });
- var num = props.cardTable.getNumberOfRows(CARD.table_code, false);
- var updateArray = new Array();
- for (var i = 0; i < num; i++) {
- updateArray.push({
- index: i,
- status: '2',//新增态
- });
- }
- props.cardTable.setRowStatusByIndexs(CARD.table_code, updateArray);
- props.setUrlParam({
- id: null,
- isCopy: false,
- status: STATUS.add
- });
- }
- }
- //卡片保存
- export function cardSave(props) {
- return new Promise((resolve, rejected) => {
- let flag = props.form.isCheckNow(CARD.form_id) && props.cardTable.checkTableRequired(CARD.table_code);
- if (flag) {
- let data = props.createMasterChildData(CARD.page_code, CARD.form_id, CARD.table_code, 'cardTable');
- props.validateToSave(data, () => {
- let status = props.getUrlParam(STATUS.status);
- ajax({
- url: REQUEST_URL.save,
- data: data,
- success: (res) => {
- let { success, data } = res;
- if (success) {
- toast({ color: STATUS.success, content: props.json['96H10119-000004'] });/* 国际化处理: 保存成功*/
- if (res.formulamsg && res.formulamsg instanceof Array && res.formulamsg.length > 0) {
- props.dealFormulamsg(res.formulamsg);
- }
- let id = null;
- if (res.data) {
- if (res.data.head && res.data.head[CARD.form_id]) {
- id = res.data.head[CARD.form_id].rows[0].values[PRIMARY_KEY.head_id].value;
- props.form.setAllFormValue({ [CARD.form_id]: res.data.head[CARD.form_id] });
- }
- if (res.data.body && res.data.body[CARD.table_code]) {
- props.cardTable.setTableData(CARD.table_code, res.data.body[CARD.table_code]);
- }
- }
- props.setUrlParam({
- id,
- status: STATUS.browse
- });
- // 缓存
- if (status === STATUS.add) {
- addCache(id, data, CARD.form_id, DATASOURCE);
- } else {
- updateCache(PRIMARY_KEY.head_id, id, data, CARD.form_id, DATASOURCE);
- }
- setByStatus(props);
- resolve(true);
- }
- }
- });
- }, { [CARD.table_code]: 'cardTable' });
- }
- });
- }
- //卡片修改
- export function cardUpdate(props) {
- debugger;
- props.setUrlParam({ status: STATUS.edit });
-
- setByStatus(props);
- }
- //变更 add by zth
- export function cardModify(props) {
- let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
- props.setUrlParam({ status: STATUS.edit });
- let vdef2 = props.form.getFormItemsValue(CARD.form_id, 'vdef2').value ;//历史版本
- debugger;
- if(!vdef2){
- debugger;
- vdef2=parseInt(2);
- }else{
- vdef2 = parseInt(vdef2)+1;
- }
- debugger;
- props.form.setFormItemsValue(CARD.form_id, {
- 'vdef3': { value: true, display: null },//设置最新版本为:是
- 'vdef4': { value: false, display: null },//设置是否注销为:否
- 'vdef2': { value: vdef2.toString(), display: null },//设置历史版本
- 'vdef10': { value: '3', display: null },//设置变更状态
- });
- setByStatus(props);
- // ajax({
- // url: REQUEST_URL.queryCard,
- // data: {
- // pk: id,
- // pagecode: CARD.page_code
- // },
- // });
- }
- //卡片修改
- export function cardCopy(props) {
- props.setUrlParam({ isCopy: true });
- copyClear(props);
- setByStatus(props);
- }
- //卡片删除
- export function cardDelete(props) {
- debugger;
- let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
- let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
- let pkMapTs = new Map();
- //主键与tsMap
- if (pk && ts) {
- pkMapTs.set(pk, ts);
- }
- let data = { pks: [pk], pkMapTs };
- ajax({
- url: REQUEST_URL.delete,
- data: data,
- success: (res) => {
- if (res.success) {
- toast({ color: STATUS.success, content: props.json['96H10119-000005'] });/* 国际化处理: 删除成功*/
- // 获取下一条数据的id
- let nextId = getNextId(pk, DATASOURCE);
- //删除缓存
- deleteCacheById(PRIMARY_KEY.head_id, pk, DATASOURCE);
- let lastId = nextId ? nextId : null;
- props.setUrlParam({ status: STATUS.browse, id: lastId });
- if (lastId) {
- getCardData(props, lastId);
- } else {// 删除的是最后一个的操作
- clearAll(props);
- setByStatus(props);
- }
- }
- }
- });
- }
- /**
- * 卡片详情
- * @param {*} id 单据id
- * @param {*} isRefresh 是否刷新按钮,是的话不取缓存数据,直接调取接口,并addCache, 默认否
- */
- export function getCardData(props, id, isRefresh = false, callBack) {
- debugger;
- clearAll(props);
- if (!isRefresh) {
- let cardData = getCacheById(id, DATASOURCE);
- if (cardData) {//有缓存
- cardData.head && props.form.setAllFormValue({ [CARD.form_id]: cardData.head[CARD.form_id] });
- cardData.body && props.cardTable.setTableData(CARD.table_code, cardData.body[CARD.table_code]);
- setByStatus(props);
- return;
- }
- }
- ajax({
- url: REQUEST_URL.queryCard,
- data: {
- pk: id,
- pagecode: CARD.page_code
- },
- success: (res) => {
- let { success, data } = res;
- if (success) {
- if (data && data.head) {
- props.form.setAllFormValue({ [CARD.form_id]: data.head[CARD.form_id] });
- }
- if (data && data.body) {
- props.cardTable.setTableData(CARD.table_code, data.body[CARD.table_code]);
- }
- // 更新缓存
- updateCache(PRIMARY_KEY.head_id, id, data, CARD.form_id, DATASOURCE);
- callBack && callBack(props);
- setByStatus(props);
- }
- },
- error: (res) => {
- toast({ color: STATUS.danger, content: res.message });
- clearAll(props);
- setByStatus(props);
- }
- });
- }
- //卡片取消
- export function cardCancel(props) {
- let id = props.getUrlParam(PRIMARY_KEY.id);
- props.setUrlParam({ status: STATUS.browse });
- if (id) { //有id切换编辑态
- props.form.cancel(CARD.form_id);
- props.cardTable.resetTableData(CARD.table_code);
- getCardData(props, id);
- } else { //没有id查缓存中最后一条数据
- let currentLastId = getCurrentLastId(DATASOURCE);
- let lastId = currentLastId ? currentLastId : null;
- props.setUrlParam({ id: lastId });
- if (lastId) {
- getCardData(props, lastId);
- } else {
- clearAll(props);
- setByStatus(props);
- }
- }
- }
- //卡片注销
- export function cardLogOut(props) {
- debugger;
- let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
- let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
- let pkMapTs = new Map();
- //主键与tsMap
- if (pk && ts) {
- pkMapTs.set(pk, ts);
- }
- let data = { pks: [pk], pkMapTs };
- ajax({
- url: REQUEST_URL.logout,
- data: data,
- success: (res) => {
- debugger;
- if (res.success) {
- toast({ color: STATUS.success, content: "注销成功" });/* 国际化处理: 注销成功*/
- //删除缓存
- deleteCacheById(PRIMARY_KEY.head_id, pk, DATASOURCE);
- clearAll(props);
- setByStatus(props);
- cardRefresh(props);
- }
- }
- });
- }
- //卡片刷新
- export function cardRefresh(props) {
- let id = props.getUrlParam(PRIMARY_KEY.id);
- getCardData(props, id, true);
- }
- /**
- * 卡片分页
- * @param {*} props 页面内置对象
- * @param {*} pk 下一页的pk
- */
- export function pageClick(props, id) {
- props.setUrlParam({ status: STATUS.browse, id });
- getCardData(props, id);
- }
- //卡片附件
- export function cardAttachment(props) {
- let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
- let billNo = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no).value;
- this.setState({
- showUploader: !this.state.showUploader,
- billInfo: { billId, billNo }
- });
- }
- //卡片单据追溯
- export function cardBillTrack(props) {
- let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
- this.setState({
- showBillTrack: true,
- billTrackBillId: billId,
- billTrackBillType: BILL_TYPE_CODE
- });
- }
- //卡片联查审批详情
- export function cardLinkApprove(props) {
- let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
- this.setState({
- showApproveDetail: true,
- billId: billId
- });
- }
- //卡片提交
- export function cardCommit(props, data) {
- if (!data) {
- let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
- let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
- let pkMapTs = new Map();
- //主键与tsMap
- if (pk && ts) {
- pkMapTs.set(pk, ts);
- }
- data = { pks: [pk], pkMapTs };
- }
- ajax({
- url: REQUEST_URL.commit,
- data: data,
- success: (res) => {
- if (res.success) { //成功
- if (res.data && res.data.workflow && (res.data.workflow == 'approveflow' || res.data.workflow == 'workflow')) {
- this.setState({
- compositeData: res.data,
- compositeDisplay: true,
- curPk: data.pks
- });
- } else {
- cardRefresh(props);
- }
- } else { //失败
- toast({ color: STATUS.warning, content: props.json['96H10119-000015'] });/* 国际化处理: 提交失败*/
- }
- }
- });
- }
- //卡片收回
- export function cardUnCommit(props) {
- let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
- let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
- let pkMapTs = new Map();
- //主键与tsMap
- if (pk && ts) {
- pkMapTs.set(pk, ts);
- }
- let data = { pks: [pk], pkMapTs };
- ajax({
- url: REQUEST_URL.unCommit,
- data: data,
- success: (res) => {
- if (res.success) { //成功
- cardRefresh(props);
- } else { //失败
- toast({ color: STATUS.warning, content: props.json['96H10119-000017'] });/* 国际化处理: 收回失败*/
- }
- }
- });
- }
|