regist.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <script setup>
  2. import { ref, reactive, watch } from "vue";
  3. import { post, get } from "@/utils/request";
  4. import { useRequest } from "@/composables/useRequest";
  5. const SendCodeByPhone = (params) => post("/Common/SendCodeByPhone", params);
  6. const PhoneLoginReg = (params) => post("/Login/PhoneLoginReg", params);
  7. // 响应式表单数据
  8. const form = ref({
  9. mobile: "",
  10. code: "",
  11. password: "",
  12. agentId: null,
  13. agentValue: "",
  14. userType: 4,
  15. userTypeName: "全民营销",
  16. readName: "",
  17. });
  18. const columnsAgent = ref([]);
  19. const columnsType = ref([
  20. {
  21. text: "中介",
  22. value: 3,
  23. },
  24. {
  25. text: "全民营销",
  26. value: 4,
  27. },
  28. ]);
  29. // 校验规则
  30. const rules = {
  31. mobile: [
  32. {
  33. required: true,
  34. message: "请输入用户名或手机号",
  35. trigger: ["change", "blur"],
  36. },
  37. {
  38. // 自定义验证函数,见上说明
  39. validator: (rule, value, callback) => {
  40. // 上面有说,返回true表示校验通过,返回false表示不通过
  41. // uni.$u.test.mobile()就是返回true或者false的
  42. return uni.$u.test.mobile(value);
  43. },
  44. message: "手机号码不正确",
  45. // 触发器可以同时用blur和change
  46. trigger: ["change", "blur"],
  47. },
  48. ],
  49. code: [
  50. {
  51. required: true,
  52. message: "请输入验证码",
  53. trigger: ["change", "blur"],
  54. },
  55. ],
  56. password: [
  57. {
  58. required: true,
  59. message: "请输入密码",
  60. trigger: ["change", "blur"],
  61. },
  62. ],
  63. readName: [
  64. {
  65. required: true,
  66. message: "请输入真实姓名",
  67. trigger: ["change", "blur"],
  68. },
  69. ],
  70. agentValue: [
  71. {
  72. required: true,
  73. message: "请选择中介",
  74. trigger: ["change", "blur"],
  75. },
  76. ],
  77. };
  78. const tips = ref("");
  79. const value = ref("");
  80. const seconds = ref(60);
  81. const uCodeRef = ref(null);
  82. watch(value, (newValue, oldValue) => {
  83. // console.log('v-model', newValue);
  84. });
  85. const codeChange = (text) => {
  86. tips.value = text;
  87. };
  88. const getCode = async () => {
  89. // console.log("uCodeRef.canGetCode: ", uCodeRef.value);
  90. if (!form.value.mobile) {
  91. return uni.$u.toast("请先输入手机号");
  92. }
  93. if (uCodeRef.value.canGetCode) {
  94. // 模拟向后端请求验证码
  95. uni.showLoading({
  96. title: "正在获取验证码",
  97. });
  98. const data = await SendCodeByPhone({ phone: form.value.mobile });
  99. // console.log("data: ", data);
  100. if (data) {
  101. setTimeout(() => {
  102. uni.hideLoading();
  103. // 这里此提示会被start()方法中的提示覆盖
  104. uni.$u.toast("验证码已发送");
  105. // 通知验证码组件内部开始倒计时
  106. uCodeRef.value.start();
  107. }, 2000);
  108. } else {
  109. uni.hideLoading();
  110. }
  111. } else {
  112. uni.$u.toast("倒计时结束后再发送");
  113. }
  114. };
  115. const change = (e) => {
  116. // console.log("change", e);
  117. };
  118. const showAgent = ref(false);
  119. const confirmAgent = (e) => {
  120. // console.log("e: ", e);
  121. form.value.agentValue = e.value[0].text;
  122. form.value.agentId = e.value[0].value;
  123. showAgent.value = false;
  124. };
  125. const showType = ref(false);
  126. const confirmType = (e) => {
  127. // console.log("e: ", e);
  128. form.value.userTypeName = e.value[0].text;
  129. form.value.userType = e.value[0].value;
  130. if (form.value.userType == 4) {
  131. form.value.agentValue = "";
  132. form.value.agentId = "";
  133. }
  134. showType.value = false;
  135. };
  136. const uFormRef = ref(null);
  137. function submit() {
  138. uFormRef.value
  139. .validate()
  140. .then(async (valid) => {
  141. if (valid) {
  142. if (!aloneChecked.value) {
  143. return uni.$u.toast("请同意用户协议与隐私政策");
  144. }
  145. // uni.$u.toast('校验通过');
  146. let res = await PhoneLoginReg({
  147. phone: form.value.mobile,
  148. code: form.value.code,
  149. password: form.value.password,
  150. agencyId: form.value.agentId || null,
  151. userType: form.value.userType,
  152. name: form.value.readName,
  153. });
  154. // console.log("res: ", res);
  155. if (res) {
  156. uni.$u.toast("注册并登录成功");
  157. uni.setStorageSync("token", res);
  158. setTimeout(() => {
  159. uni.redirectTo({
  160. url: "/pages/index/index",
  161. });
  162. }, 1500);
  163. }
  164. } else {
  165. // uni.$u.toast('校验失败');
  166. }
  167. })
  168. .catch(() => {
  169. // 处理验证错误
  170. // uni.$u.toast('校验失败');
  171. });
  172. }
  173. const customStyle = {
  174. height: "84px",
  175. "border-radius": "8px",
  176. background: "#f7f8fa",
  177. padding: "0 20px !important",
  178. position: "relative",
  179. };
  180. const aloneChecked = ref(false);
  181. const getRichText = (url) => {
  182. uni.navigateTo({
  183. url,
  184. });
  185. };
  186. const GetAgencys = (params) => get("/Buss/GetAgencys", params);
  187. const { data, loading, error, refresh } = useRequest(GetAgencys, {
  188. initialParams: {},
  189. immediate: true, // 默认立即执行
  190. });
  191. watch([loading, error], () => {
  192. if (!loading.value) {
  193. // 加载完成
  194. if (error.value) {
  195. // console.log("请求失败: ", error.value); // 打印错误信息
  196. } else {
  197. // console.log("请求成功: ", data.value); // 成功时获取数据
  198. columnsAgent.value = data.value.map((item) => {
  199. return {
  200. text: item.name,
  201. value: item.id,
  202. };
  203. });
  204. }
  205. }
  206. });
  207. </script>
  208. <template>
  209. <view>
  210. <view class="company u-flex u-flex-y-center">
  211. <image src="/static/images/logo.png" class="company-icon" mode="widthFix"></image>
  212. <view class="company-head">
  213. <view class="name">华都渠道管家</view>
  214. <view class="into">专业的房产销售管理平台</view>
  215. </view>
  216. </view>
  217. <view class="account">
  218. <view>
  219. <up-form :model="form" :rules="rules" ref="uFormRef">
  220. <up-form-item label="" @click.prevent="showType = true">
  221. <up-input :customStyle="customStyle" v-model="form.userTypeName" border="none" :disabled="true"
  222. placeholder="请选择身份">
  223. <template #suffix>
  224. <up-icon name="arrow-down" color="#222222" size="12"></up-icon>
  225. </template>
  226. </up-input>
  227. </up-form-item>
  228. <up-picker :show="showType" @confirm="confirmType" @close="showType = false" @cancel="showType = false"
  229. :columns="[columnsType]" valueKey="value" labelKey="text"></up-picker>
  230. <up-form-item label="" prop="readName">
  231. <up-input :customStyle="customStyle" v-model="form.readName" border="none" placeholder="请输入真实姓名" />
  232. </up-form-item>
  233. <up-form-item label="" prop="mobile">
  234. <up-input :customStyle="customStyle" v-model="form.mobile" border="none" placeholder="请输入用户名或手机号" />
  235. </up-form-item>
  236. <up-form-item label="" prop="code">
  237. <up-input :customStyle="customStyle" v-model="form.code" border="none" placeholder="请输入验证码">
  238. <template #suffix>
  239. <up-code ref="uCodeRef" @change="codeChange" :seconds="seconds"></up-code>
  240. <up-text :text="tips" @click="getCode" class="code-text"></up-text>
  241. </template>
  242. </up-input>
  243. </up-form-item>
  244. <up-form-item label="" prop="password">
  245. <up-input :customStyle="customStyle" v-model="form.password" type="password" border="none"
  246. placeholder="设置密码" />
  247. </up-form-item>
  248. <up-form-item label="" prop="agentValue" @click.prevent="showAgent = true" v-if="form.userType == 3">
  249. <up-input :customStyle="customStyle" v-model="form.agentValue" border="none" :disabled="true"
  250. placeholder="所属中介">
  251. <template #suffix>
  252. <up-icon name="arrow-down" color="#222222" size="12"></up-icon>
  253. </template>
  254. </up-input>
  255. </up-form-item>
  256. <up-picker :show="showAgent" @confirm="confirmAgent" @close="showAgent = false" @cancel="showAgent = false"
  257. :columns="[columnsAgent]" valueKey="value" labelKey="text"></up-picker>
  258. </up-form>
  259. </view>
  260. </view>
  261. <view class="">
  262. <up-checkbox :customStyle="{ marginBottom: '8px' }" name="agree" usedAlone v-model:checked="aloneChecked"
  263. size="14" labelSize="14" labelColor="#666666">
  264. <template #label>
  265. <view class="account-tip">
  266. 请阅读并同意
  267. <text @click.prevent="getRichText('/pages/mine/richtext?type=1')">用户协议</text>
  268. <text @click.prevent="getRichText('/pages/mine/richtext?type=2')">隐私政策</text>
  269. </view>
  270. </template>
  271. </up-checkbox>
  272. </view>
  273. <button type="primary" class="regiset-btn" @click="submit">注册</button>
  274. <navigator url="/pages/login/index" class="account-tip">
  275. 已有账号?
  276. <text>立即登录</text>
  277. </navigator>
  278. </view>
  279. </template>
  280. <style>
  281. page {
  282. padding: px2rpx(10) px2rpx(52);
  283. box-sizing: border-box;
  284. }
  285. </style>
  286. <style lang="scss" scoped>
  287. @import "@/uni.scss";
  288. button {
  289. background-color: #ea002a;
  290. font-size: px2rpx(14);
  291. font-weight: normal;
  292. height: px2rpx(84);
  293. line-height: px2rpx(84);
  294. }
  295. .company {
  296. padding: px2rpx(40) 0;
  297. }
  298. .company-icon {
  299. width: px2rpx(104);
  300. height: px2rpx(104);
  301. margin-right: px2rpx(14);
  302. }
  303. .company-head {
  304. .name {
  305. font-size: px2rpx(20);
  306. font-weight: 500;
  307. color: #ea002a;
  308. margin-bottom: px2rpx(2);
  309. }
  310. .into {
  311. font-size: px2rpx(13);
  312. font-weight: 350;
  313. color: #222222;
  314. }
  315. }
  316. .account {
  317. .input {
  318. height: px2rpx(84);
  319. border-radius: px2rpx(8);
  320. background: #f7f8fa;
  321. padding: 0 px2rpx(20) !important;
  322. }
  323. }
  324. .regiset-btn {
  325. margin: px2rpx(20) 0;
  326. }
  327. .account-tip {
  328. color: #666666;
  329. font-size: px2rpx(13);
  330. text-align: center;
  331. text {
  332. color: #ea002a;
  333. }
  334. }
  335. .code-text {
  336. padding-right: px2rpx(20);
  337. }
  338. :deep(.u-text__value) {
  339. color: #ea002a !important;
  340. font-size: px2rpx(14) !important;
  341. }
  342. </style>