index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const _sfc_main = {
  4. data() {
  5. return {
  6. phone: "",
  7. code: "",
  8. //时间标志
  9. time: null,
  10. //倒计时数字
  11. timeCount: 60,
  12. //显示倒计时还是发送验证码
  13. sendCodeFlag: "发送验证码",
  14. userId: "",
  15. resultId: ""
  16. };
  17. },
  18. onLoad(options) {
  19. if (options.userId && options.resultId) {
  20. this.userId = options.userId;
  21. this.resultId = options.resultId;
  22. }
  23. },
  24. onUnload() {
  25. clearInterval(this.time);
  26. this.phone = "";
  27. this.code = "";
  28. this.timeCount = 60;
  29. this.sendCodeFlag = "发送验证码";
  30. },
  31. methods: {
  32. //对手机号进行校验
  33. checkPhone() {
  34. var phoneReg = /^[1][3,4,5,7,8][0-9]{9}$/;
  35. if (phoneReg.test(this.phone)) {
  36. return true;
  37. } else {
  38. common_vendor.index.showToast({
  39. title: "请输入正确手机号",
  40. icon: "error"
  41. });
  42. return false;
  43. }
  44. },
  45. sendCode() {
  46. if (!this.checkPhone()) {
  47. return;
  48. }
  49. if (this.sendCodeFlag == "重新发送" || this.sendCodeFlag == "发送验证码") {
  50. this.timeCount = 60;
  51. clearInterval(this.time);
  52. this.sendCodeFlag = this.timeCount + "s";
  53. this.time = setInterval(() => {
  54. this.timeCount -= 1;
  55. this.sendCodeFlag = this.timeCount + "s";
  56. if (this.timeCount == 0) {
  57. clearInterval(this.time);
  58. this.sendCodeFlag = "重新发送";
  59. }
  60. }, 1e3);
  61. this.$request.get({
  62. url: "user/authCode",
  63. loadingTip: "加载中...",
  64. data: {
  65. phone: this.phone
  66. }
  67. }).then((res) => {
  68. common_vendor.index.showToast({
  69. title: "验证码已发送",
  70. icon: "success"
  71. });
  72. });
  73. }
  74. },
  75. // 绑定手机号并查看报告
  76. saveAndView() {
  77. if (this.checkPhone() && this.code != "") {
  78. this.$request.get({
  79. url: "user/updateMobile",
  80. loadingTip: "加载中...",
  81. data: {
  82. id: this.userId,
  83. mobile: this.phone,
  84. authCode: this.code
  85. }
  86. }).then((res) => {
  87. if (res.code == 200) {
  88. common_vendor.index.showToast({
  89. icon: "success",
  90. title: "保存成功"
  91. });
  92. common_vendor.index.navigateTo({
  93. url: `/scaleTestResults/testResults/index?resultId=${this.resultId}&messageShare=1`
  94. });
  95. } else {
  96. common_vendor.index.showToast({
  97. icon: "none",
  98. title: res.msg
  99. });
  100. }
  101. });
  102. }
  103. }
  104. }
  105. };
  106. if (!Array) {
  107. const _easycom_uni_easyinput2 = common_vendor.resolveComponent("uni-easyinput");
  108. _easycom_uni_easyinput2();
  109. }
  110. const _easycom_uni_easyinput = () => "../../node-modules/@dcloudio/uni-ui/lib/uni-easyinput/uni-easyinput.js";
  111. if (!Math) {
  112. _easycom_uni_easyinput();
  113. }
  114. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  115. return {
  116. a: common_vendor.o(($event) => $options.checkPhone()),
  117. b: common_vendor.o(($event) => $data.phone = $event),
  118. c: common_vendor.p({
  119. trim: "all",
  120. placeholder: "请输入手机号",
  121. ["placeholder-style"]: "font-size:32rpx",
  122. modelValue: $data.phone
  123. }),
  124. d: common_vendor.t($data.sendCodeFlag),
  125. e: common_vendor.o(($event) => $options.sendCode()),
  126. f: common_vendor.o(($event) => $data.code = $event),
  127. g: common_vendor.p({
  128. placeholder: "请输入验证码",
  129. ["placeholder-style"]: "font-size:32rpx",
  130. modelValue: $data.code
  131. }),
  132. h: common_vendor.o(($event) => $options.saveAndView())
  133. };
  134. }
  135. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-25e10d82"], ["__file", "E:/psy_web_share/paymentPage/phoneSave/index.vue"]]);
  136. tt.createPage(MiniProgramPage);