registration.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <script setup name="registration">
  2. import Container from "../../components/Container/Container.vue";
  3. import CustomerService from "../../components/CustomerService/CustomerService.vue";
  4. import RadioBlock from "../../components/RadioBlock/RadioBlock.vue";
  5. import Modal from "../../components/Modal/Modal.vue";
  6. import { onShow } from "@dcloudio/uni-app";
  7. import { request } from "../../utils/request";
  8. import { getRoute, router } from "../../utils/router";
  9. import { ref, getCurrentInstance } from "vue";
  10. import ext from "../../ext.json";
  11. const instance = getCurrentInstance();
  12. const context = ref("");
  13. const permissions = ref(false);
  14. const formData = ref({
  15. contact_name: "",
  16. contact_information: "",
  17. pharmacist_type: 0,
  18. });
  19. const loading = ref(false);
  20. const show = ref(false);
  21. const rules = {
  22. contact_name: [
  23. {
  24. required: true,
  25. message: "请输入姓名",
  26. },
  27. ],
  28. contact_information: [
  29. {
  30. required: true,
  31. message: "请输入联系方式",
  32. type: "phone",
  33. },
  34. ],
  35. pharmacist_type: [
  36. {
  37. required: true,
  38. message: "请选择报考药师类型",
  39. },
  40. ],
  41. };
  42. onShow(() => {
  43. const { id } = getRoute().params;
  44. request("api/question_bank/question_reception/recharge_package/detail", {
  45. id,
  46. }).then((res) => {
  47. context.value = res.data.instructions || "";
  48. });
  49. });
  50. const validate = ({ value, message, type = "text" }) =>
  51. new Promise((resolve, reject) => {
  52. if (!value) {
  53. uni.showToast({
  54. title: message,
  55. icon: "none",
  56. });
  57. loading.value = false;
  58. return reject(message);
  59. }
  60. if (type === "phone") {
  61. const phoneReg =
  62. /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1589]))\d{8}$/;
  63. if (!phoneReg.test(value)) {
  64. uni.showToast({
  65. title: "请输入正确的手机号码",
  66. icon: "none",
  67. });
  68. loading.value = false;
  69. return reject("请输入正确的手机号码");
  70. }
  71. }
  72. resolve();
  73. });
  74. const onSubmit = async () => {
  75. loading.value = true;
  76. for (const key in formData.value) {
  77. await validate({
  78. value: formData.value[key],
  79. message: rules[key][0].message,
  80. type: rules[key][0].type,
  81. });
  82. }
  83. if (!permissions.value) {
  84. show.value = true;
  85. return;
  86. }
  87. const { id } = getRoute().params;
  88. uni.login({
  89. provider: instance.proxy.$mpPlatform.substring(3),
  90. success: async ({ code }) => {
  91. const order = await request(
  92. "api/question_bank/question_reception/challenge_registration_log/add",
  93. {
  94. package_id: id,
  95. ...formData.value,
  96. }
  97. );
  98. const e = await request(
  99. "api/question_bank/question_reception/orders/wechat_pay",
  100. {
  101. code,
  102. order_id: order.data.order_id,
  103. app_id: ext.extAppid,
  104. }
  105. );
  106. uni.requestPayment({
  107. provider: "wxpay",
  108. timeStamp: e.data.timeStamp, //时间戳
  109. nonceStr: e.data.nonceStr, //随机字符串
  110. package: e.data.package, //prepay_id
  111. signType: e.data.signType, //签名算法MD5
  112. paySign: e.data.paySign, //签名,
  113. success() {
  114. router.redirectTo({
  115. url: "/pages/challenge/addContant",
  116. params: {
  117. type: formData.value.pharmacist_type,
  118. },
  119. });
  120. },
  121. fail(err) {
  122. console.log(err);
  123. },
  124. complete() {
  125. loading.value = false;
  126. },
  127. });
  128. },
  129. });
  130. };
  131. </script>
  132. <template>
  133. <Container
  134. title="报名"
  135. :scrollStyle="{
  136. padding: 0,
  137. }"
  138. bgColor="#a8e0fd"
  139. bottomBgColor="#fff"
  140. headerColor="#fff"
  141. v-if="!show"
  142. >
  143. <view class="bg">
  144. <view class="bg-1">
  145. <form>
  146. <view class="uni-form-item">
  147. <view class="title required">姓名</view>
  148. <input
  149. class="uni-input"
  150. name="contact_name"
  151. placeholder="请输入真实姓名"
  152. v-model="formData.contact_name"
  153. />
  154. </view>
  155. <view class="uni-form-item">
  156. <view class="title required">联系方式</view>
  157. <input
  158. class="uni-input"
  159. name="contact_information"
  160. placeholder="请输入电话号码"
  161. v-model="formData.contact_information"
  162. />
  163. </view>
  164. <view class="uni-form-item">
  165. <view class="title required">报考药师类型(请选择)</view>
  166. <RadioBlock
  167. v-model="formData.pharmacist_type"
  168. name="pharmacist_type"
  169. :columns="[
  170. {
  171. label: '西药',
  172. value: 2,
  173. },
  174. {
  175. label: '中药',
  176. value: 1,
  177. },
  178. ]"
  179. />
  180. </view>
  181. </form>
  182. </view>
  183. </view>
  184. <div class="permissions">
  185. <label>
  186. <checkbox class="checkbox" :value="permissions" />
  187. 阅读并确认
  188. </label>
  189. <span
  190. class="text-primary"
  191. @click="
  192. () => {
  193. router.push({
  194. url: '/pages/richpage/index',
  195. params: {
  196. title: '会员服务权益',
  197. content_code: 'service_rights',
  198. },
  199. });
  200. }
  201. "
  202. >《会员服务权益》</span
  203. >
  204. <span
  205. class="text-primary"
  206. @click="
  207. () => {
  208. router.push({
  209. url: '/pages/challenge/rule',
  210. params: {
  211. id: getRoute().params.id,
  212. },
  213. });
  214. }
  215. "
  216. >《活动规则》</span
  217. >
  218. </div>
  219. <view class="service">
  220. <CustomerService>联系客服</CustomerService>
  221. </view>
  222. <template #footer>
  223. <button
  224. :loading="loading"
  225. :disabled="loading"
  226. class="btn"
  227. @click="onSubmit"
  228. >
  229. ¥999 立即开通
  230. </button>
  231. </template>
  232. </Container>
  233. <Modal
  234. v-model:open="show"
  235. title="温馨提示"
  236. :submitter="{
  237. closeText: '不同意',
  238. text: '同意并支付',
  239. }"
  240. :onClose="() => (show = false)"
  241. :onSubmit="
  242. () => {
  243. permissions = true;
  244. show = false;
  245. onSubmit();
  246. }
  247. "
  248. >
  249. <div class="text">
  250. <span> 阅读并确认 </span>
  251. <span
  252. class="text-primary"
  253. @click="
  254. () => {
  255. router.push({
  256. url: '/pages/richpage/index',
  257. params: {
  258. title: '会员服务权益',
  259. content_code: 'service_rights',
  260. },
  261. });
  262. }
  263. "
  264. >《会员服务权益》</span
  265. >
  266. <span
  267. class="text-primary"
  268. @click="
  269. () => {
  270. router.push({
  271. url: '/pages/challenge/rule',
  272. params: {
  273. id: getRoute().params.id,
  274. },
  275. });
  276. }
  277. "
  278. >《活动规则》</span
  279. >
  280. </div>
  281. </Modal>
  282. </template>
  283. <style scoped lang="scss">
  284. .bg {
  285. width: 100%;
  286. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/yz2eTeqIRv60IEe6kOQBOYlHr75wiFIpeFqrJmgZ.png")
  287. no-repeat;
  288. background-size: 100%;
  289. padding: 216rpx 10rpx 0;
  290. box-sizing: border-box;
  291. display: flex;
  292. flex-direction: column;
  293. justify-content: space-between;
  294. .bg-1 {
  295. width: 730.71rpx;
  296. height: 841rpx;
  297. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/06/3P7CBvlUNmunkIM1PA5voYhrGpIIgeqgy30pLb1z.png")
  298. no-repeat;
  299. background-size: 100% 100%;
  300. position: relative;
  301. box-sizing: border-box;
  302. padding: 170rpx 50rpx;
  303. .uni-form-item .title {
  304. padding: 20rpx 0;
  305. }
  306. .uni-input {
  307. border-radius: 8rpx 8rpx 8rpx 8rpx;
  308. border: 1rpx solid #dddddd;
  309. padding: 14rpx 9rpx;
  310. }
  311. }
  312. }
  313. .text {
  314. font-size: 30rpx;
  315. margin: 20rpx 0;
  316. }
  317. .service {
  318. position: absolute;
  319. bottom: 20%;
  320. right: 5%;
  321. color: $uni-primary;
  322. font-size: 28rpx;
  323. margin-bottom: 40rpx;
  324. text-align: right;
  325. }
  326. .permissions {
  327. position: absolute;
  328. bottom: 15%;
  329. left: 32rpx;
  330. display: flex;
  331. align-items: center;
  332. font-weight: 500;
  333. font-size: 28rpx;
  334. color: #333333;
  335. }
  336. .btn {
  337. margin: 32rpx 0;
  338. font-weight: 400;
  339. font-size: 32rpx;
  340. color: #ffffff;
  341. }
  342. </style>