commonSubmitHelper.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.loading("提交中,请耐心等待...");
  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. this.handleSuccess(FID, indexList);
  76. } catch (error) {
  77. // this.handleError(error);
  78. throw new Error(error);
  79. } finally {
  80. modal.closeLoading();
  81. }
  82. },
  83. saveData(params) {
  84. return save(JSON.stringify(params))
  85. .then(res => res.Result.ResponseStatus);
  86. },
  87. submitData(params) {
  88. return submit(JSON.stringify(params))
  89. .then(res => res.Result.ResponseStatus);
  90. },
  91. auditData(params) {
  92. return audit(JSON.stringify(params))
  93. .then(res => res.Result.ResponseStatus);
  94. },
  95. handleSuccess(FID, indexList) {
  96. // Assuming that you pass indexList back to where it's needed
  97. uni.showModal({
  98. title: "提示",
  99. content: "提交成功",
  100. showCancel: true,
  101. success: (res) => {
  102. if (res.confirm) {
  103. // 用户点击确定
  104. } else {
  105. // 用户点击取消
  106. }
  107. }
  108. });
  109. playVoice(audioUrls.warningSuccessUrl);
  110. },
  111. handleError(error) {
  112. uni.showToast({
  113. title: error.message || '操作失败',
  114. duration: 3000,
  115. icon: "error"
  116. });
  117. playVoice(audioUrls.successVoiceUrl)
  118. console.error('操作失败:', error);
  119. }
  120. };