register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="page">
  3. <!-- #ifdef H5-->
  4. <uni-nav-bar v-if="!$isWxBrowser()" :fixed="true" background-color="#FFE05C" :border="false" :statusBar="false"
  5. title="注册"/>
  6. <!-- #endif -->
  7. <view :style="{'marginTop':'10rpx'}">
  8. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  9. <u-form-item :labelWidth="80" label="头像:" borderBottom prop="img" ref="item1">
  10. <view class="photoView" @click="updateAvatar">
  11. <image class="photoImage" :src="form.imgUrl || '/static/ud4.png'"></image>
  12. </view>
  13. </u-form-item>
  14. <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
  15. <u--input v-model="form.name" placeholder="请输入姓名" border="none"></u--input>
  16. </u-form-item>
  17. <u-form-item :labelWidth="80" label="身份证号:" borderBottom prop="idCard" ref="item1">
  18. <u--input v-model="form.idCard" placeholder="请输入身份证号" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
  21. <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
  22. </u-form-item>
  23. <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
  24. <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password"
  25. border="none"></u--input>
  26. </u-form-item>
  27. <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="phone" ref="item1">
  28. <u--input v-model="form.phone" placeholder="请输入手机号" border="none"></u--input>
  29. </u-form-item>
  30. <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
  31. <view class="inputCode">
  32. <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
  33. </view>
  34. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small"
  35. :disabled="disabled1"></u-button>
  36. </u-form-item>
  37. </u--form>
  38. <view :style="{'marginTop':'100rpx'}">
  39. <!-- <button class="customStyle" @click="expandRegister">提交</button>-->
  40. <button class="customStyle" @click="debounce(expandRegister,500)">提交</button>
  41. </view>
  42. <view class="flex-row justify-center register">
  43. <text>已有账号!</text>
  44. <text @click="gologin" :style="{color:'#FFE05C'}">切换登录</text>
  45. </view>
  46. </view>
  47. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true"
  48. @end="disabled1 = false"></u-code>
  49. <u-action-sheet
  50. :show="showSex"
  51. :actions="actions"
  52. title="请选择性别"
  53. @close="showSex = false"
  54. @select="sexSelect">
  55. </u-action-sheet>
  56. <u-datetime-picker
  57. :show="showBirthday"
  58. :value="birthday"
  59. mode="date"
  60. closeOnClickOverlay
  61. @confirm="birthdayConfirm"
  62. @cancel="birthdayClose"
  63. @close="birthdayClose"
  64. ></u-datetime-picker>
  65. </view>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. timer: null, //定时任务
  72. recordId: '',//拓客经理二维码被扫记录id
  73. qrCodeInvalid: false,//二维码是否无效标识
  74. requestStatus: false,
  75. disabled1: false,
  76. showBirthday: false,
  77. showSex: false,
  78. birthday: Number(new Date()),
  79. actions: [{
  80. name: '男',
  81. value: '1'
  82. },
  83. {
  84. name: '女',
  85. value: '0'
  86. }, {
  87. name: '保密',
  88. value: '2'
  89. }
  90. ],
  91. tips: '',
  92. form: {
  93. roleId: '',
  94. parentId: '',
  95. img: '',
  96. imgUrl: '',
  97. name: '',
  98. idCard: '',
  99. newPassword: '',
  100. againPassword: '',
  101. phone: '',
  102. code: '',
  103. },
  104. rules: {
  105. 'img': {
  106. type: 'string',
  107. required: true,
  108. message: '请上传头像',
  109. trigger: ['blur', 'change']
  110. },
  111. 'name': [
  112. {
  113. type: 'string',
  114. required: true,
  115. min: 2,
  116. pattern: '^([\u4e00-\u9fa5]{2,20})$',
  117. message: '请输入正确的姓名',
  118. trigger: ['blur', 'change']
  119. }
  120. ],
  121. 'idCard': [
  122. {
  123. type: 'string',
  124. required: true,
  125. min: 18,
  126. max: 18,
  127. pattern: this.$idCardPattern,
  128. message: '请输入身份证号',
  129. trigger: ['blur', 'change']
  130. }
  131. ],
  132. 'phone': {
  133. type: 'string',
  134. required: true,
  135. min: 11,
  136. max: 11,
  137. pattern: this.$phonePattern,
  138. message: '请输入正确的电话号码',
  139. trigger: ['blur', 'change']
  140. },
  141. 'code': {
  142. type: 'string',
  143. required: true,
  144. min: 4,
  145. max: 6,
  146. message: '请输入验证码',
  147. trigger: ['blur', 'change']
  148. },
  149. 'newPassword': {
  150. type: 'string',
  151. min: 6,
  152. max: 16,
  153. required: true,
  154. message: '请输入6-18位密码',
  155. trigger: ['blur', 'change']
  156. },
  157. 'againPassword': {
  158. type: 'string',
  159. min: 6,
  160. max: 16,
  161. required: true,
  162. message: '请输入6-18位密码',
  163. trigger: ['blur', 'change']
  164. }
  165. },
  166. }
  167. },
  168. onLoad(e) {
  169. if (e.roleId) {
  170. console.log('++++++++++++扫码进注册页面+++++++++++++++++++')
  171. uni.setStorageSync('isRegister', true)
  172. this.form.roleId = e.roleId
  173. console.log('获取到的id', e.roleId)
  174. }
  175. if (e.type) {
  176. this.form.type = e.type
  177. console.log('获取到的type', e.type)
  178. }
  179. if (e.parentId) {
  180. this.form.parentId = e.parentId
  181. console.log('获取到的name', e.parentId)
  182. this.addRecordForManager()
  183. }
  184. if (e.timestamp) {
  185. console.log('获取到的时间戳', e.timestamp, new Date().getTime() > e.timestamp)
  186. if (new Date().getTime() > e.timestamp) {
  187. this.qrCodeInvalid = true
  188. uni.showModal({
  189. title: '温馨提示',
  190. content: ' 当前二维码已过期,请重新扫码',
  191. showCancel: false,
  192. success: function (res) {
  193. if (res.confirm) {
  194. console.log('用户点击确定');
  195. } else if (res.cancel) {
  196. console.log('用户点击取消');
  197. }
  198. }
  199. });
  200. }
  201. }
  202. },
  203. methods: {
  204. addRecordForManager() {
  205. console.log("+++++++++++++创建被扫码记录++++++++++++++")
  206. console.log("+++++++++++++拓客经理id++++++++++++++", this.form.parentId)
  207. console.log("+++++++++++++角色id++++++++++++++", this.form.roleId)
  208. this.$api.service.addRecordForManager({
  209. expandUserId: this.form.parentId,
  210. roleId: this.form.roleId,
  211. type: this.form.type
  212. }).then(res => {
  213. console.log("获取到的记录id", res.data.data)
  214. this.recordId = res.data.data
  215. })
  216. },
  217. updateScanRecordById() {
  218. this.$api.service.updateScanRecordById({
  219. recordId: this.recordId
  220. }).then(res => {
  221. console.log("+++++++++++++创建被扫码记录为成功++++++++++++++", res)
  222. })
  223. },
  224. idCardAndName() {
  225. return this.$api.service.idCardAndName({
  226. name: this.form.name,
  227. idCard: this.form.idCard,
  228. }).then(res => {
  229. return res
  230. })
  231. },
  232. gologin() {
  233. uni.redirectTo({
  234. url: '/pages/login/login'
  235. })
  236. },
  237. updateAvatar() {
  238. let that = this
  239. uni.chooseImage({
  240. count: 1, //默认9
  241. sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  242. sourceType: ['album'], //从相册选择
  243. success: function (res) {
  244. let tempUrl = res.tempFiles[0].path
  245. uni.uploadFile({
  246. url: that.$baseUrl + '/resource/oss/upload', //仅为示例,非真实的接口地址
  247. filePath: tempUrl,
  248. name: 'file',
  249. header: {
  250. // "Content-Type": "multipart/form-data",
  251. // 'X-Access-Token': uni.getStorageSync('token'),
  252. 'Authorization': 'Bearer ' + uni.getStorageSync('accessToken'),
  253. },
  254. success: (uploadFileRes) => {
  255. let res = JSON.parse(uploadFileRes.data)
  256. console.log('+++++++++++++++++chooseavatar+++++++++++++++++++++++', uploadFileRes.data)
  257. that.form.imgUrl = res.data.url.replace(/^http:/, "https:")
  258. that.form.img = res.data.ossId
  259. }
  260. });
  261. }
  262. })
  263. },
  264. birthdayClose() {
  265. this.showBirthday = false
  266. // this.$refs.form1.validateField('userInfo.birthday')
  267. },
  268. birthdayConfirm(e) {
  269. console.log(e)
  270. this.showBirthday = false
  271. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  272. // this.$refs.form1.validateField('userInfo.birthday')
  273. },
  274. sexSelect(e) {
  275. console.log(e)
  276. },
  277. expandRegister() {
  278. if (this.qrCodeInvalid) {
  279. uni.showModal({
  280. title: '温馨提示',
  281. content: ' 当前二维码已过期,请重新扫码',
  282. showCancel: false,
  283. success: function (res) {
  284. if (res.confirm) {
  285. console.log('用户点击确定');
  286. } else if (res.cancel) {
  287. console.log('用户点击取消');
  288. }
  289. }
  290. });
  291. return;
  292. }
  293. if (this.requestStatus) {
  294. return
  295. }
  296. this.requestStatus = true
  297. this.rules.idCard = [
  298. {
  299. type: 'string',
  300. required: true,
  301. min: 18,
  302. max: 18,
  303. pattern: this.$idCardPattern,
  304. message: '请输入身份证号',
  305. trigger: ['blur', 'change']
  306. }
  307. ]
  308. this.$refs.uForm.validate().then(res => {
  309. this.idCardAndName().then(res => {
  310. if (res.data.data.respCode !== '0000') {
  311. this.rules.idCard.push({
  312. validator: (a, b, callback) => {
  313. callback(new Error(res.data.data.respMessage));
  314. },
  315. // 触发器可以同时用blur和change
  316. trigger: []
  317. })
  318. this.$refs.uForm.validateField('idCard')
  319. } else {
  320. // 如果校验通过执行注册
  321. uni.showLoading({
  322. title: '正在注册...'
  323. });
  324. this.$api.login.expandRegister(this.form).then(res => {
  325. uni.hideLoading();
  326. uni.showToast({
  327. icon: 'success',
  328. duration: 2000,
  329. title: '注册成功,即将跳转登录页'
  330. });
  331. uni.removeStorageSync('isRegister');
  332. setTimeout(() => {
  333. this.requestStatus = false
  334. this.gologin()
  335. }, 2000)
  336. this.updateScanRecordById()
  337. }).catch(err => {
  338. uni.hideLoading();
  339. this.requestStatus = false
  340. })
  341. }
  342. })
  343. }).catch(err => {
  344. this.requestStatus = false
  345. })
  346. },
  347. logout() {
  348. this.$api.login.logout().then(res => {
  349. uni.clearStorageSync();
  350. uni.navigateTo({
  351. url: '/pages/login/login'
  352. })
  353. })
  354. },
  355. back() {
  356. uni.navigateBack({
  357. delta: 1
  358. });
  359. },
  360. codeChange(text) {
  361. this.tips = text;
  362. },
  363. getCode() {
  364. let regExp = new RegExp(this.$phonePattern);
  365. let b = regExp.test(this.form.phone)
  366. if (!b) {
  367. uni.$u.toast('请输入正确的手机号')
  368. return
  369. }
  370. if (this.$refs.uCode.canGetCode) {
  371. // 模拟向后端请求验证码
  372. uni.showLoading({
  373. title: '正在获取验证码'
  374. })
  375. this.$api.service.getSmsCode({phonenumber: this.form.phone}).then(res => {
  376. uni.hideLoading();
  377. // 这里此提示会被this.start()方法中的提示覆盖
  378. uni.$u.toast('验证码已发送');
  379. // 通知验证码组件内部开始倒计时
  380. this.$refs.uCode.start();
  381. })
  382. } else {
  383. uni.$u.toast('倒计时结束后再发送');
  384. }
  385. },
  386. debounce(fn, delay) {
  387. console.log(delay)
  388. clearTimeout(this.timer);
  389. this.timer = setTimeout(() => {
  390. fn.apply();
  391. }, delay);
  392. }
  393. }
  394. }
  395. </script>
  396. <style lang="scss" scoped>
  397. @import './index.rpx.css';
  398. </style>