userinfo.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <template>
  2. <view>
  3. <!--pages/userinfo/userinfo.wxml-->
  4. <view class="list">
  5. <view class="li">
  6. <text>头像</text>
  7. <button open-type="chooseAvatar" hover-class="none" class="item" @chooseavatar="uploadAvatar">
  8. <image :src="avatar" mode="aspectFit" class="logo"></image>
  9. </button>
  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 class="li li-brief">
  89. <text>个人简介</text>
  90. <view class="item">
  91. <editor placeholder="请输入个人简介" v-model="brief" id="editor" @ready="onEditorReadyB" @input="bindBrief" class="textarea brief"></editor>
  92. </view>
  93. </view>
  94. <view class="li li-brief">
  95. <text>个人爱好</text>
  96. <view class="item">
  97. <editor placeholder="请输入个人爱好" v-model="hobbies" id="editor" @ready="onEditorReadyH" @input="bindHobbies" class="textarea hobbies"></editor>
  98. </view>
  99. </view>
  100. </view>
  101. <view style="height: 200rpx;"></view>
  102. <button class="submit" @tap="confirm">确定</button>
  103. </view>
  104. </template>
  105. <script>
  106. // pages/userinfo/userinfo.js
  107. const app = getApp();
  108. const req = require("../../utils/request.js");
  109. var QQMapWX = require("../../utils/qqmap.js");
  110. export default {
  111. data() {
  112. return {
  113. genders: ['男', '女'],
  114. index: 0,
  115. avatar: "",
  116. nickName: "",
  117. realName: "",
  118. cardNo: "",
  119. mobile: "",
  120. birthday: "",
  121. city: "",
  122. address: "",
  123. cityCode: '',
  124. morCity: [],
  125. brief: '',
  126. hobbies: ''
  127. };
  128. },
  129. components: {},
  130. props: {},
  131. onLoad: function() {
  132. let _ts = this;
  133. QQMapWX.initMap('3OJBZ-EQEKO-PFNWC-SHHEK-CGWAJ-KRBF7');
  134. app.globalData.getCheckSessoin(json => {
  135. _ts.sessionKey = json.session_key;
  136. });
  137. this.getInfo();
  138. },
  139. methods: {
  140. getInfo() {
  141. let that = this;
  142. let isShowLoading = false;
  143. if (!isShowLoading) {
  144. req.loadIng('加载中');
  145. isShowLoading = true;
  146. }
  147. req.getRequest('/api/user/info', {}, data => {
  148. // console.log(data);
  149. if (!data.district) {} else {
  150. this.cityCode = data.district
  151. this.morCity = (data.district.substring(0, 2) + "0000," + data.district.substring(0, 4) +
  152. "00," + data.district).split(",")
  153. }
  154. this.setData(data);
  155. if (!data.areaAdd) {} else {
  156. this.city = data.areaAdd
  157. }
  158. req.setStorage('userInfo', data);
  159. if (data.gender == 2) {
  160. that.setData({
  161. index: 1
  162. });
  163. } else {
  164. that.setData({
  165. index: 0
  166. });
  167. }
  168. if (isShowLoading) {
  169. uni.hideLoading();
  170. isShowLoading = false;
  171. }
  172. that.onEditorReadyB();
  173. that.onEditorReadyH();
  174. });
  175. },
  176. uploadAvatar(e) {
  177. req.uploadFile('/api/upload', e.detail.avatarUrl, res => {
  178. this.avatar = res.src
  179. });
  180. // let that = this;
  181. // uni.chooseImage({
  182. // count: 1,
  183. // sizeType: ['original', 'compressed'],
  184. // sourceType: ['album', 'camera'],
  185. // success(res) {
  186. // // console.log(res.tempFilePaths);
  187. // req.uploadFile('/api/upload', res.tempFilePaths[0], res => {
  188. // req.msg('图片上传成功');
  189. // that.setData({
  190. // avatar: res.src
  191. // });
  192. // });
  193. // }
  194. // });
  195. },
  196. intNickName(e) {
  197. this.nickName = e.detail.value
  198. },
  199. intrealName(e) {
  200. this.setData({
  201. realName: e.detail.value
  202. });
  203. },
  204. bindaddress(e) {
  205. this.address = e.detail.value
  206. },
  207. getcardNo(e) {
  208. this.setData({
  209. cardNo: e.detail.value
  210. });
  211. },
  212. intMobile(e) {
  213. this.setData({
  214. mobile: e.detail.value
  215. });
  216. },
  217. bindGender: function(e) {
  218. this.setData({
  219. index: e.detail.value
  220. });
  221. },
  222. bindDateChange: function(e) {
  223. this.setData({
  224. birthday: e.detail.value
  225. });
  226. },
  227. bindCity: function(e) {
  228. this.morCity = e.detail.code
  229. this.city = e.detail.value.join().replace(/[,]/g, "")
  230. this.cityCode = e.detail.code[2]
  231. },
  232. bindBrief(e) {
  233. this.brief = e.detail.html;
  234. },
  235. bindHobbies(e) {
  236. this.hobbies = e.detail.html;
  237. },
  238. confirm() {
  239. let that = this;
  240. let d = {
  241. avatar: that.avatar,
  242. nickName: that.nickName,
  243. realName: that.realName,
  244. mobile: that.mobile,
  245. cardNo: that.cardNo,
  246. gender: that.index == 0 ? 1 : 2,
  247. birthday: that.birthday,
  248. district: that.cityCode,
  249. areaAdd: that.city,
  250. address: that.address,
  251. brief: that.brief,
  252. hobbies: that.hobbies,
  253. };
  254. let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
  255. // console.log(reg.test(d.realName));
  256. if (!reg.test(d.realName)) return req.msg("请输入正确真实姓名(至少2位汉字)");
  257. let isShowLoading = false;
  258. if (!isShowLoading) {
  259. req.loadIng('保存中');
  260. isShowLoading = true;
  261. }
  262. req.postRequest('/api/user/save', d, res => {
  263. // req.msg('保存成功', () => {
  264. // this.getInfo()
  265. // app.switchTab('pages/user/user')
  266. // })
  267. if (isShowLoading) {
  268. uni.hideLoading();
  269. this.getInfo();
  270. app.globalData.switchTab('pages/user/user');
  271. isShowLoading = false;
  272. }
  273. });
  274. },
  275. getphonenumber(event) {
  276. const detail = event.detail;
  277. const _ts = this;
  278. if (!detail || !detail.encryptedData || !detail.iv) return false;
  279. req.postRequest('/api/weixin/mobile', {
  280. encryptedData: detail.encryptedData,
  281. iv: detail.iv,
  282. sessionKey: this.sessionKey
  283. }, res => {
  284. _ts.getInfo();
  285. });
  286. },
  287. onEditorReadyB() {
  288. var that = this;
  289. uni.createSelectorQuery().select('.brief').context((res) => {
  290. this.editorCtx = res.context;
  291. this.editorCtx.setContents({//赋值
  292. html:that.brief
  293. });
  294. }).exec()
  295. },
  296. onEditorReadyH() {
  297. var that = this;
  298. uni.createSelectorQuery().select('.hobbies').context((res) => {
  299. this.editorCtx = res.context;
  300. this.editorCtx.setContents({//赋值
  301. html:that.hobbies
  302. });
  303. }).exec()
  304. },
  305. }
  306. };
  307. </script>
  308. <style>
  309. @import "./userinfo.css";
  310. .ql-editor.ql-blank:before {
  311. /* 此处设置 placeholder 样式 */
  312. color: #999;
  313. font-style: normal;
  314. }
  315. </style>