form.request.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /**
  2. * Created by RaoMeng on 2020/12/11
  3. * Desc: 通用表单数据处理
  4. */
  5. import { isObjEmpty, isObjNull } from './common.util'
  6. import BillGroupModel from '../../model/common/BillGroupModel'
  7. import BillModel, {
  8. billGetDisplay,
  9. billGetValue, billIsEnclosure,
  10. } from '../../model/common/BillModel'
  11. import { message } from 'antd'
  12. import store from '../../redux/store/store'
  13. import { _baseURL } from '../../configs/api.config'
  14. export function analysisFormData (formData, isDetail) {
  15. let billGroupList = []
  16. if (!isObjEmpty(formData)) {
  17. const formList = formData.formList
  18. const gridList = formData.gridList
  19. /**
  20. * 主表数据
  21. */
  22. if (!isObjEmpty(formList)) {
  23. formList.forEach((formGroup, formIndex) => {
  24. const billGroup = getBillGroup(formGroup, billGroupList.length,
  25. isDetail)
  26. billGroup.isForm = true
  27. billGroupList.push(billGroup)
  28. })
  29. }
  30. /**
  31. * 从表数据
  32. */
  33. if (!isObjEmpty(gridList)) {
  34. gridList.forEach((gridGroup, gridIndex) => {
  35. //单个从表的明细列表
  36. const gridDetailList = gridGroup.fieldList
  37. if (!isObjEmpty(gridDetailList)) {
  38. gridDetailList.forEach((gridDetail, gridDetailIndex) => {
  39. const billGroup = getBillGroup({
  40. ...gridGroup,
  41. fieldList: gridDetail,
  42. }, billGroupList.length, isDetail)
  43. if (!isDetail && gridDetailIndex === (gridDetailList.length - 1)) {
  44. billGroup.lastInType = true
  45. } else {
  46. billGroup.lastInType = false
  47. }
  48. billGroup.isForm = false
  49. billGroupList.push(billGroup)
  50. })
  51. }
  52. })
  53. }
  54. }
  55. return billGroupList
  56. }
  57. export function getBillGroup (groupItem, groupIndex, isDetail) {
  58. let billGroup = new BillGroupModel()
  59. billGroup.group = groupItem.groupTitle
  60. billGroup.isForm = (groupItem.isForm === undefined) ? true:groupItem.isForm;
  61. billGroup.keyField = groupItem.keyField
  62. billGroup.billCaller = groupItem.groupCaller
  63. billGroup.groupIndex = groupIndex
  64. let showBillFields = [], hideBillFields = []
  65. if (!isObjEmpty(groupItem.fieldList)) {
  66. groupItem.fieldList.forEach((fieldItem, filedIndex) => {
  67. let billModel = new BillModel()
  68. billModel.groupIndex = groupIndex
  69. // billModel.childIndex = filedIndex
  70. billModel.appwidth = fieldItem.appwidth
  71. billModel.length = fieldItem.length
  72. billModel.isdefault = fieldItem.isdefault
  73. billModel.readOnly = (fieldItem.readOnly || isDetail)
  74. billModel.field = fieldItem.field
  75. billModel.logicType = fieldItem.logicType
  76. billModel.findFunctionName = fieldItem.findfunctionname
  77. billModel.allowBlank = (fieldItem.allowBlank || isDetail)
  78. billModel.allowBlankReal = fieldItem.allowBlank
  79. billModel.caption = fieldItem.caption
  80. billModel.type = fieldItem.type//前端类型
  81. billModel.sourceType = fieldItem.sourceType//字段原类型
  82. if (billModel.type === 'MF' && isDetail) {
  83. //移动端不支持从表的放大镜多选类型
  84. //将多选类型识别为放大镜单选类型
  85. billModel.type = 'DF'
  86. }
  87. // CBG 视同多选放大镜
  88. if (billModel.type === 'CBG') {
  89. if(isDetail){
  90. billModel.type = 'DF'
  91. }else {
  92. billModel.type = 'MF'
  93. }
  94. }
  95. billModel.value = fieldItem.value
  96. billModel.display = fieldItem.display
  97. billModel.defValue = fieldItem.defValue
  98. billModel.localDatas = fieldItem.localDatas
  99. if (isObjEmpty(billModel.value) &&
  100. !isObjEmpty(billModel.defValue, billModel.localDatas)) {
  101. billModel.localDatas.forEach(item => {
  102. if (item.display === billModel.defValue) {
  103. billModel.value = item.value
  104. billModel.display = item.display
  105. }
  106. })
  107. }
  108. //CBG 数据处理
  109. if (!isObjEmpty(billModel.value) && billModel.value.indexOf(";")>=0
  110. &&billModel.sourceType === 'CBG'&&billModel.logicType
  111. ){
  112. var logicTypeList = billModel.logicType.split(";");
  113. var cbgVList= billModel.value.split(";");
  114. var cbgRealV = "";
  115. cbgVList.localDatas.forEach((cbgv,index) => {
  116. if (String(cbgv) === '1') {
  117. cbgRealV = cbgRealV+"#"+logicTypeList[index];
  118. }
  119. })
  120. if(cbgRealV){
  121. cbgRealV = cbgRealV.substring(1);
  122. }
  123. billModel.value = cbgRealV;
  124. }
  125. //添加附件
  126. let filePaths = fieldItem.filePaths
  127. if (billIsEnclosure(billModel)) {
  128. let fileList = []
  129. if (!isObjEmpty(filePaths)) {
  130. filePaths.forEach((item, index) => {
  131. let fileObj = {}
  132. fileObj.uid = 'rc-upload-' + new Date().getTime() + '-' + index
  133. fileObj.enclosureId = item.fp_id
  134. fileObj.url = item.pathurl || (_baseURL +
  135. '/common/downloadbyId.action?id=' +
  136. fileObj.enclosureId
  137. + '&master=' + store.getState().userState.accountCode)
  138. fileObj.name = item.fp_name
  139. fileObj.size = item.fp_size
  140. fileObj.status = 'done'
  141. fileList.push(fileObj)
  142. })
  143. }
  144. billModel.fileList = fileList
  145. }
  146. //是否是显示字段,添加到show或hide列表
  147. if (billModel.isdefault) {
  148. showBillFields.push(billModel)
  149. } else {
  150. hideBillFields.push(billModel)
  151. }
  152. })
  153. }
  154. billGroup.showBillFields = showBillFields
  155. billGroup.hideBillFields = hideBillFields
  156. return billGroup
  157. }
  158. /**
  159. * 解析拼接单据数据
  160. * @param billGroupModelList
  161. * @returns {{form: *, grid: (null|[])}}
  162. */
  163. export function getFormAndGrid (billGroupModelList) {
  164. if (!isObjEmpty(billGroupModelList)) {
  165. const fields = analysisFields(billGroupModelList)
  166. let formStore = analysisForm(fields.formFields)
  167. if (isObjNull(formStore)) {
  168. return
  169. }
  170. let gridStoreList = analysisGrid(fields.gridGroupFields)
  171. if (isObjNull(gridStoreList)) {
  172. return
  173. }
  174. return {
  175. form: formStore,
  176. grid: gridStoreList,
  177. formFields: fields.formFields,
  178. gridFields: fields.gridGroupFields,
  179. }
  180. }
  181. }
  182. /**
  183. * 返回主表与从表字段配置列表
  184. * @param billGroupModelList
  185. * @returns {{formFields: [], gridGroupFields: []}}
  186. */
  187. function analysisFields (billGroupModelList) {
  188. let formFields = [], gridGroupFields = []
  189. for (let i = 0; i < billGroupModelList.length; i++) {
  190. let billGroup = billGroupModelList[i]
  191. if (isObjNull(billGroup)) {
  192. continue
  193. }
  194. if (billGroup.isForm) {
  195. if (!isObjEmpty(billGroup.showBillFields)) {
  196. formFields = formFields.concat(billGroup.showBillFields)
  197. }
  198. if (!isObjEmpty(billGroup.hideBillFields)) {
  199. formFields = formFields.concat(billGroup.hideBillFields)
  200. }
  201. } else {
  202. let gridFields = []
  203. if (!isObjEmpty(billGroup.showBillFields)) {
  204. gridFields = gridFields.concat(billGroup.showBillFields)
  205. }
  206. if (!isObjEmpty(billGroup.hideBillFields)) {
  207. gridFields = gridFields.concat(billGroup.hideBillFields)
  208. }
  209. gridGroupFields.push(gridFields)
  210. }
  211. }
  212. return {
  213. formFields,
  214. gridGroupFields,
  215. }
  216. }
  217. /**
  218. * 判断主表字段必填情况,拼接主表字段
  219. * @param formFields
  220. * @returns {null}
  221. */
  222. function analysisForm (formFields) {
  223. if (!isObjNull(formFields)) {
  224. let formStore = {}
  225. for (let i = 0; i < formFields.length; i++) {
  226. let billModel = formFields[i]
  227. if (isObjNull(billModel)) {
  228. continue
  229. }
  230. if (isObjEmpty(billGetValue(billModel)) && !billModel.allowBlank) {
  231. message.error(`${billModel.caption}为必填项`)
  232. return null
  233. }
  234. //Todo 附件上传
  235. formStore[billModel.field] = billGetDisplay(billModel)
  236. }
  237. return formStore
  238. } else {
  239. return null
  240. }
  241. }
  242. function analysisGrid (gridBillMap) {
  243. let gridStoreList = []
  244. if (!isObjNull(gridBillMap)) {
  245. for (let i = 0; i < gridBillMap.length; i++) {
  246. let gridFields = gridBillMap[i]
  247. if (!isObjEmpty(gridFields)) {
  248. let gridStore = {}
  249. for (let j = 0; j < gridFields.length; j++) {
  250. let billModel = gridFields[j]
  251. if (isObjEmpty(billGetValue(billModel)) && !billModel.allowBlank) {
  252. message.error(`${billModel.caption}为必填项`)
  253. return null
  254. }
  255. //Todo 附件上传
  256. gridStore[billModel.field] = billGetDisplay(billModel)
  257. }
  258. gridStoreList.push(gridStore)
  259. }
  260. }
  261. }
  262. return gridStoreList
  263. }