useDraw.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ref, reactive } from "vue";
  2. import { payment } from "@/services/ams";
  3. let isBtn = ref(true);
  4. const appid = uni.getStorageSync("appid");
  5. export function useDraw(props?: any, emit?: any) {
  6. const handleClose = () => {
  7. emit("update:show", false);
  8. };
  9. const isWithDraw = (status: string) => {
  10. return status === "3" || status === "5" || status === "6";
  11. };
  12. const onPayment = (data: any, type: string) => {
  13. if (!isWithDraw(data.processStatus)) return;
  14. if (!isBtn.value) return;
  15. isBtn.value = false;
  16. const status =
  17. data.processStatus === "3" ||
  18. data.processStatus === "5" ||
  19. data.processStatus === "6";
  20. if (!status) return;
  21. payment(data.id)
  22. .then((res: any) => {
  23. if (res.code === 500) {
  24. uni.showToast({ icon: "none", title: "提现中" });
  25. return;
  26. }
  27. if (
  28. wx.canIUse("requestMerchantTransfer") &&
  29. res.data &&
  30. res.data.packageInfo
  31. ) {
  32. wx.requestMerchantTransfer({
  33. mchId: res.data.merchantId,
  34. appId: appid,
  35. package: res.data.packageInfo,
  36. success: (response: any) => {
  37. uni.showToast({ icon: "success", title: "请求成功" });
  38. if (type === "1") {
  39. setTimeout(() => {
  40. uni.switchTab({
  41. url: "/pages/my/index",
  42. });
  43. }, 500);
  44. } else {
  45. handleClose();
  46. }
  47. },
  48. fail: (response: any) => {
  49. // uni.showToast({ icon: "none", title: "提现中" });
  50. },
  51. });
  52. } else {
  53. if (!res.data || !res.data.packageInfo) {
  54. uni.showToast({ icon: "none", title: "提现中" });
  55. } else {
  56. wx.showModal({
  57. content: "你的微信版本过低,请更新至最新版本。",
  58. showCancel: false,
  59. });
  60. }
  61. }
  62. })
  63. .catch((err) => {
  64. console.log("-----------------------");
  65. uni.showToast({ icon: "none", title: err.msg });
  66. });
  67. setTimeout(() => {
  68. isBtn.value = true;
  69. }, 1500);
  70. };
  71. return { handleClose, onPayment, isWithDraw };
  72. }