dataUser.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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" v-if="false">
  68. <view class="button">
  69. 退出账号
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import * as API from '@/apis/pagejs/index.js'
  77. export default {
  78. components: {
  79. },
  80. data() {
  81. return {
  82. userInfo:{
  83. phone:"",
  84. headImg:"",
  85. carNumber:"",
  86. },
  87. showMessage:false,
  88. showCarNumber:false,
  89. carNumber:"",
  90. nickName:"",
  91. abc:false,
  92. customStyle: {
  93. "border-radius": "50px",
  94. "background-color": 'rgba(242, 244, 246, 1)',
  95. padding: "5px 20px",
  96. margin: "5px 0 ",
  97. },
  98. }
  99. },
  100. onLoad() {
  101. this.userInfo = this.jphelp.getPersonInfo()
  102. },
  103. onReady() {
  104. this.$refs.refLogin.findByOpenId()
  105. },
  106. methods: {
  107. carNumberBtn(){
  108. this.showCarNumber=1;
  109. this.carNumber=this.userInfo.carNumber;
  110. if(!this.carNumber){
  111. this.carNumber=""
  112. }
  113. this.valInit(1)
  114. },
  115. valInit(bl){
  116. if(bl){
  117. this.abc=this.carNumber.length>0
  118. }else{
  119. if(this.carNumber.length==1&&this.abc==false){
  120. this.abc=true
  121. }
  122. if(this.carNumber.length==0&&this.abc==true){
  123. this.abc=false
  124. }
  125. }
  126. },
  127. valChange(val){
  128. if(this.carNumber.length>=8){
  129. return
  130. }
  131. this.carNumber+=val
  132. this.valInit()
  133. this.$forceUpdate()
  134. },
  135. backspace(){
  136. //
  137. var value=this.carNumber
  138. if(value.length){
  139. value = value.substr(0, value.length - 1);
  140. }
  141. this.carNumber=value
  142. this.valInit()
  143. },
  144. updateCarNumber(){
  145. this.userInfo.carNumber=this.carNumber
  146. this.showCarNumber=false;
  147. this.updatePersonInformation()
  148. },
  149. updateName(){
  150. if(this.nickName){
  151. this.userInfo.nickName=this.nickName
  152. this.showMessage=false;
  153. this.updatePersonInformation()
  154. }else{
  155. this.showMessage=true;
  156. uni.showToast({
  157. title: "用户昵称不能为空",
  158. icon: "none"
  159. })
  160. }
  161. },
  162. updatePersonInformation(){
  163. uni.showLoading({
  164. title: "加载中",
  165. mask: true,
  166. })
  167. if(!this.userInfo.nickName){
  168. this.userInfo.nickName=""
  169. }
  170. if(!this.userInfo.headImg){
  171. this.userInfo.headImg=""
  172. }
  173. if(!this.userInfo.carNumber){
  174. this.userInfo.carNumber=""
  175. }
  176. var obj={
  177. nickName:this.userInfo.nickName,
  178. headImg:this.userInfo.headImg,
  179. carNumber:this.userInfo.carNumber,
  180. }
  181. API.updatePersonInformation(obj).then((res) => {
  182. uni.hideLoading();
  183. this.$refs.refLogin.findByOpenId()
  184. }).catch(error => {
  185. uni.hideLoading();
  186. uni.showToast({
  187. title: error,
  188. icon: "none"
  189. })
  190. })
  191. },
  192. findByOpenId(res){
  193. this.userInfo = this.jphelp.getPersonInfo()
  194. },
  195. saveRecordConfirmMethod(fileData) {
  196. var token = this.jphelp.getToken()
  197. uni.uploadFile({
  198. url: process.jphelp.BASE_URL + "uploadPicture", //仅为示例,非真实的接口地址
  199. filePath:fileData,
  200. header: {
  201. 'Authorization': token,
  202. //'Content-Type': 'multipart/form-data',
  203. 'X-Requested-With': 'XMLHttpRequest',
  204. // 'content-type': 'multipart/form-data'
  205. },
  206. name: 'photoFile',
  207. formData: {
  208. subFolder: "headimg"
  209. },
  210. success: (uploadFileRes) => {
  211. var obj = JSON.parse(uploadFileRes.data)
  212. //.log(obj);
  213. //this.src = obj.data;
  214. this.userInfo.headImg=obj.data;
  215. this.updatePersonInformation();
  216. // uni.hideLoading();
  217. }
  218. });
  219. },
  220. uploadPhoto() {
  221. let _self = this;
  222. const crop = {
  223. quality: 100,
  224. width: 600,
  225. height: 600,
  226. resize: true
  227. };
  228. // 上传图片
  229. uni.chooseImage({
  230. count: 1,
  231. crop,
  232. success: async (res) => {
  233. //(res);
  234. let tempFile = res.tempFiles[0];
  235. var filePath = res.tempFilePaths[0]
  236. let fileData = await new Promise((callback) => {
  237. uni.navigateTo({
  238. url: './cropImage?path=' + filePath +
  239. `&options=${JSON.stringify(crop)}`,
  240. animationType: "fade-in",
  241. events: {
  242. success: url => {
  243. callback(url)
  244. }
  245. }
  246. });
  247. })
  248. this.saveRecordConfirmMethod(fileData);
  249. }
  250. });
  251. },
  252. }
  253. }
  254. </script>
  255. <style>
  256. page {
  257. background-color: rgba(242, 244, 246, 1);
  258. }
  259. </style>
  260. <style scoped lang="scss">
  261. /* styles.css */
  262. .showMessage{
  263. padding: 40rpx 40rpx 60rpx 40rpx;
  264. .carNumber {
  265. background-color: #F2F4F6;
  266. padding: 5px 20px;
  267. margin: 5px 0 15px 0;
  268. height: 90rpx;
  269. display: flex;
  270. align-items: center;
  271. border-radius: 50px;
  272. }
  273. .carNumber1{
  274. color: #bcbcbc;
  275. }
  276. .title{
  277. color: rgba(16,16,16,1);
  278. font-size: 36rpx;
  279. margin-top: 32rpx;
  280. font-weight: bold;
  281. }
  282. .body{
  283. color: rgba(16,16,16,1);
  284. font-size: 32rpx;
  285. padding-bottom: 66rpx;
  286. }
  287. .botton{
  288. display: flex;
  289. justify-content: space-between;
  290. }
  291. }
  292. .body {
  293. padding: 32rpx;
  294. }
  295. .page {
  296. border-radius: 16rpx;
  297. background-color: rgba(255, 255, 255, 1);
  298. color: rgba(16, 16, 16, 1);
  299. padding:0 32rpx;
  300. margin-bottom: 32rpx;
  301. font-size: 32rpx;
  302. color: rgb(16, 16, 16);
  303. .page-content {
  304. .item:not(:last-child) {
  305. border-bottom:1px solid rgba(232,232,232,1);
  306. }
  307. .item {
  308. padding: 32rpx 0;
  309. display: flex;
  310. justify-content: space-between;
  311. align-items: center;
  312. font-size: 32rpx;
  313. .title {
  314. display: flex;
  315. justify-content: space-between;
  316. display: flex;
  317. align-items: center;
  318. color: rgba(51,51,51,1);
  319. }
  320. .goto{
  321. display: flex;
  322. align-items: center;
  323. color: rgba(119,119,119,1);
  324. }
  325. .photo {
  326. border-radius: 50px;
  327. background-color: rgba(229, 229, 229, 1);
  328. height: 80rpx;
  329. width: 80rpx;
  330. overflow: hidden;
  331. .img {
  332. width: 100%;
  333. height: 100%;
  334. }
  335. }
  336. }
  337. }
  338. .button{
  339. text-align: center;
  340. color: red;
  341. padding: 32rpx 0;
  342. }
  343. }
  344. </style>