information.vue 8.6 KB

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