index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. formData: {
  7. name: "",
  8. phone: "",
  9. email: ""
  10. }
  11. };
  12. },
  13. methods: {
  14. goHome() {
  15. common_vendor.index.navigateBack({
  16. delta: 1
  17. });
  18. },
  19. submitForm() {
  20. if (!this.formData.name.trim()) {
  21. common_vendor.index.showToast({
  22. title: "请输入姓名",
  23. icon: "none"
  24. });
  25. return;
  26. }
  27. if (!this.formData.phone.trim()) {
  28. common_vendor.index.showToast({
  29. title: "请输入手机号",
  30. icon: "none"
  31. });
  32. return;
  33. }
  34. if (!/^1\d{10}$/.test(this.formData.phone)) {
  35. common_vendor.index.showToast({
  36. title: "请输入正确的手机号",
  37. icon: "none"
  38. });
  39. return;
  40. }
  41. if (this.formData.email && !/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/.test(this.formData.email)) {
  42. common_vendor.index.showToast({
  43. title: "请输入正确的邮箱",
  44. icon: "none"
  45. });
  46. return;
  47. }
  48. console.log("提交的表单数据:", this.formData);
  49. common_vendor.index.showLoading({
  50. title: "提交中..."
  51. });
  52. setTimeout(() => {
  53. common_vendor.index.hideLoading();
  54. common_vendor.index.showToast({
  55. title: "提交成功",
  56. icon: "success",
  57. duration: 1500,
  58. success: () => {
  59. setTimeout(() => {
  60. common_vendor.index.navigateTo({
  61. url: "/pages/success/success",
  62. // 修改为成功页面的路径
  63. fail: (err) => {
  64. console.error("页面跳转失败:", err);
  65. common_vendor.index.showToast({
  66. title: "页面跳转失败",
  67. icon: "none"
  68. });
  69. }
  70. });
  71. }, 1500);
  72. }
  73. });
  74. }, 1e3);
  75. }
  76. }
  77. };
  78. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  79. return {
  80. a: $data.formData.name,
  81. b: common_vendor.o(($event) => $data.formData.name = $event.detail.value),
  82. c: $data.formData.phone,
  83. d: common_vendor.o(($event) => $data.formData.phone = $event.detail.value),
  84. e: $data.formData.email,
  85. f: common_vendor.o(($event) => $data.formData.email = $event.detail.value),
  86. g: common_vendor.o((...args) => $options.submitForm && $options.submitForm(...args))
  87. };
  88. }
  89. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
  90. wx.createPage(MiniProgramPage);