userinfo.vue 8.9 KB

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