commonSubmitHelper.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {
  2. audit,
  3. save,
  4. submit
  5. } from '../api/production_replenishment.js';
  6. import modal from '../plugins/modal.js';
  7. import {
  8. audioUrls,
  9. playVoice
  10. } from './audio2.js';
  11. import {
  12. getSaveParam,
  13. getSubmitParam,
  14. getAuditParam,
  15. get2SaveParam
  16. } from './newparams.js';
  17. import {
  18. getCreateSaveParam,
  19. getCreateSubmitParam,
  20. } from './transferparams.js'
  21. export default {
  22. async submit(FormId,FID, indexList,fbillType) {
  23. try {
  24. modal.loading("提交中,请耐心等待...");
  25. let saveParam;
  26. if(fbillType == "B"){
  27. saveParam = get2SaveParam(FormId,FID, indexList);
  28. }else{
  29. saveParam = getSaveParam(FormId,FID, indexList);
  30. }
  31. console.log(saveParam)
  32. const saveRes = await this.saveData(saveParam);
  33. if (!saveRes.IsSuccess) {
  34. throw new Error(saveRes.Errors[0].Message);
  35. }
  36. const submitParam = getSubmitParam(FormId,FID);
  37. const submitRes = await this.submitData(submitParam);
  38. if (!submitRes.IsSuccess) {
  39. throw new Error(submitRes.Errors[0].Message);
  40. }
  41. const auditParam = getAuditParam(FormId,submitRes.SuccessEntitys[0].Id);
  42. const auditRes = await this.auditData(auditParam);
  43. if (!auditRes.IsSuccess) {
  44. throw new Error(auditRes.Errors[0].Message);
  45. }
  46. this.handleSuccess(FID, indexList);
  47. } catch (error) {
  48. // this.handleError(error);
  49. throw new Error(error);
  50. } finally {
  51. modal.closeLoading();
  52. }
  53. },
  54. async createSubmit(FormId,indexList) {
  55. try {
  56. modal.loadingMask("提交中,请耐心等待...");
  57. let saveParam;
  58. const username = uni.getStorageSync('HBusername')
  59. saveParam = getCreateSaveParam(FormId,username,indexList)
  60. console.log(saveParam)
  61. const saveRes = await this.saveData(saveParam);
  62. if (!saveRes.IsSuccess) {
  63. throw new Error(saveRes.Errors[0].Message);
  64. }
  65. const submitParam = getCreateSubmitParam(FormId,saveRes.SuccessEntitys[0].Id);
  66. const submitRes = await this.submitData(submitParam);
  67. if (!submitRes.IsSuccess) {
  68. throw new Error(submitRes.Errors[0].Message);
  69. }
  70. const auditParam = getAuditParam(FormId,submitRes.SuccessEntitys[0].Id);
  71. const auditRes = await this.auditData(auditParam);
  72. if (!auditRes.IsSuccess) {
  73. throw new Error(auditRes.Errors[0].Message);
  74. }
  75. const FNumber = auditRes.SuccessEntitys[0].Number;
  76. this.handleSuccess(FNumber, indexList);
  77. } catch (error) {
  78. // this.handleError(error);
  79. throw new Error(error);
  80. } finally {
  81. modal.closeLoading();
  82. }
  83. },
  84. saveData(params) {
  85. return save(JSON.stringify(params))
  86. .then(res => res.Result.ResponseStatus);
  87. },
  88. submitData(params) {
  89. return submit(JSON.stringify(params))
  90. .then(res => res.Result.ResponseStatus);
  91. },
  92. auditData(params) {
  93. return audit(JSON.stringify(params))
  94. .then(res => res.Result.ResponseStatus);
  95. },
  96. handleSuccess(FID, indexList) {
  97. // Assuming that you pass indexList back to where it's needed
  98. uni.showModal({
  99. title: "提示",
  100. content: "提交成功",
  101. showCancel: true,
  102. success: (res) => {
  103. if (res.confirm) {
  104. // 用户点击确定
  105. } else {
  106. // 用户点击取消
  107. }
  108. }
  109. });
  110. playVoice(audioUrls.warningSuccessUrl);
  111. },
  112. handleError(error) {
  113. uni.showToast({
  114. title: error.message || '操作失败',
  115. duration: 3000,
  116. icon: "error"
  117. });
  118. playVoice(audioUrls.successVoiceUrl)
  119. console.error('操作失败:', error);
  120. }
  121. };