register.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // pages/tasks/tasks.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber,formatEncrypt } from '../../utils/util.js'
  3. import { Register, LibList, MyInfo,GetVerificationCode,BindPhone,RegisterV2,CheckStatus} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp();
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. hiddenModel:false,
  14. isLook: false,
  15. phone:'',
  16. curatorName: '',
  17. libId: '',
  18. areaIndex:0,
  19. libIndex:0,
  20. isBtn:1,
  21. isPhone:0,
  22. times:60,
  23. tips:'获取验证码',
  24. isCode:true,
  25. code:'',
  26. cityList: [
  27. // {
  28. // city: "广州",
  29. // libList: [
  30. // {
  31. // libId: "dahioubrbiuwnirtbirwubribsbfgb",
  32. // libName: "私塾家星伯乐共享图书馆GZ151safsa",
  33. // status:''
  34. // },
  35. // {
  36. // libId: "dahioubrbiuwnirtbirwubribsbfgb",
  37. // libName: "私塾家星伯乐共享图书馆GZ15144",
  38. // status: ''
  39. // },
  40. // {
  41. // libId: "dahioubrbiuwnirtbirwubribsbfgb",
  42. // libName: "私塾家星伯乐共享图书馆GZ151",
  43. // status: ''
  44. // },
  45. // ]
  46. // },
  47. // {
  48. // city: "深圳",
  49. // libList: [
  50. // {
  51. // libId: "dahioubrbiuwnirtbirwubribsbfgb",
  52. // libName: "私塾家星伯乐共享图书馆GZ151444",
  53. // status: ''
  54. // }
  55. // ]
  56. // },
  57. // {
  58. // city: "佛山",
  59. // libList: [
  60. // {
  61. // libId: "dahioubrbiuwnirtbirwubribsbfgb",
  62. // libName: "私塾家星伯乐共享图书馆GZ151222",
  63. // status: 'active'
  64. // }
  65. // ]
  66. // },
  67. ]
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad: function (options) {
  73. // console.log(options)
  74. this.setData(options);
  75. const userInfo = wx.getStorageSync('userInfo')
  76. this.setData({ userInfo});
  77. const {isBtn,phone,isSlect} = options
  78. if (isBtn==0){
  79. this.getInfo();
  80. }
  81. this.checkStatus()
  82. },
  83. /**
  84. * 生命周期函数--监听页面初次渲染完成
  85. */
  86. onReady: function () {
  87. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  88. for (const i in obj) {
  89. this[i] = obj[i]
  90. }
  91. },
  92. /**
  93. * 生命周期函数--监听页面显示
  94. */
  95. onShow: function () {
  96. // this.getLibList();
  97. },
  98. /**
  99. * 生命周期函数--监听页面隐藏
  100. */
  101. onHide: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面卸载
  105. */
  106. onUnload: function () {
  107. },
  108. /**
  109. * 页面相关事件处理函数--监听用户下拉动作
  110. */
  111. onPullDownRefresh: function () {
  112. },
  113. /**
  114. * 页面上拉触底事件的处理函数
  115. */
  116. onReachBottom: function () {
  117. },
  118. /**
  119. * 用户点击右上角分享
  120. */
  121. onShareAppMessage: function () {
  122. if (app.sharePageDefaultCtl) {
  123. return app.sharePageDefaultCtl()
  124. }
  125. },
  126. //查看图片
  127. viewImageCtl: app.viewImageCtl,
  128. /**
  129. * 跳转
  130. */
  131. navigateCtl: app.navigateCtl,
  132. /**
  133. * 底部导航跳转
  134. */
  135. redirectCtl: app.redirectCtl,
  136. /**
  137. * 提示框隐藏
  138. */
  139. allShowModel: function () {
  140. this.setData({ hiddenModel: false })
  141. },
  142. /**
  143. * 选择地区
  144. */
  145. selectArea: function () {
  146. console.log('55555')
  147. this.setData({ hiddenModel: true})
  148. },
  149. /**
  150. * 选择城市
  151. */
  152. selectCity:function(e){
  153. const { index } = e.currentTarget.dataset;
  154. this.setData({ areaIndex: index })
  155. },
  156. /**
  157. * 选择馆名
  158. */
  159. setLibName:function(e){
  160. const { item,idx } = e.currentTarget.dataset;
  161. const { libId, libName}=item;
  162. const { areaIndex, libIndex,cityList } = this.data;
  163. console.log(areaIndex, libIndex, cityList)
  164. var temp = {};
  165. for (var i in cityList) {
  166. for (var j in cityList[i].libList) {
  167. temp[`cityList[${i}].libList[${j}].status`] = ''
  168. }
  169. }
  170. temp[`cityList[${areaIndex}].libList[${idx}].status`] = cityList[areaIndex].libList[idx].status == '' ? 'active' : '';
  171. this.setData(temp)
  172. console.log(cityList)
  173. this.setData({ libId, libName,hiddenModel: false,libIndex:idx })
  174. },
  175. /**
  176. * 上传头像
  177. */
  178. uploadHeadIconCtl: function () {
  179. wx.chooseImage({
  180. count: 1,
  181. success: res => {
  182. this.uploadImage(res.tempFilePaths[0])
  183. },
  184. fail: res => {
  185. wx.showToast({
  186. title: '选择拍照或者相册失败',
  187. icon: 'none'
  188. })
  189. }
  190. })
  191. },
  192. /**
  193. * 上传头像接口
  194. */
  195. uploadImage: function (file) {
  196. app.uploadFile('/api/common/common/uploadForm', file, {}).then(res => {
  197. let { filePath } = JSON.parse(res).data.pics[0];
  198. console.log(filePath);
  199. this.setData({ imgUrl: filePath })
  200. })
  201. },
  202. /**
  203. * input
  204. */
  205. inputCtl: function (e) {
  206. const mobileExp = /^1[0-9]{10}$/;
  207. const { temp = {}, type } = e.currentTarget.dataset
  208. const { value } = e.detail
  209. temp[type] = value;
  210. const { curatorName, phone,code} = temp;
  211. // console.log(phone)
  212. if (type == 'phone') {
  213. this.setData({ phone })
  214. // if (value != '') {
  215. // if (!mobileExp.test(value)) {
  216. // wx.showToast({
  217. // title: '手机号码位数不对',
  218. // icon: 'none',
  219. // duration: 2000
  220. // })
  221. // return this.setData({ phone })
  222. // } else {
  223. // return this.setData({ phone })
  224. // }
  225. // }
  226. } else if (type == 'curatorName') {
  227. return this.setData({ curatorName })
  228. } else if(type == 'code'){
  229. this.setData({ code })
  230. }
  231. },
  232. /**
  233. * 点击馆
  234. */
  235. getLibList:function(cb){
  236. const continuousFn = { fn: this.getLibList, param: { ...arguments } }
  237. const { areaIndex,libIndex}=this.data;
  238. LibList({ data: {}, continuousFn }).then(res => {
  239. const { cityList}=res.data;
  240. var temp = {};
  241. for (var i in cityList) {
  242. for (var j in cityList[i].libList){
  243. temp[`cityList[${i}].libList[${j}].libId`] = cityList[i].libList[j].libId
  244. temp[`cityList[${i}].libList[${j}].libName`] = cityList[i].libList[j].libName
  245. temp[`cityList[${i}].city`] = cityList[i].city
  246. temp[`cityList[${i}].libList[${j}].status`] = ''
  247. }
  248. }
  249. this.setData(temp)
  250. if (isFn(cb)) cb()
  251. }).catch(res => {
  252. if (isFn(cb)) cb()
  253. })
  254. },
  255. /**
  256. * 提交数据
  257. */
  258. getData: function (cb) {
  259. const mobileExp = /^1[0-9]{10}$/;
  260. const continuousFn = { fn: this.getData, param: { ...arguments } }
  261. const { phone, curatorName, libId,code} = this.data;
  262. console.log(phone, curatorName, libId,code)
  263. if (!curatorName) {
  264. wx.showToast({
  265. title: '请输入姓名',
  266. icon: 'none'
  267. })
  268. return
  269. }
  270. if (!mobileExp.test(phone)) {
  271. wx.showToast({
  272. title: '手机号码位数不对',
  273. icon: 'none',
  274. duration: 2000
  275. })
  276. return
  277. } else if (!phone) {
  278. wx.showToast({
  279. title: '手机号不能为空',
  280. icon: 'none',
  281. duration: 2000
  282. })
  283. return
  284. }
  285. if (!code) {
  286. wx.showToast({
  287. title: '请输入验证码',
  288. icon: 'none'
  289. })
  290. return
  291. }
  292. if (!libId) {
  293. wx.showToast({
  294. title: '请选择馆',
  295. icon: 'none'
  296. })
  297. return
  298. }
  299. // console.log(phone, curatorName, libId)
  300. RegisterV2({ data: { phone:formatEncrypt(phone), curatorName:formatEncrypt(curatorName), libId,vCode:formatEncrypt(code)}, continuousFn }).then(res => {
  301. if (libId =='6b308989-0988-45a0-853d-537a923ba2e7'){
  302. this.redirectCtl({ url: 'child_list', method: {} }, true)
  303. }else{
  304. this.redirectCtl({ url: 'check_status', method: { isCheck: 1, curatorName } }, true)
  305. }
  306. if (isFn(cb)) cb()
  307. }).catch(res => {
  308. this.setData({ isLoaded: true })
  309. if (isFn(cb)) cb()
  310. })
  311. },
  312. /**
  313. * 审核结果
  314. * */
  315. checkStatus: function () {
  316. const continuousFn = { fn: this.checkStatus, param: { ...arguments } }
  317. CheckStatus({ data: {},continuousFn}).then(res => {
  318. const {phone} = res.data
  319. if(phone){
  320. this.setData({ isCode:false});
  321. }
  322. })
  323. },
  324. /**
  325. * 获取数据
  326. */
  327. getInfo: function (cb) {
  328. const continuousFn = { fn: this.getInfo, param: { ...arguments } }
  329. const { isType } = this.data;
  330. MyInfo({ data: { type:isType}, continuousFn }).then(res => {
  331. const { curatorName, phone, libId, libName } = res.data;
  332. this.setData({ curatorName, phone, libId, libName })
  333. if (isFn(cb)) cb()
  334. }).catch(res => {
  335. this.setData({ isLoaded: true })
  336. if (isFn(cb)) cb()
  337. })
  338. },
  339. /**
  340. * 绑定手机号
  341. */
  342. bindCuratorPhone: function (cb) {
  343. const continuousFn = { fn: this.bindCuratorPhone, param: { ...arguments } }
  344. const { code,phone } = this.data;
  345. const mobileExp = /^1[0-9]{10}$/;
  346. if (!mobileExp.test(phone)) {
  347. wx.showToast({
  348. title: '手机号码位数不对',
  349. icon: 'none',
  350. duration: 2000
  351. })
  352. return
  353. } else if (!phone) {
  354. wx.showToast({
  355. title: '手机号不能为空',
  356. icon: 'none',
  357. duration: 2000
  358. })
  359. return
  360. }
  361. if (!code) {
  362. wx.showToast({
  363. title: '请输入验证码',
  364. icon: 'none'
  365. })
  366. return
  367. }
  368. BindPhone({ data: { vCode:formatEncrypt(code),phone:formatEncrypt(phone)}, continuousFn }).then(res => {
  369. wx.showToast({
  370. title: '绑定成功',
  371. duration: 1000
  372. })
  373. this.redirectCtl({ url: 'main', method: {} }, true)
  374. if (isFn(cb)) cb()
  375. }).catch(res => {
  376. if (isFn(cb)) cb()
  377. })
  378. },
  379. /**
  380. * 再次获取验证码
  381. */
  382. setStime:function(){
  383. const mobileExp = /^1[0-9]{10}$/;
  384. const { times, phone}=this.data;
  385. // console.log(phone)
  386. if (!phone) {
  387. wx.showToast({
  388. title: '手机号码不能为空',
  389. icon: 'none'
  390. })
  391. return
  392. } else if (!mobileExp.test(phone)) {
  393. wx.showToast({
  394. title: '手机号码位数不对',
  395. icon: 'none',
  396. duration: 1000
  397. })
  398. return
  399. }
  400. if (times == 60 || times ==0){
  401. this.getPhoneCode()
  402. }
  403. if(times>0){
  404. this.startSetInter()
  405. }else if(times==0){
  406. this.setData({times:60})
  407. this.startSetInter()
  408. }
  409. },
  410. /**
  411. * 开始计时
  412. */
  413. startSetInter: function () {
  414. var that = this;
  415. const {phone, tips, times} = that.data;
  416. // console.log(phone, tips, times)
  417. if (times == 0) {
  418. that.setData({ tips: "获取验证码"});
  419. return ;
  420. } else {
  421. var numVal =that.data.times--;
  422. that.setData({ tips: "重新发送(" + numVal + ")"});
  423. }
  424. this.myTime=setTimeout(function () {
  425. that.startSetInter();
  426. }, 1000);
  427. },
  428. /**
  429. * 获取手机验证码(加密)
  430. */
  431. getPhoneCode: function (cb) {
  432. const continuousFn = { fn: this.getPhoneCode, param: { ...arguments } }
  433. const { phone } = this.data;
  434. console.log(phone)
  435. GetVerificationCode({ data: { phone:formatEncrypt(phone)}, continuousFn }).then(res => {
  436. if (isFn(cb)) cb()
  437. }).catch(res => {
  438. if (isFn(cb)) cb()
  439. })
  440. }
  441. })