c-userinfo.vue 8.1 KB

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