index.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import React,{Component} from "react";
  2. import {Button, View} from '@tarojs/components'
  3. import Taro from "@tarojs/taro";
  4. import { AtIcon } from 'taro-ui'
  5. import "taro-ui/dist/style/components/icon.scss";
  6. import { setDecryptData } from '../../../utils/servers/servers';
  7. import './index.less';
  8. class PhoneWarrantMore extends Component{
  9. constructor(props) {
  10. super(props);
  11. this.setDecryptData = this.setDecryptData.bind(this);
  12. }
  13. async setDecryptData(data){
  14. Taro.showLoading({title:'正在努力绑定中...'})
  15. let msg = await setDecryptData({
  16. encryptedData : data.encryptedData,
  17. iv : data.iv
  18. });
  19. if(msg.error && msg.error.length !== 0){
  20. Taro.showToast({title:msg.error[0].message,icon:'none'});
  21. Taro.hideLoading();
  22. return;
  23. }
  24. if(msg.phoneNumber){
  25. let userInfor = Taro.getStorageSync('userInfor');
  26. userInfor.mobile = msg.phoneNumber;
  27. Taro.setStorageSync('userInfor', userInfor);
  28. Taro.showToast({
  29. title:'绑定成功',
  30. icon:'success'
  31. });
  32. this.props.onClose();
  33. }else{
  34. Taro.showToast({
  35. title:'绑定失败',
  36. icon:'error'
  37. });
  38. }
  39. Taro.hideLoading();
  40. }
  41. render() {
  42. return(
  43. <>
  44. {
  45. this.props.visible ? <View className='phoneWarrantMore' onClick={(e)=>{
  46. e.stopPropagation();
  47. this.props.onClose();
  48. }}>
  49. <View className='content' onClick={(e)=>{
  50. e.stopPropagation();
  51. }}>
  52. <View className='close' onClick={(e)=>{
  53. e.stopPropagation();
  54. this.props.onClose();
  55. }}>
  56. <AtIcon value='close' size='20' />
  57. </View>
  58. <View className='phone'>
  59. <AtIcon value='phone' size='40' color='#24f121'/>
  60. </View>
  61. <View className='title'>绑定手机号授权</View>
  62. <View className='introduction'>绑定手机号后,我们能更好的为您服务</View>
  63. <Button className='phoneButton' type='primary' openType='getPhoneNumber' onGetphonenumber={(v)=>{
  64. if(v.detail.encryptedData){
  65. this.setDecryptData(v.detail)
  66. }
  67. }}>
  68. 绑定手机号
  69. </Button>
  70. </View>
  71. </View> : <View/>
  72. }
  73. </>
  74. );
  75. }
  76. }
  77. export default PhoneWarrantMore;