userinfo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 type="nickname" 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 class="agree dflex" @click="agree" v-if="config.CONFIG_PRIVACY_AGREEMENT">
  101. <image :src="'../static/images/' + (isAgree ? 'gou1_h.png' : 'gou1.png')" class="gou"></image>
  102. 已阅读并同意
  103. <text @click.stop="jumpUrl('/pages/web/web?url='+it.url)" v-for="it,idx in JSON.parse(config.CONFIG_PRIVACY_AGREEMENT)"><block v-if="idx!=0">、</block>{{it.name}}</text>
  104. </view>
  105. </view>
  106. <view style="height: 200rpx;"></view>
  107. <button class="submit" @tap="confirm">确定</button>
  108. </view>
  109. </template>
  110. <script>
  111. // pages/userinfo/userinfo.js
  112. const app = getApp();
  113. const req = require("../../utils/request.js");
  114. const requsetmessage = require('../../utils/requestmessage.js');
  115. var QQMapWX = require("../../utils/qqmap.js");
  116. export default {
  117. data() {
  118. return {
  119. genders: ['男', '女'],
  120. index: 0,
  121. avatar: "",
  122. nickName: "",
  123. realName: "",
  124. cardNo: "",
  125. mobile: "",
  126. birthday: "",
  127. city: "",
  128. address: "",
  129. cityCode: '',
  130. morCity: [],
  131. brief: '',
  132. hobbies: '',
  133. isAgree:false,
  134. config:{}
  135. };
  136. },
  137. components: {},
  138. props: {},
  139. onLoad:async function() {
  140. let _ts = this;
  141. QQMapWX.initMap('3OJBZ-EQEKO-PFNWC-SHHEK-CGWAJ-KRBF7');
  142. app.globalData.getCheckSessoin(json => {
  143. _ts.sessionKey = json.session_key;
  144. });
  145. this.getInfo();
  146. this.config = await req.getsysConfig()
  147. if(!this.config.CONFIG_PRIVACY_AGREEMENT) this.isAgree = true
  148. },
  149. methods: {
  150. jumpUrl(url){
  151. uni.navigateTo({
  152. url:url
  153. })
  154. },
  155. getInfo() {
  156. let that = this;
  157. let isShowLoading = false;
  158. if (!isShowLoading) {
  159. req.loadIng('加载中');
  160. isShowLoading = true;
  161. }
  162. req.getRequest('/api/user/myInfo', {}, data => {
  163. // console.log(data);
  164. if (!data.district) {} else {
  165. this.cityCode = data.district
  166. this.morCity = (data.district.substring(0, 2) + "0000," + data.district.substring(0, 4) +
  167. "00," + data.district).split(",")
  168. }
  169. this.setData(data);
  170. if (!data.areaAdd) {} else {
  171. this.city = data.areaAdd
  172. }
  173. req.setStorage('userInfo', data);
  174. if (data.gender == 2) {
  175. that.setData({
  176. index: 1
  177. });
  178. } else {
  179. that.setData({
  180. index: 0
  181. });
  182. }
  183. if (isShowLoading) {
  184. uni.hideLoading();
  185. isShowLoading = false;
  186. }
  187. that.onEditorReadyB();
  188. that.onEditorReadyH();
  189. });
  190. },
  191. uploadAvatar(e) {
  192. uni.showLoading({
  193. title:'上传中'
  194. })
  195. req.uploadFile('/api/nocheck/upload', e.detail.avatarUrl, res => {
  196. uni.hideLoading()
  197. this.avatar = res.src
  198. });
  199. // let that = this;
  200. // uni.chooseImage({
  201. // count: 1,
  202. // sizeType: ['original', 'compressed'],
  203. // sourceType: ['album', 'camera'],
  204. // success(res) {
  205. // // console.log(res.tempFilePaths);
  206. // req.uploadFile('/api/upload', res.tempFilePaths[0], res => {
  207. // req.msg('图片上传成功');
  208. // that.setData({
  209. // avatar: res.src
  210. // });
  211. // });
  212. // }
  213. // });
  214. },
  215. intNickName(e) {
  216. this.nickName = e.detail.value
  217. },
  218. getNickname: function(e) {
  219. this.nickName = e.detail.value;
  220. },
  221. intrealName(e) {
  222. this.setData({
  223. realName: e.detail.value
  224. });
  225. },
  226. bindaddress(e) {
  227. this.address = e.detail.value
  228. },
  229. getcardNo(e) {
  230. this.setData({
  231. cardNo: e.detail.value
  232. });
  233. },
  234. intMobile(e) {
  235. this.setData({
  236. mobile: e.detail.value
  237. });
  238. },
  239. bindGender: function(e) {
  240. this.setData({
  241. index: e.detail.value
  242. });
  243. },
  244. bindDateChange: function(e) {
  245. this.setData({
  246. birthday: e.detail.value
  247. });
  248. },
  249. bindCity: function(e) {
  250. this.morCity = e.detail.code
  251. this.city = e.detail.value.join().replace(/[,]/g, "")
  252. this.cityCode = e.detail.code[2]
  253. },
  254. bindBrief(e) {
  255. this.brief = e.detail.html;
  256. },
  257. bindHobbies(e) {
  258. this.hobbies = e.detail.html;
  259. },
  260. async confirm() {
  261. let that = this;
  262. let d = {
  263. avatar: that.avatar,
  264. nickName: that.nickName,
  265. realName: that.realName,
  266. mobile: that.mobile,
  267. cardNo: that.cardNo,
  268. gender: that.index == 0 ? 1 : 2,
  269. birthday: that.birthday,
  270. district: that.cityCode,
  271. areaAdd: that.city,
  272. address: that.address,
  273. brief: that.brief,
  274. hobbies: that.hobbies,
  275. };
  276. let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
  277. // console.log(reg.test(d.realName));
  278. if(!d.avatar) return req.msg("请上传头像");
  279. if(!d.nickName) return req.msg("请填写用户昵称");
  280. if(!d.realName) return req.msg("请填写真实姓名");
  281. if (!reg.test(d.realName)) return req.msg("请输入正确真实姓名(至少2位汉字)");
  282. // if(!d.cardNo) return req.msg("请填写身份证号");
  283. if(!d.mobile) return req.msg("请填写手机号");
  284. // if(!d.birthday) return req.msg("请选择出生日期");
  285. // if(!d.district) return req.msg("请选择地区");
  286. // if(!d.address) return req.msg("请填写详细地址");
  287. if(!this.isAgree) return req.msg("请阅读并同意以下协议");
  288. let isShowLoading = false;
  289. if (!isShowLoading) {
  290. req.loadIng('保存中');
  291. isShowLoading = true;
  292. }
  293. // await requsetmessage.remindIntegral().then(res => {});
  294. req.postRequest('/api/user/save', d, res => {
  295. // req.msg('保存成功', () => {
  296. // this.getInfo()
  297. // app.switchTab('pages/user/user')
  298. // })
  299. req.getRequest('/api/user/myInfo', {}, data => {
  300. req.setStorage('userInfo', data);
  301. if (isShowLoading) {
  302. uni.hideLoading();
  303. this.getInfo();
  304. uni.navigateBack()
  305. isShowLoading = false;
  306. }
  307. });
  308. });
  309. },
  310. getphonenumber(event) {
  311. const detail = event.detail;
  312. const _ts = this;
  313. if (!detail || !detail.encryptedData || !detail.iv) return false;
  314. req.postRequest('/api/weixin/mobile', {
  315. encryptedData: detail.encryptedData,
  316. iv: detail.iv,
  317. sessionKey: this.sessionKey
  318. }, res => {
  319. req.getRequest('/api/user/myInfo', {}, data => {
  320. req.setStorage('userInfo', data);
  321. this.mobile = data.mobile
  322. });
  323. });
  324. },
  325. onEditorReadyB() {
  326. var that = this;
  327. uni.createSelectorQuery().select('.brief').context((res) => {
  328. this.editorCtx = res.context;
  329. this.editorCtx.setContents({//赋值
  330. html:that.brief
  331. });
  332. }).exec()
  333. },
  334. onEditorReadyH() {
  335. var that = this;
  336. uni.createSelectorQuery().select('.hobbies').context((res) => {
  337. this.editorCtx = res.context;
  338. this.editorCtx.setContents({//赋值
  339. html:that.hobbies
  340. });
  341. }).exec()
  342. },
  343. agree(){
  344. this.isAgree = !this.isAgree
  345. }
  346. }
  347. };
  348. </script>
  349. <style>
  350. @import "./userinfo.css";
  351. .ql-editor.ql-blank:before {
  352. /* 此处设置 placeholder 样式 */
  353. color: #999;
  354. font-style: normal;
  355. }
  356. </style>