userinfo.vue 11 KB

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