registration.vue 9.0 KB

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