information.vue 8.0 KB

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