commonSubmitHelper.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 './audio.js';
  11. import {
  12. getSaveParam,
  13. getSubmitParam,
  14. getAuditParam
  15. } from './newparams.js';
  16. export default {
  17. async submit(FormId,FID, indexList) {
  18. try {
  19. modal.loading("提交中,请耐心等待...");
  20. const saveParam = getSaveParam(FormId,FID, indexList);
  21. console.log(saveParam)
  22. const saveRes = await this.saveData(saveParam);
  23. if (!saveRes.IsSuccess) {
  24. throw new Error(saveRes.Errors[0].Message);
  25. }
  26. const submitParam = getSubmitParam(FormId,FID);
  27. const submitRes = await this.submitData(submitParam);
  28. if (!submitRes.IsSuccess) {
  29. throw new Error(submitRes.Errors[0].Message);
  30. }
  31. const auditParam = getAuditParam(FormId,submitRes.SuccessEntitys[0].Id);
  32. const auditRes = await this.auditData(auditParam);
  33. if (!auditRes.IsSuccess) {
  34. throw new Error(auditRes.Errors[0].Message);
  35. }
  36. this.handleSuccess(FID, indexList);
  37. } catch (error) {
  38. // this.handleError(error);
  39. throw new Error(error);
  40. } finally {
  41. modal.closeLoading();
  42. }
  43. },
  44. saveData(params) {
  45. return save(JSON.stringify(params))
  46. .then(res => res.Result.ResponseStatus);
  47. },
  48. submitData(params) {
  49. return submit(JSON.stringify(params))
  50. .then(res => res.Result.ResponseStatus);
  51. },
  52. auditData(params) {
  53. return audit(JSON.stringify(params))
  54. .then(res => res.Result.ResponseStatus);
  55. },
  56. handleSuccess(FID, indexList) {
  57. // Assuming that you pass indexList back to where it's needed
  58. uni.showModal({
  59. title: "提示",
  60. content: "提交成功",
  61. showCancel: true,
  62. success: (res) => {
  63. if (res.confirm) {
  64. // 用户点击确定
  65. } else {
  66. // 用户点击取消
  67. }
  68. }
  69. });
  70. playVoice(audioUrls.successVoiceUrl);
  71. },
  72. handleError(error) {
  73. uni.showToast({
  74. title: error.message || '操作失败',
  75. duration: 3000,
  76. icon: "error"
  77. });
  78. playVoice(audioUrls.successVoiceUrl)
  79. console.error('操作失败:', error);
  80. }
  81. };