registration.vue 8.9 KB

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