cardOperator.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. import { ajax, cardCache, toast } from 'nc-lightapp-front';
  2. import { REQUEST_URL, CARD, PRIMARY_KEY, CARD_BUTTON, CARD_CACHE, DATASOURCE, STATUS, FIELD, BILL_TYPE_CODE, CARD_ADD_DISABLED_BUTTON } from '../../constant';
  3. import { buttonVisibilityControl } from './buttonVisibilityControl';
  4. import { afterHeadEvent } from './afterHeadEvent';
  5. let { updateCache, addCache, getNextId, deleteCacheById, getCacheById, getCurrentLastId } = cardCache;
  6. //卡片返回
  7. export function cardBack(props) {
  8. props.pushTo(REQUEST_URL.toList, {});
  9. }
  10. //卡片新增
  11. export function cardCreate(props) {
  12. props.setUrlParam({ status: STATUS.add });
  13. //单据有主组织,新增时,将其他字段设置为不可编辑
  14. props.initMetaByPkorg();
  15. props.button.setButtonDisabled(CARD_ADD_DISABLED_BUTTON, true);
  16. props.cardTable.setAllCheckboxAble(CARD.table_code, false);
  17. clearAll(props);
  18. setByStatus(props);
  19. let { getDefData } = cardCache;
  20. let context = getDefData(CARD_CACHE.key, CARD_CACHE.dataSource);
  21. if (context) {
  22. let { pk_org, org_Name} = context;
  23. props.form.setFormItemsValue(CARD.form_id, {
  24. [FIELD.org]: { value: pk_org, display: org_Name }
  25. });
  26. afterHeadEvent(props, CARD.form_id, FIELD.org, { display: org_Name, value: pk_org }, { display: null, value: null });
  27. }
  28. }
  29. /**
  30. * 根据状态设置卡片
  31. * @param {*} status
  32. */
  33. function setByStatus(props) {
  34. debugger;
  35. buttonVisibilityControl(props);
  36. let status = props.getUrlParam(STATUS.status);
  37. //设置单据编号
  38. props.BillHeadInfo.setBillHeadInfoVisible({
  39. showBackBtn: status === STATUS.browse,
  40. showBillCode: status === STATUS.browse,
  41. billCode: props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no).value
  42. });
  43. let vdef10=props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.vdef10).value;
  44. if(vdef10==2){
  45. props.form.setFormItemsValue(CARD.form_id, {
  46. 'vdef10': { value: '1', display: null },//设置变更状态
  47. });
  48. }
  49. debugger;
  50. if (status !== STATUS.add) {
  51. props.resMetaAfterPkorgEdit(); //选择主组织以后,恢复其他字段的编辑性 
  52. }
  53. // orgVersionView(props);//组织版本视图
  54. }
  55. /**
  56. * 组织多版本视图
  57. * @param {*} props
  58. * @param {*} headCode
  59. */
  60. function orgVersionView(props) {
  61. let status = props.getUrlParam(STATUS.status);
  62. //浏览态显示组织版本,编辑态显示组织
  63. let showflag = status == STATUS.browse;
  64. let obj = {};
  65. obj[FIELD.org] = !showflag;
  66. props.form.setFormItemsVisible(CARD.form_id, obj);
  67. }
  68. //清空表头表体数据
  69. function clearAll(props) {
  70. props.form.EmptyAllFormValue(CARD.form_id);
  71. props.cardTable.setTableData(CARD.table_code, { rows: [] });
  72. }
  73. //复制时清空数据
  74. export function copyClear(props) {
  75. debugger;
  76. if (props.getUrlParam('isCopy')) {
  77. props.form.setFormItemsValue(CARD.form_id, {
  78. [PRIMARY_KEY.head_id]: { value: null, display: null },
  79. [PRIMARY_KEY.bill_no]: { value: null, display: null },
  80. [FIELD.billStatus]: { value: STATUS.NOSTATE, display: '自由' },
  81. [PRIMARY_KEY.vdef3]: { value: true, display: '是' },
  82. [PRIMARY_KEY.vdef4]: { value: null, display: null },
  83. [PRIMARY_KEY.vdef2]: { value: '1', display: null },
  84. [PRIMARY_KEY.vdef10]: { value: '0', display: null }
  85. });
  86. props.cardTable.setColValue(CARD.table_code, PRIMARY_KEY.head_id, { value: null, display: null });
  87. props.cardTable.setColValue(CARD.table_code, PRIMARY_KEY.body_id, { value: null, display: null });
  88. var num = props.cardTable.getNumberOfRows(CARD.table_code, false);
  89. var updateArray = new Array();
  90. for (var i = 0; i < num; i++) {
  91. updateArray.push({
  92. index: i,
  93. status: '2',//新增态
  94. });
  95. }
  96. props.cardTable.setRowStatusByIndexs(CARD.table_code, updateArray);
  97. props.setUrlParam({
  98. id: null,
  99. isCopy: false,
  100. status: STATUS.add
  101. });
  102. }
  103. }
  104. //卡片保存
  105. export function cardSave(props) {
  106. return new Promise((resolve, rejected) => {
  107. let flag = props.form.isCheckNow(CARD.form_id) && props.cardTable.checkTableRequired(CARD.table_code);
  108. if (flag) {
  109. let data = props.createMasterChildData(CARD.page_code, CARD.form_id, CARD.table_code, 'cardTable');
  110. props.validateToSave(data, () => {
  111. let status = props.getUrlParam(STATUS.status);
  112. ajax({
  113. url: REQUEST_URL.save,
  114. data: data,
  115. success: (res) => {
  116. let { success, data } = res;
  117. if (success) {
  118. toast({ color: STATUS.success, content: props.json['96H10119-000004'] });/* 国际化处理: 保存成功*/
  119. if (res.formulamsg && res.formulamsg instanceof Array && res.formulamsg.length > 0) {
  120. props.dealFormulamsg(res.formulamsg);
  121. }
  122. let id = null;
  123. if (res.data) {
  124. if (res.data.head && res.data.head[CARD.form_id]) {
  125. id = res.data.head[CARD.form_id].rows[0].values[PRIMARY_KEY.head_id].value;
  126. props.form.setAllFormValue({ [CARD.form_id]: res.data.head[CARD.form_id] });
  127. }
  128. if (res.data.body && res.data.body[CARD.table_code]) {
  129. props.cardTable.setTableData(CARD.table_code, res.data.body[CARD.table_code]);
  130. }
  131. }
  132. props.setUrlParam({
  133. id,
  134. status: STATUS.browse
  135. });
  136. // 缓存
  137. if (status === STATUS.add) {
  138. addCache(id, data, CARD.form_id, DATASOURCE);
  139. } else {
  140. updateCache(PRIMARY_KEY.head_id, id, data, CARD.form_id, DATASOURCE);
  141. }
  142. setByStatus(props);
  143. resolve(true);
  144. }
  145. }
  146. });
  147. }, { [CARD.table_code]: 'cardTable' });
  148. }
  149. });
  150. }
  151. //卡片修改
  152. export function cardUpdate(props) {
  153. debugger;
  154. props.setUrlParam({ status: STATUS.edit });
  155. setByStatus(props);
  156. }
  157. //变更 add by zth
  158. export function cardModify(props) {
  159. let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
  160. props.setUrlParam({ status: STATUS.edit });
  161. let vdef2 = props.form.getFormItemsValue(CARD.form_id, 'vdef2').value ;//历史版本
  162. debugger;
  163. if(!vdef2){
  164. debugger;
  165. vdef2=parseInt(2);
  166. }else{
  167. vdef2 = parseInt(vdef2)+1;
  168. }
  169. debugger;
  170. props.form.setFormItemsValue(CARD.form_id, {
  171. 'vdef3': { value: true, display: null },//设置最新版本为:是
  172. 'vdef4': { value: false, display: null },//设置是否注销为:否
  173. 'vdef2': { value: vdef2.toString(), display: null },//设置历史版本
  174. 'vdef10': { value: '3', display: null },//设置变更状态
  175. });
  176. setByStatus(props);
  177. // ajax({
  178. // url: REQUEST_URL.queryCard,
  179. // data: {
  180. // pk: id,
  181. // pagecode: CARD.page_code
  182. // },
  183. // });
  184. }
  185. //卡片修改
  186. export function cardCopy(props) {
  187. props.setUrlParam({ isCopy: true });
  188. copyClear(props);
  189. setByStatus(props);
  190. }
  191. //卡片删除
  192. export function cardDelete(props) {
  193. debugger;
  194. let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
  195. let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
  196. let pkMapTs = new Map();
  197. //主键与tsMap
  198. if (pk && ts) {
  199. pkMapTs.set(pk, ts);
  200. }
  201. let data = { pks: [pk], pkMapTs };
  202. ajax({
  203. url: REQUEST_URL.delete,
  204. data: data,
  205. success: (res) => {
  206. if (res.success) {
  207. toast({ color: STATUS.success, content: props.json['96H10119-000005'] });/* 国际化处理: 删除成功*/
  208. // 获取下一条数据的id
  209. let nextId = getNextId(pk, DATASOURCE);
  210. //删除缓存
  211. deleteCacheById(PRIMARY_KEY.head_id, pk, DATASOURCE);
  212. let lastId = nextId ? nextId : null;
  213. props.setUrlParam({ status: STATUS.browse, id: lastId });
  214. if (lastId) {
  215. getCardData(props, lastId);
  216. } else {// 删除的是最后一个的操作
  217. clearAll(props);
  218. setByStatus(props);
  219. }
  220. }
  221. }
  222. });
  223. }
  224. /**
  225. * 卡片详情
  226. * @param {*} id 单据id
  227. * @param {*} isRefresh 是否刷新按钮,是的话不取缓存数据,直接调取接口,并addCache, 默认否
  228. */
  229. export function getCardData(props, id, isRefresh = false, callBack) {
  230. debugger;
  231. clearAll(props);
  232. if (!isRefresh) {
  233. let cardData = getCacheById(id, DATASOURCE);
  234. if (cardData) {//有缓存
  235. cardData.head && props.form.setAllFormValue({ [CARD.form_id]: cardData.head[CARD.form_id] });
  236. cardData.body && props.cardTable.setTableData(CARD.table_code, cardData.body[CARD.table_code]);
  237. setByStatus(props);
  238. return;
  239. }
  240. }
  241. ajax({
  242. url: REQUEST_URL.queryCard,
  243. data: {
  244. pk: id,
  245. pagecode: CARD.page_code
  246. },
  247. success: (res) => {
  248. let { success, data } = res;
  249. if (success) {
  250. if (data && data.head) {
  251. props.form.setAllFormValue({ [CARD.form_id]: data.head[CARD.form_id] });
  252. }
  253. if (data && data.body) {
  254. props.cardTable.setTableData(CARD.table_code, data.body[CARD.table_code]);
  255. }
  256. // 更新缓存
  257. updateCache(PRIMARY_KEY.head_id, id, data, CARD.form_id, DATASOURCE);
  258. callBack && callBack(props);
  259. setByStatus(props);
  260. }
  261. },
  262. error: (res) => {
  263. toast({ color: STATUS.danger, content: res.message });
  264. clearAll(props);
  265. setByStatus(props);
  266. }
  267. });
  268. }
  269. //卡片取消
  270. export function cardCancel(props) {
  271. let id = props.getUrlParam(PRIMARY_KEY.id);
  272. props.setUrlParam({ status: STATUS.browse });
  273. if (id) { //有id切换编辑态
  274. props.form.cancel(CARD.form_id);
  275. props.cardTable.resetTableData(CARD.table_code);
  276. getCardData(props, id);
  277. } else { //没有id查缓存中最后一条数据
  278. let currentLastId = getCurrentLastId(DATASOURCE);
  279. let lastId = currentLastId ? currentLastId : null;
  280. props.setUrlParam({ id: lastId });
  281. if (lastId) {
  282. getCardData(props, lastId);
  283. } else {
  284. clearAll(props);
  285. setByStatus(props);
  286. }
  287. }
  288. }
  289. //卡片注销
  290. export function cardLogOut(props) {
  291. debugger;
  292. let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value || props.getUrlParam(PRIMARY_KEY.id);
  293. let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
  294. let pkMapTs = new Map();
  295. //主键与tsMap
  296. if (pk && ts) {
  297. pkMapTs.set(pk, ts);
  298. }
  299. let data = { pks: [pk], pkMapTs };
  300. ajax({
  301. url: REQUEST_URL.logout,
  302. data: data,
  303. success: (res) => {
  304. debugger;
  305. if (res.success) {
  306. toast({ color: STATUS.success, content: "注销成功" });/* 国际化处理: 注销成功*/
  307. //删除缓存
  308. deleteCacheById(PRIMARY_KEY.head_id, pk, DATASOURCE);
  309. clearAll(props);
  310. setByStatus(props);
  311. cardRefresh(props);
  312. }
  313. }
  314. });
  315. }
  316. //卡片刷新
  317. export function cardRefresh(props) {
  318. let id = props.getUrlParam(PRIMARY_KEY.id);
  319. getCardData(props, id, true);
  320. }
  321. /**
  322. * 卡片分页
  323. * @param {*} props 页面内置对象
  324. * @param {*} pk 下一页的pk
  325. */
  326. export function pageClick(props, id) {
  327. props.setUrlParam({ status: STATUS.browse, id });
  328. getCardData(props, id);
  329. }
  330. //卡片附件
  331. export function cardAttachment(props) {
  332. let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
  333. let billNo = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.bill_no).value;
  334. this.setState({
  335. showUploader: !this.state.showUploader,
  336. billInfo: { billId, billNo }
  337. });
  338. }
  339. //卡片单据追溯
  340. export function cardBillTrack(props) {
  341. let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
  342. this.setState({
  343. showBillTrack: true,
  344. billTrackBillId: billId,
  345. billTrackBillType: BILL_TYPE_CODE
  346. });
  347. }
  348. //卡片联查审批详情
  349. export function cardLinkApprove(props) {
  350. let billId = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
  351. this.setState({
  352. showApproveDetail: true,
  353. billId: billId
  354. });
  355. }
  356. //卡片提交
  357. export function cardCommit(props, data) {
  358. if (!data) {
  359. let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
  360. let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
  361. let pkMapTs = new Map();
  362. //主键与tsMap
  363. if (pk && ts) {
  364. pkMapTs.set(pk, ts);
  365. }
  366. data = { pks: [pk], pkMapTs };
  367. }
  368. ajax({
  369. url: REQUEST_URL.commit,
  370. data: data,
  371. success: (res) => {
  372. if (res.success) { //成功
  373. if (res.data && res.data.workflow && (res.data.workflow == 'approveflow' || res.data.workflow == 'workflow')) {
  374. this.setState({
  375. compositeData: res.data,
  376. compositeDisplay: true,
  377. curPk: data.pks
  378. });
  379. } else {
  380. cardRefresh(props);
  381. }
  382. } else { //失败
  383. toast({ color: STATUS.warning, content: props.json['96H10119-000015'] });/* 国际化处理: 提交失败*/
  384. }
  385. }
  386. });
  387. }
  388. //卡片收回
  389. export function cardUnCommit(props) {
  390. let pk = props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id) && props.form.getFormItemsValue(CARD.form_id, PRIMARY_KEY.head_id).value;
  391. let ts = props.form.getFormItemsValue(CARD.form_id, FIELD.ts) && props.form.getFormItemsValue(CARD.form_id, FIELD.ts).value;
  392. let pkMapTs = new Map();
  393. //主键与tsMap
  394. if (pk && ts) {
  395. pkMapTs.set(pk, ts);
  396. }
  397. let data = { pks: [pk], pkMapTs };
  398. ajax({
  399. url: REQUEST_URL.unCommit,
  400. data: data,
  401. success: (res) => {
  402. if (res.success) { //成功
  403. cardRefresh(props);
  404. } else { //失败
  405. toast({ color: STATUS.warning, content: props.json['96H10119-000017'] });/* 国际化处理: 收回失败*/
  406. }
  407. }
  408. });
  409. }