dataUser.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="jpmain ">
  3. <u-navbar title="个人信息" title-color="#101010"></u-navbar>
  4. <u-popup v-model="showMessage" mode="bottom" border-radius="30" >
  5. <view class="showMessage">
  6. <view class="title">用户昵称</view>
  7. <view class="body">
  8. <u-input :customStyle="customStyle"
  9. placeholder="请填写用户昵称"
  10. v-model="nickName"></u-input>
  11. </view>
  12. <view class="botton">
  13. <u-button @click="showMessage=false" style="width: 35%;" shape="square" >取消</u-button>
  14. <u-button @click="updateName" style="width: 60%;" type="primary" shape="square" >确认</u-button>
  15. </view>
  16. </view>
  17. </u-popup>
  18. <u-keyboard ref="uKeyboard" @change="valChange" @backspace="backspace"
  19. :tips="carNumber?carNumber:'请输入车牌号'" @confirm="updateCarNumber()"
  20. mode="car" v-model="showCarNumber" :abc="abc" ></u-keyboard>
  21. <view class="body">
  22. <view class="page">
  23. <view class="page-content">
  24. <view class="item">
  25. <view class="title">
  26. 头像
  27. </view>
  28. <view class="goto " @click="uploadPhoto" >
  29. <view class="photo">
  30. <img class="img" :src="userInfo.headImg" v-if="userInfo.headImg" alt="">
  31. </view>
  32. <u-icon name="arrow-right" style="margin-left: 8rpx;" size="24" color="#BBBBBB"></u-icon>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="page">
  38. <view class="page-content">
  39. <!-- <view class="item">
  40. <view class="title">
  41. 用户昵称
  42. </view>
  43. <view class="goto" @click="showMessage=true,nickName=userInfo.nickName">
  44. {{userInfo.nickName?userInfo.nickName:'未设置'}}
  45. <u-icon name="arrow-right" style="margin-left: 8rpx;" size="24" color="#BBBBBB"></u-icon>
  46. </view>
  47. </view> -->
  48. <view class="item">
  49. <view class="title">
  50. 车牌号
  51. </view>
  52. <view class="goto" @click="carNumberBtn">
  53. {{userInfo.carNumber?userInfo.carNumber:'未设置'}}
  54. <u-icon name="arrow-right" style="margin-left: 8rpx;" size="24" color="#BBBBBB"></u-icon>
  55. </view>
  56. </view>
  57. <!-- <view class="item">
  58. <view class="title">
  59. 手机号码
  60. </view>
  61. <view class="goto">
  62. {{userInfo.phone}}
  63. </view>
  64. </view> -->
  65. </view>
  66. </view>
  67. <view class="page" @click="signOut">
  68. <view class="button">
  69. 退出账号
  70. </view>
  71. </view>
  72. <u-modal v-model="show1" @confirm="confirm" confirm-color="#FF3D00" :show-cancel-button="true" ref="uModal"
  73. :asyncClose="true" title="退出账号" content="是否退出当前账号?" :content-style="{color: '#333333'}"></u-modal>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import * as API from '@/apis/pagejs/index.js'
  79. export default {
  80. components: {
  81. },
  82. data() {
  83. return {
  84. userInfo:{
  85. phone:"",
  86. headImg:"",
  87. carNumber:"",
  88. },
  89. showMessage:false,
  90. showCarNumber:false,
  91. carNumber:"",
  92. nickName:"",
  93. abc:false,
  94. show1:false,
  95. customStyle: {
  96. "border-radius": "50px",
  97. "background-color": 'rgba(242, 244, 246, 1)',
  98. padding: "5px 20px",
  99. margin: "5px 0 ",
  100. },
  101. }
  102. },
  103. onLoad() {
  104. this.userInfo = this.jphelp.getPersonInfo()
  105. },
  106. onReady() {
  107. this.$refs.refLogin.findByOpenId()
  108. },
  109. methods: {
  110. signOut() {
  111. this.show1 = true;
  112. },
  113. confirm() {
  114. uni.showLoading({
  115. title: "加载中",
  116. mask: true,
  117. })
  118. userApi.logout().then((res) => {
  119. uni.hideLoading();
  120. this.show1 = false;
  121. this.jphelp.logoff()
  122. uni.redirectTo({
  123. url: '/pages/login/login'
  124. })
  125. }).catch(error => {
  126. uni.showToast({
  127. title: error,
  128. icon: "none"
  129. })
  130. })
  131. },
  132. carNumberBtn(){
  133. this.showCarNumber=1;
  134. this.carNumber=this.userInfo.carNumber;
  135. if(!this.carNumber){
  136. this.carNumber=""
  137. }
  138. this.valInit(1)
  139. },
  140. valInit(bl){
  141. if(bl){
  142. this.abc=this.carNumber.length>0
  143. }else{
  144. if(this.carNumber.length==1&&this.abc==false){
  145. this.abc=true
  146. }
  147. if(this.carNumber.length==0&&this.abc==true){
  148. this.abc=false
  149. }
  150. }
  151. },
  152. valChange(val){
  153. if(this.carNumber.length>=8){
  154. return
  155. }
  156. this.carNumber+=val
  157. this.valInit()
  158. this.$forceUpdate()
  159. },
  160. backspace(){
  161. //
  162. var value=this.carNumber
  163. if(value.length){
  164. value = value.substr(0, value.length - 1);
  165. }
  166. this.carNumber=value
  167. this.valInit()
  168. },
  169. updateCarNumber(){
  170. this.userInfo.carNumber=this.carNumber
  171. this.showCarNumber=false;
  172. this.updatePersonInformation()
  173. },
  174. updateName(){
  175. if(this.nickName){
  176. this.userInfo.nickName=this.nickName
  177. this.showMessage=false;
  178. this.updatePersonInformation()
  179. }else{
  180. this.showMessage=true;
  181. uni.showToast({
  182. title: "用户昵称不能为空",
  183. icon: "none"
  184. })
  185. }
  186. },
  187. updatePersonInformation(){
  188. uni.showLoading({
  189. title: "加载中",
  190. mask: true,
  191. })
  192. if(!this.userInfo.nickName){
  193. this.userInfo.nickName=""
  194. }
  195. if(!this.userInfo.headImg){
  196. this.userInfo.headImg=""
  197. }
  198. if(!this.userInfo.carNumber){
  199. this.userInfo.carNumber=""
  200. }
  201. var obj={
  202. nickName:this.userInfo.nickName,
  203. headImg:this.userInfo.headImg,
  204. carNumber:this.userInfo.carNumber,
  205. }
  206. API.updatePersonInformation(obj).then((res) => {
  207. uni.hideLoading();
  208. this.$refs.refLogin.findByOpenId()
  209. }).catch(error => {
  210. uni.hideLoading();
  211. uni.showToast({
  212. title: error,
  213. icon: "none"
  214. })
  215. })
  216. },
  217. findByOpenId(res){
  218. this.userInfo = this.jphelp.getPersonInfo()
  219. },
  220. saveRecordConfirmMethod(fileData) {
  221. var token = this.jphelp.getToken()
  222. uni.uploadFile({
  223. url: process.jphelp.BASE_URL + "uploadPicture", //仅为示例,非真实的接口地址
  224. filePath:fileData,
  225. header: {
  226. 'Authorization': token,
  227. //'Content-Type': 'multipart/form-data',
  228. 'X-Requested-With': 'XMLHttpRequest',
  229. // 'content-type': 'multipart/form-data'
  230. },
  231. name: 'photoFile',
  232. formData: {
  233. subFolder: "headimg"
  234. },
  235. success: (uploadFileRes) => {
  236. var obj = JSON.parse(uploadFileRes.data)
  237. //.log(obj);
  238. //this.src = obj.data;
  239. this.userInfo.headImg=obj.data;
  240. this.updatePersonInformation();
  241. // uni.hideLoading();
  242. }
  243. });
  244. },
  245. uploadPhoto() {
  246. let _self = this;
  247. const crop = {
  248. quality: 100,
  249. width: 600,
  250. height: 600,
  251. resize: true
  252. };
  253. // 上传图片
  254. uni.chooseImage({
  255. count: 1,
  256. crop,
  257. success: async (res) => {
  258. //(res);
  259. let tempFile = res.tempFiles[0];
  260. var filePath = res.tempFilePaths[0]
  261. let fileData = await new Promise((callback) => {
  262. uni.navigateTo({
  263. url: './cropImage?path=' + filePath +
  264. `&options=${JSON.stringify(crop)}`,
  265. animationType: "fade-in",
  266. events: {
  267. success: url => {
  268. callback(url)
  269. }
  270. }
  271. });
  272. })
  273. this.saveRecordConfirmMethod(fileData);
  274. }
  275. });
  276. },
  277. }
  278. }
  279. </script>
  280. <style>
  281. page {
  282. background-color: rgba(242, 244, 246, 1);
  283. }
  284. </style>
  285. <style scoped lang="scss">
  286. /* styles.css */
  287. .showMessage{
  288. padding: 40rpx 40rpx 60rpx 40rpx;
  289. .carNumber {
  290. background-color: #F2F4F6;
  291. padding: 5px 20px;
  292. margin: 5px 0 15px 0;
  293. height: 90rpx;
  294. display: flex;
  295. align-items: center;
  296. border-radius: 50px;
  297. }
  298. .carNumber1{
  299. color: #bcbcbc;
  300. }
  301. .title{
  302. color: rgba(16,16,16,1);
  303. font-size: 36rpx;
  304. margin-top: 32rpx;
  305. font-weight: bold;
  306. }
  307. .body{
  308. color: rgba(16,16,16,1);
  309. font-size: 32rpx;
  310. padding-bottom: 66rpx;
  311. }
  312. .botton{
  313. display: flex;
  314. justify-content: space-between;
  315. }
  316. }
  317. .body {
  318. padding: 32rpx;
  319. }
  320. .page {
  321. border-radius: 16rpx;
  322. background-color: rgba(255, 255, 255, 1);
  323. color: rgba(16, 16, 16, 1);
  324. padding:0 32rpx;
  325. margin-bottom: 32rpx;
  326. font-size: 32rpx;
  327. color: rgb(16, 16, 16);
  328. .page-content {
  329. .item:not(:last-child) {
  330. border-bottom:1px solid rgba(232,232,232,1);
  331. }
  332. .item {
  333. padding: 32rpx 0;
  334. display: flex;
  335. justify-content: space-between;
  336. align-items: center;
  337. font-size: 32rpx;
  338. .title {
  339. display: flex;
  340. justify-content: space-between;
  341. display: flex;
  342. align-items: center;
  343. color: rgba(51,51,51,1);
  344. }
  345. .goto{
  346. display: flex;
  347. align-items: center;
  348. color: rgba(119,119,119,1);
  349. }
  350. .photo {
  351. border-radius: 50px;
  352. background-color: rgba(229, 229, 229, 1);
  353. height: 80rpx;
  354. width: 80rpx;
  355. overflow: hidden;
  356. .img {
  357. width: 100%;
  358. height: 100%;
  359. }
  360. }
  361. }
  362. }
  363. .button{
  364. text-align: center;
  365. color: red;
  366. padding: 32rpx 0;
  367. }
  368. }
  369. </style>