info.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view>
  3. <!--pages/userinfo/userinfo.wxml-->
  4. <view class="list">
  5. <view class="li">
  6. <text>头像</text>
  7. <view class="item" @tap="uploadAvatar">
  8. <image :src="avatar" mode="aspectFit" class="logo"></image>
  9. </view>
  10. <image src="/static/pages/images/more.png" class="rico"></image>
  11. </view>
  12. <view class="li">
  13. <text>昵称</text>
  14. <view class="item">
  15. <input name="nickName" placeholder="请输入昵称" :value="nickName" @input="intNickName"></input>
  16. <!-- {{nickName?nickName:''}} -->
  17. </view>
  18. <!-- <image src="/pages/images/more.png" class="rico"></image> -->
  19. </view>
  20. <view class="li">
  21. <text>真实姓名</text>
  22. <view class="item">
  23. <input name="realName" placeholder="请输入真实姓名" :value="realName" @input="intrealName"></input>
  24. </view>
  25. <image src="/static/pages/images/more.png" class="rico"></image>
  26. </view>
  27. <view class="li">
  28. <text>身份证号</text>
  29. <view class="item">
  30. <input name="cardNo" placeholder="请输入身份证号码" :value="cardNo" @input="getcardNo"></input>
  31. </view>
  32. <image src="/static/pages/images/more.png" class="rico"></image>
  33. </view>
  34. <view class="li">
  35. <text>手机</text>
  36. <block v-if="mobile">
  37. <view class="item active">{{mobile}}</view>
  38. <image src="/static/pages/images/more.png" class="rico"></image>
  39. </block>
  40. <button class="wechat dflex" open-type="getPhoneNumber" @getphonenumber="getphonenumber" v-else>
  41. <image src="/static/pages/images/wxico.png"></image>立即获取
  42. </button>
  43. </view>
  44. <view class="li">
  45. <text>性别</text>
  46. <view class="item active">
  47. <picker @change="bindGender" :value="index" :range="genders">
  48. <view class="picker">
  49. {{genders[index]}}
  50. </view>
  51. </picker>
  52. </view>
  53. <!-- <view class="item active">女</view> -->
  54. <image src="/static/pages/images/more.png" class="rico"></image>
  55. </view>
  56. <view class="li">
  57. <text>出生年月</text>
  58. <view :class="'item ' + (birthday ? 'active' : '')">
  59. <picker mode="date" :value="birthday" @change="bindDateChange">
  60. <view class="picker">
  61. {{birthday ? birthday : '请选择出生年月'}}
  62. </view>
  63. </picker>
  64. </view>
  65. <image src="/static/pages/images/more.png" class="rico"></image>
  66. </view>
  67. <view class="li">
  68. <text>地区</text>
  69. <view :class="['item',(city ? 'active' : '')]">
  70. <picker mode="region" :value="morCity" @change="bindCity">
  71. <!-- <view class="uni-input">{{array[index]}}</view> -->
  72. <view class="picker">
  73. {{city ? city : '请选择地区'}}
  74. </view>
  75. </picker>
  76. </view>
  77. <image src="/static/pages/images/more.png" class="rico"></image>
  78. <!-- <view class="item active">湖南</view>
  79. <image src="/pages/images/more.png" class="rico"></image> -->
  80. </view>
  81. <view class="li">
  82. <text>详细地址</text>
  83. <view class="item">
  84. <input name="realName" placeholder="请输入详细地址" :value="address" @input="bindaddress"></input>
  85. </view>
  86. <image src="/static/pages/images/more.png" class="rico"></image>
  87. </view>
  88. </view>
  89. <button class="submit" @tap="confirm">确定</button>
  90. </view>
  91. </template>
  92. <script>
  93. // pages/userinfo/userinfo.js
  94. const app = getApp();
  95. const req = require("../../utils/request.js");
  96. var QQMapWX = require("../../utils/qqmap.js");
  97. export default {
  98. data() {
  99. return {
  100. genders: ['男', '女'],
  101. index: 0,
  102. avatar: "",
  103. nickName: "",
  104. realName: "",
  105. cardNo: "",
  106. mobile: "",
  107. birthday: "",
  108. city: "",
  109. address: "",
  110. cityCode: '',
  111. morCity: []
  112. };
  113. },
  114. components: {},
  115. props: {},
  116. onLoad: function() {
  117. let _ts = this;
  118. QQMapWX.initMap('3OJBZ-EQEKO-PFNWC-SHHEK-CGWAJ-KRBF7');
  119. app.globalData.getCheckSessoin(json => {
  120. _ts.sessionKey = json.session_key;
  121. });
  122. this.getInfo();
  123. },
  124. methods: {
  125. getInfo() {
  126. let that = this;
  127. let isShowLoading = false;
  128. if (!isShowLoading) {
  129. req.loadIng('加载中');
  130. isShowLoading = true;
  131. }
  132. req.getRequest('/api/user/info', {}, data => {
  133. // console.log(data);
  134. if (!data.areaAdd) {} else {
  135. this.city = data.areaAdd
  136. }
  137. if (!data.district) {} else {
  138. this.cityCode = data.district
  139. this.morCity = (data.district.substring(0, 2) + "0000," + data.district.substring(0, 4) +
  140. "00," + data.district).split(",")
  141. }
  142. this.setData(data);
  143. req.setStorage('userInfo', data);
  144. if (data.gender == 2) {
  145. that.setData({
  146. index: 1
  147. });
  148. } else {
  149. that.setData({
  150. index: 0
  151. });
  152. }
  153. if (isShowLoading) {
  154. uni.hideLoading();
  155. isShowLoading = false;
  156. }
  157. });
  158. },
  159. uploadAvatar() {
  160. let that = this;
  161. uni.chooseImage({
  162. count: 1,
  163. sizeType: ['original', 'compressed'],
  164. sourceType: ['album', 'camera'],
  165. success(res) {
  166. // console.log(res.tempFilePaths);
  167. req.uploadFile('/api/nocheck/upload', res.tempFilePaths[0], res => {
  168. req.msg('图片上传成功');
  169. that.setData({
  170. avatar: res.src
  171. });
  172. });
  173. }
  174. });
  175. },
  176. intNickName(e) {
  177. this.nickName = e.detail.value
  178. },
  179. intrealName(e) {
  180. this.setData({
  181. realName: e.detail.value
  182. });
  183. },
  184. bindaddress(e) {
  185. this.address = e.detail.value
  186. },
  187. getcardNo(e) {
  188. this.setData({
  189. cardNo: e.detail.value
  190. });
  191. },
  192. intMobile(e) {
  193. this.setData({
  194. mobile: e.detail.value
  195. });
  196. },
  197. bindGender: function(e) {
  198. this.setData({
  199. index: e.detail.value
  200. });
  201. },
  202. bindDateChange: function(e) {
  203. this.setData({
  204. birthday: e.detail.value
  205. });
  206. },
  207. bindCity: function(e) {
  208. this.morCity = e.detail.code
  209. this.city = e.detail.value.join().replace(/[,]/g, "")
  210. this.cityCode = e.detail.code[2]
  211. },
  212. confirm() {
  213. let that = this;
  214. let d = {
  215. avatar: that.avatar,
  216. nickName: that.nickName,
  217. realName: that.realName,
  218. mobile: that.mobile,
  219. cardNo: that.cardNo,
  220. gender: that.index == 0 ? 1 : 2,
  221. birthday: that.birthday,
  222. district: that.cityCode,
  223. areaAdd: that.city,
  224. address: that.address
  225. };
  226. let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
  227. // console.log(reg.test(d.realName));
  228. if (!reg.test(d.realName)) return req.msg("请输入正确真实姓名(至少2位汉字)");
  229. let isShowLoading = false;
  230. if (!isShowLoading) {
  231. req.loadIng('保存中');
  232. isShowLoading = true;
  233. }
  234. req.postRequest('/api/user/save', d, res => {
  235. // req.msg('保存成功', () => {
  236. // this.getInfo()
  237. // app.switchTab('pages/user/user')
  238. // })
  239. if (isShowLoading) {
  240. uni.hideLoading();
  241. this.getInfo();
  242. app.globalData.switchTab('pages/user/user');
  243. isShowLoading = false;
  244. }
  245. });
  246. },
  247. getphonenumber(event) {
  248. const detail = event.detail;
  249. const _ts = this;
  250. if (!detail || !detail.encryptedData || !detail.iv) return false;
  251. req.postRequest('/api/weixin/mobile', {
  252. encryptedData: detail.encryptedData,
  253. iv: detail.iv,
  254. sessionKey: this.sessionKey
  255. }, res => {
  256. _ts.getInfo();
  257. });
  258. }
  259. }
  260. };
  261. </script>
  262. <style>
  263. @import "./info.css";
  264. </style>