register.vue 10 KB

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