uploadRecept.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="uploadReceptBox">
  3. <custom-upload title="购物小票图片" @success="handleRecept"></custom-upload>
  4. <custom-upload
  5. title="微信支付账单详情图片"
  6. @success="handleBill"
  7. ></custom-upload>
  8. <view class="remark">
  9. <view class="tBox"><text class="xing">*</text><text>申请理由</text></view>
  10. <view class="inputBox">
  11. <!-- <input type="text" /> -->
  12. <wd-textarea
  13. v-model="queryParams.applyReason"
  14. placeholder="请填写申请理由"
  15. />
  16. </view>
  17. </view>
  18. </view>
  19. <wd-gap bg-color="#fff" height="256rpx"></wd-gap>
  20. <view class="btn" @click="onSubmit">立即上传</view>
  21. </template>
  22. <script lang="ts" setup>
  23. import { onLoad } from "@dcloudio/uni-app";
  24. import { ref, reactive } from "vue";
  25. import CustomUpload from "@/components/customUpload.vue";
  26. import type { Claim } from "../../services/interface";
  27. import { quickclaimSubmit } from "@/services/claim";
  28. import { getOpenId } from "@/services/ams";
  29. const aData = JSON.parse(uni.getStorageSync("activityData"));
  30. const queryParams: Claim = reactive({
  31. brandId: uni.getStorageSync("brandId") || aData?.brandId,
  32. mobile: uni.getStorageSync("phone") || "",
  33. openid: uni.getStorageSync("openid"),
  34. paymentBillImage: "",
  35. receiptImage: "",
  36. applyReason: "",
  37. });
  38. const handleRecept = (val: Array<string>) => {
  39. console.log(val);
  40. queryParams.receiptImage = val.join(",");
  41. };
  42. const handleBill = (val: Array<string>) => {
  43. queryParams.paymentBillImage = val.join(",");
  44. };
  45. const onSubmit = async () => {
  46. if (!queryParams.paymentBillImage) {
  47. uni.showToast({
  48. title: "请上传微信支付账单详情图片",
  49. icon: "none",
  50. });
  51. return;
  52. }
  53. if (!queryParams.receiptImage) {
  54. uni.showToast({
  55. title: "请上传购物小票图片",
  56. icon: "none",
  57. });
  58. return;
  59. }
  60. if (!queryParams.applyReason) {
  61. uni.showToast({
  62. title: "请填写申请理由",
  63. icon: "none",
  64. });
  65. return;
  66. }
  67. if (!queryParams.openid) {
  68. uni.login({
  69. //获取code,
  70. success: async (res) => {
  71. const params = {
  72. code: res.code,
  73. appid: uni.getAccountInfoSync().miniProgram.appId,
  74. };
  75. getOpenId(params).then((response: any) => {
  76. if (response.code === 200) {
  77. queryParams.openid = response.data.openid;
  78. onUpload(queryParams);
  79. uni.setStorageSync("openid", response.data.openid);
  80. } else {
  81. uni.showToast({
  82. title: "获取openid失败",
  83. icon: "none",
  84. });
  85. }
  86. });
  87. },
  88. });
  89. } else {
  90. onUpload(queryParams);
  91. }
  92. };
  93. const onUpload = async (params: Claim) => {
  94. const res: any = await quickclaimSubmit(params);
  95. try {
  96. uni.showToast({
  97. title: res.msg,
  98. icon: res.code === 200 ? "success" : "none",
  99. });
  100. if (res.code === 200) {
  101. setTimeout(() => {
  102. uni.navigateBack();
  103. }, 500);
  104. }
  105. } catch (err) {
  106. uni.showToast({
  107. title: res.msg || "上传失败",
  108. icon: "none",
  109. });
  110. }
  111. };
  112. onLoad(() => {
  113. // console.log("--------------------------", Models.Claim);
  114. });
  115. </script>
  116. <style lang="scss" scoped>
  117. .uploadReceptBox {
  118. min-height: 100vh;
  119. .remark {
  120. padding: 0 32rpx;
  121. .tBox {
  122. color: #333333;
  123. font-size: 32rpx;
  124. font-weight: bold;
  125. margin-bottom: 32rpx;
  126. .xing {
  127. color: #e90308;
  128. }
  129. }
  130. .inputBox {
  131. border: rgba(191, 200, 219, 0.5) 2rpx solid;
  132. }
  133. }
  134. }
  135. .btn {
  136. width: 560rpx;
  137. background: linear-gradient(90deg, #225036 0%, #3b8e5e 45.92%, #296141 100%);
  138. color: #fff;
  139. font-size: 32rpx;
  140. border-radius: 80rpx;
  141. margin: 204rpx auto 0;
  142. text-align: center;
  143. line-height: 100rpx;
  144. position: fixed;
  145. bottom: 0;
  146. left: 0;
  147. right: 0;
  148. margin: auto;
  149. bottom: 103rpx;
  150. z-index: 99;
  151. }
  152. </style>