registration.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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. uni.setStorageSync("pages/challenge/index", null);
  137. },
  138. fail(err) {
  139. console.log(err);
  140. },
  141. complete() {
  142. loading.value = false;
  143. },
  144. });
  145. },
  146. fail() {
  147. loading.value = false;
  148. },
  149. });
  150. };
  151. const onChange = (e) => {
  152. permissions.value = !!e.detail.value[0];
  153. };
  154. </script>
  155. <template>
  156. <Container
  157. title="报名"
  158. :scrollStyle="{
  159. padding: 0,
  160. }"
  161. bgColor="#a8e0fd"
  162. bottomBgColor="#fff"
  163. headerColor="#fff"
  164. v-if="!show"
  165. >
  166. <view class="bg">
  167. <view class="bg-1">
  168. <form>
  169. <view class="uni-form-item">
  170. <view class="title required">姓名</view>
  171. <input
  172. class="uni-input"
  173. name="contact_name"
  174. placeholder="请输入真实姓名"
  175. v-model="formData.contact_name"
  176. />
  177. </view>
  178. <view class="uni-form-item">
  179. <view class="title required">联系方式</view>
  180. <input
  181. class="uni-input"
  182. name="contact_information"
  183. placeholder="请输入电话号码"
  184. v-model="formData.contact_information"
  185. />
  186. </view>
  187. <view class="uni-form-item">
  188. <view class="title required">报考执业药师类型(请选择)</view>
  189. <RadioBlock
  190. v-model="formData.pharmacist_type"
  191. name="pharmacist_type"
  192. :columns="[
  193. {
  194. label: '西药',
  195. value: 2,
  196. },
  197. {
  198. label: '中药',
  199. value: 1,
  200. },
  201. ]"
  202. />
  203. </view>
  204. </form>
  205. </view>
  206. </view>
  207. <div class="permissions">
  208. <checkbox-group @change="onChange">
  209. <label>
  210. <checkbox class="checkbox" :value="1" />
  211. 阅读并确认
  212. </label>
  213. </checkbox-group>
  214. <span
  215. class="text-primary"
  216. @click="
  217. () => {
  218. router.push({
  219. url: '/pages/richpage/index',
  220. params: {
  221. title: '会员服务权益',
  222. content_code: 'service_rights',
  223. },
  224. });
  225. }
  226. "
  227. >《会员服务权益》</span
  228. >
  229. <span
  230. class="text-primary"
  231. @click="
  232. () => {
  233. router.push({
  234. url: '/pages/challenge/rule',
  235. params: {
  236. id: getRoute().params.id,
  237. },
  238. });
  239. }
  240. "
  241. >《活动规则》</span
  242. >
  243. </div>
  244. <view class="service">
  245. <CustomerService>联系客服</CustomerService>
  246. </view>
  247. <template #footer>
  248. <button
  249. :loading="loading"
  250. :disabled="loading"
  251. class="btn"
  252. @click="onSubmit"
  253. >
  254. ¥{{ price }} 立即开通
  255. </button>
  256. </template>
  257. </Container>
  258. <Modal
  259. v-model:open="show"
  260. title="温馨提示"
  261. :submitter="{
  262. closeText: '不同意',
  263. text: '同意并支付',
  264. }"
  265. :onClose="() => (show = false)"
  266. :onSubmit="
  267. () => {
  268. permissions = true;
  269. show = false;
  270. onSubmit();
  271. }
  272. "
  273. >
  274. <div class="text">
  275. <span> 阅读并确认 </span>
  276. <span
  277. class="text-primary"
  278. @click="
  279. () => {
  280. router.push({
  281. url: '/pages/richpage/index',
  282. params: {
  283. title: '会员服务权益',
  284. content_code: 'service_rights',
  285. },
  286. });
  287. }
  288. "
  289. >《会员服务权益》</span
  290. >
  291. <span
  292. class="text-primary"
  293. @click="
  294. () => {
  295. router.push({
  296. url: '/pages/challenge/rule',
  297. params: {
  298. id: getRoute().params.id,
  299. },
  300. });
  301. }
  302. "
  303. >《活动规则》</span
  304. >
  305. </div>
  306. </Modal>
  307. </template>
  308. <style scoped lang="scss">
  309. .bg {
  310. width: 100%;
  311. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/yz2eTeqIRv60IEe6kOQBOYlHr75wiFIpeFqrJmgZ.png")
  312. no-repeat;
  313. background-size: 100%;
  314. padding: 216rpx 10rpx 0;
  315. box-sizing: border-box;
  316. display: flex;
  317. flex-direction: column;
  318. justify-content: space-between;
  319. .bg-1 {
  320. width: 730.71rpx;
  321. height: 841rpx;
  322. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/06/3P7CBvlUNmunkIM1PA5voYhrGpIIgeqgy30pLb1z.png")
  323. no-repeat;
  324. background-size: 100% 100%;
  325. position: relative;
  326. box-sizing: border-box;
  327. padding: 170rpx 50rpx;
  328. .uni-form-item .title {
  329. padding: 20rpx 0;
  330. }
  331. .uni-input {
  332. border-radius: 8rpx 8rpx 8rpx 8rpx;
  333. border: 1rpx solid #dddddd;
  334. padding: 14rpx 9rpx;
  335. }
  336. }
  337. }
  338. .text {
  339. font-size: 30rpx;
  340. margin: 20rpx 0;
  341. }
  342. .service {
  343. position: absolute;
  344. bottom: 20%;
  345. right: 5%;
  346. color: $uni-primary;
  347. font-size: 28rpx;
  348. margin-bottom: 40rpx;
  349. text-align: right;
  350. }
  351. .permissions {
  352. position: absolute;
  353. bottom: 15%;
  354. left: 32rpx;
  355. display: flex;
  356. align-items: center;
  357. font-weight: 500;
  358. font-size: 28rpx;
  359. color: #333333;
  360. }
  361. .btn {
  362. margin: 32rpx 0;
  363. font-weight: 400;
  364. font-size: 32rpx;
  365. color: #ffffff;
  366. }
  367. </style>