registration.vue 8.9 KB

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