c-userinfo.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="container">
  3. <view class="ui-all">
  4. <view class="avatar" @tap="avatarChoose">
  5. <view class="imgAvatar">
  6. <view class="iavatar" :style="'background: url('+avater+') no-repeat center/cover #eeeeee;'"></view>
  7. </view>
  8. <text v-if="avater">修改头像</text>
  9. <text v-if="!avater">授权微信</text>
  10. <button v-if="!avater" open-type="getUserInfo" @tap="getUserInfo" class="getInfo"></button>
  11. </view>
  12. <view class="ui-list">
  13. <text>昵称</text>
  14. <input type="text" :placeholder="value" :value="nickName" @input="bindnickName" placeholder-class="place" />
  15. </view>
  16. <view class="ui-list">
  17. <text>手机号</text>
  18. <input v-if="mobile" type="tel" :placeholder="value" :value="mobile" @input="bindmobile" placeholder-class="place" />
  19. <button v-if="!mobile" open-type="getPhoneNumber" @getphonenumber="getphonenumber" class="getInfo bun">授权手机号</button>
  20. </view>
  21. <view class="ui-list right">
  22. <text>性别</text>
  23. <picker @change="bindPickerChange" mode='selector' range-key="name" :value="index" :range="sex">
  24. <view class="picker">
  25. {{sex[index].name}}
  26. </view>
  27. </picker>
  28. </view>
  29. <view class="ui-list right">
  30. <text>常住地</text>
  31. <picker @change="bindRegionChange" mode='region'>
  32. <view class="picker">
  33. {{region[0]}} {{region[1]}} {{region[2]}}
  34. </view>
  35. </picker>
  36. </view>
  37. <view class="ui-list right">
  38. <text>生日</text>
  39. <picker mode="date" :value="date" @change="bindDateChange">
  40. <view class="picker">
  41. {{date}}
  42. </view>
  43. </picker>
  44. </view>
  45. <view class="ui-list">
  46. <text>签名</text>
  47. <textarea :placeholder="value" placeholder-class="place" :value="description" @input="binddescription"></textarea>
  48. </view>
  49. <button class="save" @tap="savaInfo">保 存 修 改</button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. export default {
  55. data() {
  56. return {
  57. value: '请填写',
  58. sex: [{
  59. id: 1,
  60. name: '男'
  61. }, {
  62. id: 2,
  63. name: '女'
  64. }],
  65. index: 0,
  66. region: ['请填写'],
  67. date: '请填写',
  68. avater: '',
  69. description: '',
  70. url: '',
  71. nickName: '',
  72. mobile: '',
  73. headimg: ''
  74. }
  75. },
  76. methods: {
  77. bindPickerChange(e) {
  78. this.index = e.detail.value;
  79. },
  80. bindRegionChange(e) {
  81. this.region = e.detail.value;
  82. },
  83. bindDateChange(e) {
  84. this.date = e.detail.value;
  85. },
  86. bindnickName(e) {
  87. this.nickName = e.detail.value;
  88. },
  89. bindmobile(e) {
  90. this.mobile = e.detail.value;
  91. },
  92. binddescription(e) {
  93. this.description = e.detail.value;
  94. },
  95. avatarChoose() {
  96. let that = this;
  97. uni.chooseImage({
  98. count: 1,
  99. sizeType: ['original', 'compressed'],
  100. sourceType: ['album', 'camera'],
  101. success(res) {
  102. // tempFilePath可以作为img标签的src属性显示图片
  103. that.imgUpload(res.tempFilePaths);
  104. const tempFilePaths = res.tempFilePaths;
  105. }
  106. });
  107. },
  108. getUserInfo () {
  109. uni.getUserProfile({
  110. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  111. success: (res) => {
  112. console.log(res);
  113. uni.showToast({
  114. title: '已授权',
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. }
  119. })
  120. } ,
  121. getphonenumber(e){
  122. if(e.detail.iv){
  123. console.log(e.detail.iv) //传后台解密换取手机号
  124. uni.showToast({
  125. title: '已授权',
  126. icon: 'none',
  127. duration: 2000
  128. })
  129. }
  130. },
  131. savaInfo() {
  132. let that = this;
  133. let nickname = that.nickName;
  134. let headimg = that.headimg;
  135. let gender = that.index + 1;
  136. let mobile = that.mobile;
  137. let region = that.region;
  138. let birthday = that.date;
  139. let description = that.description;
  140. let updata = {};
  141. if (!nickname) {
  142. uni.showToast({
  143. title: '请填写昵称',
  144. icon: 'none',
  145. duration: 2000
  146. });
  147. return;
  148. }
  149. updata.nickname = nickname;
  150. if (!headimg) {
  151. headimg = that.avater;
  152. }
  153. updata.headimg = headimg;
  154. updata.gender = gender;
  155. if (that.isPoneAvailable(mobile)) {
  156. updata.mobile = mobile;
  157. } else {
  158. uni.showToast({
  159. title: '手机号码有误,请重填',
  160. icon: 'none',
  161. duration: 2000
  162. });
  163. return;
  164. }
  165. if (region.length == 1) {
  166. uni.showToast({
  167. title: '请选择常住地',
  168. icon: 'none',
  169. duration: 2000
  170. });
  171. return;
  172. } else {
  173. updata.province = region[0];
  174. updata.city = region[1];
  175. updata.area = region[2];
  176. }
  177. if (birthday == "0000-00-00") {
  178. uni.showToast({
  179. title: '请选择生日',
  180. icon: 'none',
  181. duration: 2000
  182. });
  183. return;
  184. }
  185. updata.birthday = birthday;
  186. updata.description = description;
  187. that.updata(updata);
  188. },
  189. isPoneAvailable(poneInput) {
  190. var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  191. if (!myreg.test(poneInput)) {
  192. return false;
  193. } else {
  194. return true;
  195. }
  196. },
  197. async updata(datas) {
  198. //传后台
  199. },
  200. imgUpload(file) {
  201. let that = this;
  202. uni.uploadFile({
  203. header: {
  204. Authorization: uni.getStorageSync('token')
  205. },
  206. url:'/api/upload/image', //需传后台图片上传接口
  207. filePath: file[0],
  208. name: 'file',
  209. formData: {
  210. type: 'user_headimg'
  211. },
  212. success: function(res) {
  213. var data = JSON.parse(res.data);
  214. data = data.data;
  215. that.avater = that.url + data.img;
  216. that.headimg = that.url + data.img;
  217. },
  218. fail: function(error) {
  219. console.log(error);
  220. }
  221. });
  222. },
  223. },
  224. onLoad() {
  225. }
  226. }
  227. </script>
  228. <style lang="less">
  229. .container {
  230. display: block;
  231. }
  232. .ui-all {
  233. padding: 20rpx 40rpx;
  234. .avatar {
  235. width: 100%;
  236. text-align: left;
  237. padding: 20rpx 0;
  238. border-bottom: solid 1px #f2f2f2;
  239. position: relative;
  240. .imgAvatar {
  241. width: 140rpx;
  242. height: 140rpx;
  243. border-radius: 50%;
  244. display: inline-block;
  245. vertical-align: middle;
  246. overflow: hidden;
  247. .iavatar {
  248. width: 100%;
  249. height: 100%;
  250. display: block;
  251. }
  252. }
  253. text {
  254. display: inline-block;
  255. vertical-align: middle;
  256. color: #8e8e93;
  257. font-size: 28rpx;
  258. margin-left: 40rpx;
  259. }
  260. &:after {
  261. content: ' ';
  262. width: 20rpx;
  263. height: 20rpx;
  264. border-top: solid 1px #030303;
  265. border-right: solid 1px #030303;
  266. transform: rotate(45deg);
  267. -ms-transform: rotate(45deg);
  268. /* IE 9 */
  269. -moz-transform: rotate(45deg);
  270. /* Firefox */
  271. -webkit-transform: rotate(45deg);
  272. /* Safari 和 Chrome */
  273. -o-transform: rotate(45deg);
  274. position: absolute;
  275. top: 85rpx;
  276. right: 0;
  277. }
  278. }
  279. .ui-list {
  280. width: 100%;
  281. text-align: left;
  282. padding: 20rpx 0;
  283. border-bottom: solid 1px #f2f2f2;
  284. position: relative;
  285. text {
  286. color: #4a4a4a;
  287. font-size: 28rpx;
  288. display: inline-block;
  289. vertical-align: middle;
  290. min-width: 150rpx;
  291. }
  292. input {
  293. color: #030303;
  294. font-size: 30rpx;
  295. display: inline-block;
  296. vertical-align: middle;
  297. }
  298. button{
  299. color: #030303;
  300. font-size: 30rpx;
  301. display: inline-block;
  302. vertical-align: middle;
  303. background: none;
  304. margin: 0;
  305. padding: 0;
  306. &::after{
  307. display: none;
  308. }
  309. }
  310. picker {
  311. width: 90%;
  312. color: #030303;
  313. font-size: 30rpx;
  314. display: inline-block;
  315. vertical-align: middle;
  316. position: absolute;
  317. top: 30rpx;
  318. left: 150rpx;
  319. }
  320. textarea {
  321. color: #030303;
  322. font-size: 30rpx;
  323. vertical-align: middle;
  324. height: 150rpx;
  325. width: 100%;
  326. margin-top: 50rpx;
  327. }
  328. .place {
  329. color: #999999;
  330. font-size: 28rpx;
  331. }
  332. }
  333. .right:after {
  334. content: ' ';
  335. width: 20rpx;
  336. height: 20rpx;
  337. border-top: solid 1px #030303;
  338. border-right: solid 1px #030303;
  339. transform: rotate(45deg);
  340. -ms-transform: rotate(45deg);
  341. /* IE 9 */
  342. -moz-transform: rotate(45deg);
  343. /* Firefox */
  344. -webkit-transform: rotate(45deg);
  345. /* Safari 和 Chrome */
  346. -o-transform: rotate(45deg);
  347. position: absolute;
  348. top: 40rpx;
  349. right: 0;
  350. }
  351. .save {
  352. background: #030303;
  353. border: none;
  354. color: #ffffff;
  355. margin-top: 40rpx;
  356. font-size: 28rpx;
  357. }
  358. }
  359. </style>