register.vue 16 KB

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