index.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. import React, { Component } from 'react';
  2. import { ajax,createPage, base, high , toast, cardCache} from 'nc-lightapp-front';
  3. import { initTemplate} from './events/initTemplate';
  4. import { buttonClick } from './events/buttonClick';
  5. import { beforeHeadEvent } from './events/beforeHeadEvent';
  6. import { beforeTableEvent } from './events/beforeTableEvent';
  7. import { afterHeadEvent } from './events/afterHeadEvent';
  8. import { afterTableEvent } from './events/afterTableEvent';
  9. import { bodySelectedEvent, bodySelectedAllEvent } from './events/bodySelectedEvent';
  10. import { REQUEST_URL,MULTILANG, CARD, PRIMARY_KEY, CARD_BUTTON, DATASOURCE, STATUS, BILL_TYPE_CODE } from '../constant';
  11. import { pageClick, cardCommit} from './events/cardOperator';
  12. import { bodyButtonClick } from './events/bodyButtonClick';
  13. let { updateCache } = cardCache;
  14. /**
  15. * @description: 卡片
  16. */
  17. const { NCAffix } = base;
  18. class Card extends Component {
  19. constructor(props) {
  20. super(props);
  21. this.state = {
  22. json: {},
  23. showUploader: false,
  24. billInfo: {},
  25. compositeData: null, //指派信息
  26. compositeDisplay: false, //是否显示指派
  27. curPk: null, //当前选中数据的pk
  28. showApproveDetail: false, //是否显示审批详情
  29. billId: null
  30. };
  31. this.pageId =
  32. this.props.getUrlParam("scene") == "linksce"
  33. ? "96H10119_CARD"
  34. : this.props.getUrlParam("scene") == "approvesce"
  35. ? "96H10119A_CARD"
  36. : CARD.page_code; //card页面code
  37. this.versionList = []; //保存历史版本号,供查看历史版本使用
  38. }
  39. componentWillMount() {
  40. // json: 多语json格式参数;
  41. // status: 是否请求到json多语,可用来判断多语资源是否请求到并进行一些别的操作;
  42. // inlt: 可用来进行占位符的一些操作
  43. let callback = (json, status, inlt) => {
  44. if (status) {
  45. initTemplate.call(this, this.props); // 如模板内也有多语处理,平台推荐模板加载操作放于此处, 在取到json多语资源后用传参的方式传入intemplate模板函数中
  46. // 保存json和inlt到页面state中并刷新页面
  47. this.setState({ json, inlt })
  48. }
  49. }
  50. this.props.MultiInit.getMultiLang({ moduleId: MULTILANG.moduleId, domainName: MULTILANG.domainName, callback });
  51. // 关闭浏览器
  52. window.onbeforeunload = () => {
  53. let status = this.props.cardTable.getStatus(CARD.table_code);
  54. if (status == STATUS.edit) {
  55. return this.state.json['96H10119-000007'];/* 国际化处理: 当前单据未保存,您确认离开此页面?*/
  56. }
  57. };
  58. }
  59. handlePageInfoChange = (props, id) => {
  60. debugger;
  61. pageClick({ ...props, json: this.state.json }, id);
  62. }
  63. //指派提交
  64. getAssignUser = (value) => {
  65. cardCommit({ ...this.props, json: this.state.json }, {
  66. pks: this.state.curPk,
  67. userObj: value
  68. });
  69. this.compositeTurnOff();
  70. };
  71. //关闭指派
  72. compositeTurnOff = () => {
  73. this.setState({
  74. compositeData: null,
  75. compositeDisplay: false
  76. });
  77. };
  78. componentDidMount(){
  79. let id = this.props.getUrlParam("id");
  80. let status = this.props.getUrlParam("status");
  81. this.props.button.setButtonDisabled(["deleteRow", "copyRow"], true);
  82. if (id) {
  83. if (status === "version") {
  84. //查看版本
  85. this.initVersionTree();
  86. }
  87. }
  88. }
  89. //同步树节点点击事件
  90. onTreeSelect = pk => {
  91. debugger;
  92. if (pk === "-1") {
  93. return;
  94. }
  95. ajax({
  96. url:'/nccloud/zjcmp_cd/cd/guatamxqueryversioncardaction.do',
  97. data: {
  98. pk: pk,
  99. pagecode: CARD.page_code
  100. },
  101. success: (res) => {
  102. debugger;
  103. let { success, data } = res;
  104. if (success) {
  105. if (data && data.body) {
  106. this.props.cardTable.setTableData(CARD.table_code, data.body[CARD.table_code]);
  107. }
  108. if (data && data.head) {
  109. this.props.form.setAllFormValue({ [CARD.form_id]: data.head[CARD.form_id] });
  110. // this.props.form.setFormItemsDisabled(CARD.form_id, { 'pk_org': true});
  111. }
  112. }
  113. },
  114. error: (res) => {
  115. toast({ color: STATUS.danger, content: res.message });
  116. }
  117. });
  118. };
  119. //获取列表肩部信息
  120. getTableHead = () => (
  121. <div className="shoulder-definition-area">
  122. <div className="definition-icons">
  123. {this.props.button.createButtonApp({
  124. area: CARD.shoulder_btn_code,
  125. onButtonClick: bodyButtonClick.bind(this),
  126. popContainer: document.querySelector('.header-button-area')
  127. })}
  128. </div>
  129. </div>
  130. );
  131. //同步树鼠标滑过事件
  132. onTreeMouseEnter = key => {
  133. this.props.syncTree.hideIcon(this.treeId, key, {
  134. delIcon: false,
  135. editIcon: false,
  136. addIcon: false
  137. });
  138. };
  139. /**
  140. * 加载查看版本页面
  141. * @param {*} callback - 回调函数
  142. */
  143. initVersionTree = callback => {
  144. debugger;
  145. const treeRoot = {
  146. isleaf: false,
  147. pid: "__root__",
  148. refname: this.state.json["36620GC-000001"] /* 国际化处理: 版本号*/,
  149. refpk: "-1"
  150. };
  151. ajax({
  152. url:'/nccloud/zjcmp_cd/cd/guatamxqueryversionlistaction.do',
  153. data: {
  154. queryAreaCode: "search",
  155. querytype: "tree",
  156. querycondition: {},
  157. pageCode: this.pageId,
  158. pageInfo: { pageIndex: 0, pageSize: 100 },
  159. def1: this.props.getUrlParam("id") //主键
  160. },
  161. success: res => {
  162. debugger;
  163. let { success, data } = res;
  164. let versionList = data && data.data && data.data.rows;
  165. this.versionList = versionList.map(item => item.refpk);
  166. if (success) {
  167. let treeData = this.props.syncTree.createTreeData(versionList);
  168. if (versionList.length) {
  169. this.onTreeSelect(versionList[0].refpk);
  170. }
  171. this.props.syncTree.setSyncTreeData(this.treeId, [
  172. Object.assign(treeRoot, { children: treeData })
  173. ]);
  174. }
  175. }
  176. });
  177. };
  178. render() {
  179. let { form, cardPagination, BillHeadInfo, cardTable,syncTree,DragWidthCom } = this.props;
  180. let { createCardPagination } = cardPagination;
  181. let { createForm } = form;
  182. let { createCardTable } = cardTable;
  183. let { createBillHeadInfo } = BillHeadInfo;
  184. let { NCUploader, BillTrack, ApprovalTrans, ApproveDetail } = high;
  185. let status = this.props.getUrlParam(STATUS.status);
  186. let id = this.props.getUrlParam(PRIMARY_KEY.id);
  187. let billNo = this.props.form.getFormItemsValue(CARD.page_code, PRIMARY_KEY.bill_no);
  188. let { createSyncTree } = syncTree;
  189. // 卡片 主表dom
  190. let cardFormDom = (
  191. <div className="nc-bill-top-area">
  192. <div className="nc-bill-form-area">
  193. {createForm(CARD.headcode, {
  194. onAfterEvent: afterHeadEvent.bind(this),
  195. onBeforeEvent: beforeHeadEvent.bind(this)
  196. })}
  197. </div>
  198. </div>
  199. );
  200. // 卡片子表dom
  201. let cardFormTableDom = (
  202. <div className="nc-bill-bottom-area">
  203. <div className="nc-bill-table-area">
  204. {createCardTable(CARD.table_code, {
  205. cancelCustomRightMenu: true,
  206. tableHead: this.getTableHead.bind(this),
  207. onTabChange: key => {
  208. console.log(key);
  209. },
  210. adaptionHeight: true,
  211. modelSave: buttonClick.bind(this, this.props, "Save"),
  212. }
  213. )}
  214. </div>
  215. </div>
  216. );
  217. // 左树 dom
  218. let treeDom = (
  219. <div className="left-area" style={{ marginLeft: "20px" }}>
  220. {createSyncTree({
  221. treeId: this.treeId, // 组件id
  222. needSearch: false, //是否需要查询框,默认为true,显示。false: 不显示
  223. onSelectEve: this.onTreeSelect.bind(this), //选择节点回调方法
  224. onMouseEnterEve: this.onTreeMouseEnter.bind(this), //鼠标滑过节点事件
  225. defaultExpandAll: true, //默认展开所有节点
  226. disabledSearch: true //是否显示搜索框
  227. })}
  228. </div>
  229. );
  230. // 右卡 dom
  231. let rightDom = (
  232. <div className="nc-bill-card">
  233. {cardFormDom}
  234. {cardFormTableDom}
  235. </div>
  236. );
  237. return (
  238. <div className="nc-bill-card">
  239. <div className="nc-bill-top-area">
  240. <NCAffix>
  241. <div className="nc-bill-header-area">
  242. <div>
  243. {createBillHeadInfo({
  244. title: this.state.json[CARD.page_title],//标题
  245. billCode: billNo && billNo.value,//单据号
  246. backBtnClick: buttonClick.bind(this, this.props, CARD_BUTTON.back)
  247. })}
  248. </div>
  249. {status !== "version" && (
  250. <div className="header-button-area">
  251. {this.props.button.createButtonApp({
  252. area: CARD.head_btn_code,
  253. onButtonClick: buttonClick.bind(this)
  254. })}
  255. </div>
  256. )}
  257. {status == STATUS.browse && id &&
  258. <div className="header-cardPagination-area" style={{ float: 'right' }}>
  259. {createCardPagination({
  260. dataSource: DATASOURCE,
  261. pkname: PRIMARY_KEY.head_id,
  262. handlePageInfoChange: this.handlePageInfoChange
  263. })}
  264. </div>
  265. }
  266. </div>
  267. {/* 为多版本联查时加载 树卡区域 */}
  268. {status === "version" && (
  269. <div className="tree-card">
  270. <DragWidthCom
  271. leftDom={treeDom} //左侧区域dom
  272. rightDom={rightDom} //右侧区域dom
  273. defLeftWid="20%" // 默认左侧区域宽度,px/百分百
  274. />
  275. </div>
  276. )}
  277. </NCAffix>
  278. {status !== "version" && (
  279. <div className="nc-bill-form-area">
  280. {createForm(CARD.form_id, {
  281. onAfterEvent: afterHeadEvent,
  282. onBeforeEvent: beforeHeadEvent
  283. })}
  284. </div>
  285. ) }
  286. </div>
  287. {/* 为正常状态时 加载主子表 */}
  288. {status !== "version" && (
  289. <div className="nc-bill-bottom-area">
  290. <div className="nc-bill-table-area">
  291. {createCardTable(CARD.table_code, {
  292. tableHead: this.getTableHead.bind(this),
  293. showCheck: true,
  294. showIndex: true,
  295. onSelected: bodySelectedEvent,
  296. onSelectedAll: bodySelectedAllEvent,
  297. onBeforeEvent: beforeTableEvent,
  298. onAfterEvent: afterTableEvent,
  299. modelSave: buttonClick.bind(this, { ...this.props, json: this.state.json }, CARD_BUTTON.save, undefined, true),
  300. })}
  301. </div>
  302. </div>
  303. ) }
  304. {/* 附件 */}
  305. {this.state.showUploader && (
  306. <NCUploader
  307. placement={'bottom'}
  308. {...this.state.billInfo}
  309. onHide={() => {
  310. this.setState({
  311. showUploader: false
  312. });
  313. }}
  314. />
  315. )}
  316. {/*联查单据追溯*/}
  317. {
  318. <BillTrack
  319. show={this.state.showBillTrack}
  320. close={() => {
  321. this.setState({ showBillTrack: false });
  322. }}
  323. pk={this.state.billTrackBillId}
  324. type={this.state.billTrackBillType}
  325. />
  326. }
  327. {/* 指派 */}
  328. {this.state.compositeDisplay && (
  329. <ApprovalTrans
  330. title={this.state.json['96H10119-000018']} /* 国际化处理: 指派*/
  331. data={this.state.compositeData}
  332. display={this.state.compositeDisplay}
  333. getResult={this.getAssignUser}
  334. cancel={this.compositeTurnOff}
  335. />
  336. )}
  337. {/* 联查审批详情 */}
  338. {
  339. <ApproveDetail
  340. show={this.state.showApproveDetail}
  341. billtype={BILL_TYPE_CODE}
  342. billid={this.state.billId}
  343. close={() => {
  344. this.setState({
  345. showApproveDetail: false
  346. });
  347. }}
  348. />
  349. }
  350. </div>
  351. );
  352. }
  353. }
  354. Card = createPage({
  355. billinfo: {
  356. billtype: 'card',
  357. pagecode: CARD.page_code,
  358. headcode: CARD.form_id,
  359. bodycode: CARD.table_code
  360. }
  361. })(Card);
  362. export default Card;