userinfo.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <view>
  3. <!--pages/userinfo/userinfo.wxml-->
  4. <view class="list">
  5. <view class="li">
  6. <text style="color: red;">*</text>
  7. <text>头像</text>
  8. <button open-type="chooseAvatar" hover-class="none" class="item" @chooseavatar="uploadAvatar">
  9. <image :src="avatar" mode="aspectFit" class="logo"></image>
  10. </button>
  11. <image src="/static/pages/images/more.png" class="rico"></image>
  12. </view>
  13. <view class="li">
  14. <text style="color: red;">*</text>
  15. <text>昵称</text>
  16. <view class="item">
  17. <input type="nickname" name="nickName" placeholder="请输入昵称" :value="nickName" @input="intNickName" @blur="getNickname"></input>
  18. <!-- {{nickName?nickName:''}} -->
  19. </view>
  20. <!-- <image src="/pages/images/more.png" class="rico"></image> -->
  21. </view>
  22. <view class="li">
  23. <text style="color: red;">*</text>
  24. <text>手机</text>
  25. <block v-if="mobile">
  26. <view class="item active">{{handlePhone(mobile)}}</view>
  27. <image src="/static/pages/images/more.png" class="rico"></image>
  28. </block>
  29. <button class="wechat dflex" open-type="getPhoneNumber" @getphonenumber="getphonenumber" v-else>
  30. <image src="/static/pages/images/wxico.png"></image>立即获取
  31. </button>
  32. </view>
  33. <view class="li">
  34. <text>真实姓名</text>
  35. <view class="item">
  36. <input name="realName" placeholder="请输入真实姓名" :value="realName" @input="intrealName"></input>
  37. </view>
  38. <image src="/static/pages/images/more.png" class="rico"></image>
  39. </view>
  40. <view class="li">
  41. <text>身份证号</text>
  42. <view class="item">
  43. <input v-if="cardNoEdit" :focus="cardNoEdit" name="cardNo" placeholder="请输入身份证号码" :value="cardNo" @input="getcardNo" @blur="cardNoBlur"></input>
  44. <text v-else style="width: 100%;text-align: right;font-size: 30rpx;color: #333;line-height: 36rpx;" @click="cardNoFocus">{{handleIdCard(cardNo)}}</text>
  45. </view>
  46. <image src="/static/pages/images/more.png" class="rico"></image>
  47. </view>
  48. <view class="li">
  49. <text>性别</text>
  50. <view class="item active">
  51. <picker @change="bindGender" :value="index" :range="genders">
  52. <view class="picker">
  53. {{genders[index]}}
  54. </view>
  55. </picker>
  56. </view>
  57. <!-- <view class="item active">女</view> -->
  58. <image src="/static/pages/images/more.png" class="rico"></image>
  59. </view>
  60. <view class="li">
  61. <text>出生年月</text>
  62. <view :class="'item ' + (birthday ? 'active' : '')">
  63. <picker mode="date" :value="birthday" @change="bindDateChange">
  64. <view class="picker">
  65. {{birthday ? birthday : '请选择出生年月'}}
  66. </view>
  67. </picker>
  68. </view>
  69. <image src="/static/pages/images/more.png" class="rico"></image>
  70. </view>
  71. <view class="li">
  72. <text>地区</text>
  73. <view :class="['item',(city ? 'active' : '')]">
  74. <picker mode="region" :value="morCity" @change="bindCity">
  75. <!-- <view class="uni-input">{{array[index]}}</view> -->
  76. <view class="picker">
  77. {{city ? city : '请选择地区'}}
  78. </view>
  79. </picker>
  80. </view>
  81. <image src="/static/pages/images/more.png" class="rico"></image>
  82. <!-- <view class="item active">湖南</view>
  83. <image src="/pages/images/more.png" class="rico"></image> -->
  84. </view>
  85. <view class="li">
  86. <text>详细地址</text>
  87. <view class="item">
  88. <input name="realName" placeholder="请输入详细地址" :value="address" @input="bindaddress"></input>
  89. </view>
  90. <image src="/static/pages/images/more.png" class="rico"></image>
  91. </view>
  92. <view class="li li-brief">
  93. <text>个人简介</text>
  94. <view class="item">
  95. <editor placeholder="请输入个人简介" v-model="brief" id="editor" @ready="onEditorReadyB" @input="bindBrief" class="textarea brief"></editor>
  96. </view>
  97. </view>
  98. <!-- <view class="li li-brief">
  99. <text>个人爱好</text>
  100. <view class="item">
  101. <editor placeholder="请输入个人爱好" v-model="hobbies" id="editor" @ready="onEditorReadyH" @input="bindHobbies" class="textarea hobbies"></editor>
  102. </view>
  103. </view> -->
  104. <view style="color: red;font-size: 24rpx;padding: 30rpx 30rpx;">*号表示必填项</view>
  105. <view class="agree dflex" @click="agree" v-if="config.CONFIG_PRIVACY_AGREEMENT">
  106. <image :src="'../static/images/' + (isAgree ? 'gou1_h.png' : 'gou1.png')" class="gou"></image>
  107. 已阅读并同意
  108. <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>
  109. </view>
  110. </view>
  111. <view style="height: 200rpx;"></view>
  112. <button class="submit" @tap="confirm">确定</button>
  113. </view>
  114. </template>
  115. <script>
  116. // pages/userinfo/userinfo.js
  117. const app = getApp();
  118. const req = require("../../utils/request.js");
  119. const requsetmessage = require('../../utils/requestmessage.js');
  120. var QQMapWX = require("../../utils/qqmap.js");
  121. export default {
  122. data() {
  123. return {
  124. genders: ['男', '女'],
  125. index: 0,
  126. avatar: "",
  127. nickName: "",
  128. realName: "",
  129. cardNo: "",
  130. mobile: "",
  131. birthday: "",
  132. city: "",
  133. address: "",
  134. cityCode: '',
  135. morCity: [],
  136. brief: '',
  137. hobbies: '',
  138. isAgree:false,
  139. config:{},
  140. cardNoEdit:true
  141. };
  142. },
  143. components: {},
  144. props: {},
  145. onLoad:async function() {
  146. let _ts = this;
  147. QQMapWX.initMap('3OJBZ-EQEKO-PFNWC-SHHEK-CGWAJ-KRBF7');
  148. app.globalData.getCheckSessoin(json => {
  149. _ts.sessionKey = json.session_key;
  150. });
  151. this.getInfo();
  152. this.config = await req.getsysConfig()
  153. if(!this.config.CONFIG_PRIVACY_AGREEMENT) this.isAgree = true
  154. },
  155. methods: {
  156. jumpUrl(url){
  157. uni.navigateTo({
  158. url:url
  159. })
  160. },
  161. cardNoBlur(){
  162. if(this.cardNo) this.cardNoEdit = false
  163. },
  164. cardNoFocus(){
  165. this.cardNoEdit = true
  166. },
  167. getInfo() {
  168. let that = this;
  169. let isShowLoading = false;
  170. if (!isShowLoading) {
  171. req.loadIng('加载中');
  172. isShowLoading = true;
  173. }
  174. req.getRequest('/api/user/myInfo', {}, data => {
  175. // console.log(data);
  176. if (!data.district) {} else {
  177. this.cityCode = data.district
  178. this.morCity = (data.district.substring(0, 2) + "0000," + data.district.substring(0, 4) +
  179. "00," + data.district).split(",")
  180. }
  181. this.setData(data);
  182. if(this.cardNo) this.cardNoEdit = false
  183. if (!data.areaAdd) {} else {
  184. this.city = data.areaAdd
  185. }
  186. req.setStorage('userInfo', data);
  187. if (data.gender == 2) {
  188. that.setData({
  189. index: 1
  190. });
  191. } else {
  192. that.setData({
  193. index: 0
  194. });
  195. }
  196. if (isShowLoading) {
  197. uni.hideLoading();
  198. isShowLoading = false;
  199. }
  200. that.onEditorReadyB();
  201. that.onEditorReadyH();
  202. });
  203. },
  204. uploadAvatar(e) {
  205. uni.showLoading({
  206. title:'上传中'
  207. })
  208. req.uploadFile('/api/nocheck/upload', e.detail.avatarUrl, res => {
  209. uni.hideLoading()
  210. this.avatar = res.src
  211. });
  212. // let that = this;
  213. // uni.chooseImage({
  214. // count: 1,
  215. // sizeType: ['original', 'compressed'],
  216. // sourceType: ['album', 'camera'],
  217. // success(res) {
  218. // // console.log(res.tempFilePaths);
  219. // req.uploadFile('/api/upload', res.tempFilePaths[0], res => {
  220. // req.msg('图片上传成功');
  221. // that.setData({
  222. // avatar: res.src
  223. // });
  224. // });
  225. // }
  226. // });
  227. },
  228. intNickName(e) {
  229. this.nickName = e.detail.value
  230. },
  231. getNickname: function(e) {
  232. this.nickName = e.detail.value;
  233. },
  234. intrealName(e) {
  235. this.setData({
  236. realName: e.detail.value
  237. });
  238. },
  239. bindaddress(e) {
  240. this.address = e.detail.value
  241. },
  242. getcardNo(e) {
  243. this.setData({
  244. cardNo: e.detail.value
  245. });
  246. },
  247. intMobile(e) {
  248. this.setData({
  249. mobile: e.detail.value
  250. });
  251. },
  252. bindGender: function(e) {
  253. this.setData({
  254. index: e.detail.value
  255. });
  256. },
  257. bindDateChange: function(e) {
  258. this.setData({
  259. birthday: e.detail.value
  260. });
  261. },
  262. bindCity: function(e) {
  263. this.morCity = e.detail.code
  264. this.city = e.detail.value.join().replace(/[,]/g, "")
  265. this.cityCode = e.detail.code[2]
  266. },
  267. bindBrief(e) {
  268. this.brief = e.detail.html;
  269. },
  270. bindHobbies(e) {
  271. this.hobbies = e.detail.html;
  272. },
  273. async confirm() {
  274. let that = this;
  275. let d = {
  276. avatar: that.avatar,
  277. nickName: that.nickName,
  278. realName: that.realName,
  279. mobile: that.mobile,
  280. cardNo: that.cardNo,
  281. gender: that.index == 0 ? 1 : 2,
  282. birthday: that.birthday,
  283. district: that.cityCode,
  284. areaAdd: that.city,
  285. address: that.address,
  286. brief: that.brief,
  287. hobbies: that.hobbies,
  288. };
  289. let reg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;
  290. // console.log(reg.test(d.realName));
  291. if(!d.avatar) return req.msg("请上传头像");
  292. if(!d.nickName) return req.msg("请填写用户昵称");
  293. // if(!d.realName) return req.msg("请填写真实姓名");
  294. // if (!reg.test(d.realName)) return req.msg("请输入正确真实姓名(至少2位汉字)");
  295. // if(!d.cardNo) return req.msg("请填写身份证号");
  296. if(!d.mobile) return req.msg("请填写手机号");
  297. var re = /^\d{17}(\d|x)$/i;
  298. if (d.cardNo && !re.test(d.cardNo)) {
  299. return req.msg("请填写正确的身份证号");
  300. }
  301. // if(!d.birthday) return req.msg("请选择出生日期");
  302. // if(!d.district) return req.msg("请选择地区");
  303. // if(!d.address) return req.msg("请填写详细地址");
  304. if(!this.isAgree) return req.msg("请阅读并同意以下协议");
  305. let isShowLoading = false;
  306. if (!isShowLoading) {
  307. req.loadIng('保存中');
  308. isShowLoading = true;
  309. }
  310. // await requsetmessage.remindIntegral().then(res => {});
  311. req.postRequest('/api/user/save', d, res => {
  312. // req.msg('保存成功', () => {
  313. // this.getInfo()
  314. // app.switchTab('pages/user/user')
  315. // })
  316. req.getRequest('/api/user/myInfo', {}, data => {
  317. req.setStorage('userInfo', data);
  318. if (isShowLoading) {
  319. uni.hideLoading();
  320. this.getInfo();
  321. uni.navigateBack()
  322. isShowLoading = false;
  323. }
  324. });
  325. });
  326. },
  327. getphonenumber(event) {
  328. const detail = event.detail;
  329. const _ts = this;
  330. if (!detail || !detail.encryptedData || !detail.iv) return false;
  331. req.postRequest('/api/weixin/mobile', {
  332. encryptedData: detail.encryptedData,
  333. iv: detail.iv,
  334. sessionKey: this.sessionKey
  335. }, res => {
  336. req.getRequest('/api/user/myInfo', {}, data => {
  337. req.setStorage('userInfo', data);
  338. this.mobile = data.mobile
  339. });
  340. });
  341. },
  342. onEditorReadyB() {
  343. var that = this;
  344. uni.createSelectorQuery().select('.brief').context((res) => {
  345. this.editorCtx = res.context;
  346. this.editorCtx.setContents({//赋值
  347. html:that.brief
  348. });
  349. }).exec()
  350. },
  351. onEditorReadyH() {
  352. var that = this;
  353. uni.createSelectorQuery().select('.hobbies').context((res) => {
  354. this.editorCtx = res.context;
  355. this.editorCtx.setContents({//赋值
  356. html:that.hobbies
  357. });
  358. }).exec()
  359. },
  360. agree(){
  361. this.isAgree = !this.isAgree
  362. },
  363. handleIdCard(cardId) {
  364. var re = /^\d{17}(\d|x)$/i;
  365. if (re.test(cardId)) {
  366. return cardId.replace(/^(.{4})(?:\d+)(.{4})$/, "$1**********$2");
  367. }else{
  368. return cardId
  369. }
  370. },
  371. handlePhone (phone) {
  372. return phone.replace(/^(.{3})(?:\d+)(.{4})$/, "$1****$2")
  373. },
  374. }
  375. };
  376. </script>
  377. <style>
  378. @import "./userinfo.css";
  379. .ql-editor.ql-blank:before {
  380. /* 此处设置 placeholder 样式 */
  381. color: #999;
  382. font-style: normal;
  383. }
  384. </style>