editInfo.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <view class="page">
  3. <view class="list_info">
  4. <view class="bcenter">
  5. <view class="avator" @click="upload">
  6. <image class="img" :src="avator" mode="aspectFill" />
  7. <image class="photo" src="../../static/me/photo.png" mode="widthFix" />
  8. </view>
  9. </view>
  10. <view class="section_title">基本信息</view>
  11. <view class="info_card">
  12. <view class="info_item">
  13. <text class="label">昵称</text>
  14. <view class="content">
  15. <input type="text" placeholder="请输入昵称" v-model="nickname" maxlength="30" />
  16. <image class="arrow" src="../../static/me/arrow_right_gray.png" mode="widthFix" />
  17. </view>
  18. </view>
  19. <view class="info_item">
  20. <text class="label">简介</text>
  21. <view class="content">
  22. <input type="text" placeholder="请输入简介" v-model="content" maxlength="32" />
  23. <image class="arrow" src="../../static/me/arrow_right_gray.png" mode="widthFix" />
  24. </view>
  25. </view>
  26. <view class="info_item" @click="SetSex">
  27. <text class="label">性别</text>
  28. <view class="content">
  29. <input type="text" placeholder="请选择" v-model="sexText" disabled="true" />
  30. <image class="arrow" src="../../static/me/arrow_right_gray.png" mode="widthFix" />
  31. </view>
  32. </view>
  33. <view class="info_item">
  34. <text class="label">生日</text>
  35. <view class="content">
  36. <picker mode="date" :value="birthday" :end="endDate" @change="onBirthdayChange">
  37. <input type="text" placeholder="请选择生日" v-model="birthday" disabled="true" />
  38. </picker>
  39. <image class="arrow" src="../../static/me/arrow_right_gray.png" mode="widthFix" />
  40. </view>
  41. </view>
  42. <view class="info_item">
  43. <text class="label">星座</text>
  44. <view class="content">
  45. <input type="text" :value="xinzuo_sel" disabled="true" />
  46. <image class="arrow" src="../../static/me/arrow_right_gray.png" mode="widthFix" />
  47. </view>
  48. </view>
  49. </view>
  50. <view class="section_title">个性标签</view>
  51. <view class="info_card">
  52. <view class="item_tag">
  53. <view class="tag" v-for="(item,index) in sel_tags">
  54. {{item}}
  55. <image class="close" src="../../static/me/close.png" mode="widthFix" @click="delTag(item)" />
  56. </view>
  57. <view class="addNew" @click="showPop = true;">添加+</view>
  58. </view>
  59. </view>
  60. <view class="blankHeight"></view>
  61. </view>
  62. <view class="btn_submit" @click="submitData">提交保存</view>
  63. <DialogBox ref="DialogBox"></DialogBox>
  64. <view class="popSel" v-if="showPop" @tap.stop="onPreview">
  65. <view class="list_info">
  66. <view class="name">你的兴趣爱好是?</view>
  67. <view class="desc">提示:最多选择10个兴趣爱好标签</view>
  68. <view class="item_tag">
  69. <view @tap.stop="chkTag(item)" class="tag" :class="selTags(item)?'active':''"
  70. v-for="(item,index) in list_tag">
  71. {{item}}
  72. </view>
  73. </view>
  74. </view>
  75. <view class="btn_submit" @click="showPop = false;">提交选择</view>
  76. </view>
  77. <ToastW3 ref="ToastW3"></ToastW3>
  78. <view v-if="showRights"
  79. style="width:100%;height:300rpx;background-color: rgba(255,255,255,0.9);position: fixed;top:0;display: flex;flex-direction: column;justify-content: center;align-items: center;">
  80. <text
  81. style="width:90%;color:#000000;font-size:38rpx;text-align: left;padding:10rpx 20rpx;padding-top:10rpx;">正在获取相机、存储权限</text>
  82. <text
  83. style="width:90%;color:#666666;font-size:28rpx;text-align: left;padding:10rpx 20rpx;">该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</text>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. import {
  89. requestAndroidPermission,
  90. gotoAppPermissionSetting
  91. } from '../index/permission.js'
  92. export default {
  93. components: {},
  94. data() {
  95. return {
  96. showRights: false,
  97. title: '',
  98. sel: 1,
  99. info: {},
  100. showPop: false,
  101. nickname: '',
  102. content: '',
  103. sex: 1,
  104. age: 18,
  105. height: 160,
  106. weight: 50,
  107. avator: '../../static/me/avator.png',
  108. ziye: '',
  109. qianmin: '',
  110. xinzuo_sel: '',
  111. xinzuo: ['水瓶座', '双鱼座', '白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座'],
  112. list_tag: [],
  113. sel_tags: [],
  114. sexText: '',
  115. birthday: '',
  116. sexOptions: ['男', '女', '其他'],
  117. endDate: new Date().toISOString().split('T')[0]
  118. }
  119. },
  120. onLoad() {
  121. let tagStr =
  122. "篮球、羽毛球、兵乓球、足球、滑板、滑旱冰、跑步、跳绳、举重、听音乐、看电影、绘画、写小说、看书、做弹弓玩、做木剑玩、做橡皮枪玩、积木、用麻将搭金字塔、拼图、拆装、扑克牌、小汽车、手表、鞋之类的、弹吉他、钢琴、萨克斯、葫芦丝、大号、小号、折纸、剪纸、品茶、涂鸦、英雄联盟、qq堂、cs、cf、地下城勇士、桌面游戏";
  123. this.list_tag = tagStr.split("、");
  124. this.getInfoData();
  125. },
  126. onShow() {},
  127. methods: {
  128. onBack() {},
  129. onPreview() {},
  130. chkSel() {
  131. if (this.sel == 1) {
  132. this.sel = 0;
  133. } else {
  134. this.sel = 1;
  135. }
  136. },
  137. chkSex(sex) {
  138. this.sex = sex;
  139. },
  140. delTag(tg) {
  141. let list_tag2 = [];
  142. for (let i = 0; i < this.sel_tags.length; i++) {
  143. if (this.sel_tags[i] != tg) {
  144. list_tag2.push(this.sel_tags[i]);
  145. }
  146. }
  147. this.sel_tags = list_tag2;
  148. },
  149. selTags(itm) {
  150. let that = this;
  151. let isIn = false;
  152. for (let entry of this.sel_tags) {
  153. if (entry == itm) {
  154. isIn = true;
  155. break;
  156. }
  157. }
  158. return isIn;
  159. },
  160. chkTag(itm) {
  161. if (this.selTags(itm)) {
  162. let tmpTags = [];
  163. for (let entry of this.sel_tags) {
  164. if (entry != itm) {
  165. tmpTags.push(entry);
  166. }
  167. }
  168. this.sel_tags = tmpTags;
  169. } else {
  170. if (this.sel_tags.length <= 9) {
  171. this.sel_tags.push(itm);
  172. } else {
  173. this.$refs['ToastW3'].showToast({
  174. title: "最多选择10个标签",
  175. animation: 0
  176. });
  177. }
  178. }
  179. },
  180. sliderChange1(e) {
  181. this.age = e.detail.value;
  182. },
  183. sliderChange2(e) {
  184. this.height = e.detail.value;
  185. },
  186. sliderChange3(e) {
  187. this.weight = e.detail.value;
  188. },
  189. SetSex() {
  190. let that = this;
  191. uni.showActionSheet({
  192. itemColor: '#000000',
  193. itemList: this.sexOptions,
  194. success: function(res) {
  195. that.sexText = that.sexOptions[res.tapIndex];
  196. that.sex = res.tapIndex + 1;
  197. },
  198. fail: function(res) {
  199. console.log(res.errMsg);
  200. }
  201. });
  202. },
  203. getInfoData() {
  204. uni.request({
  205. url: this.$apiHost + '/Member/getinfoData',
  206. data: {
  207. uuid: getApp().globalData.uuid
  208. },
  209. header: {
  210. 'content-type': 'application/json'
  211. },
  212. success: (res) => {
  213. console.log(res.data);
  214. this.nickname = res.data.nickname;
  215. this.wechat = res.data.wechat;
  216. this.sex = res.data.sex;
  217. this.sexText = this.sexOptions[res.data.sex - 1] || '';
  218. this.birthday = res.data.birthday;
  219. this.xinzuo_sel = this.getConstellation(this.birthday);
  220. if (res.data.avator != "") {
  221. this.avator = res.data.avator;
  222. }
  223. if (res.data.aihao) {
  224. this.sel_tags = res.data.aihao.split(",");
  225. }
  226. }
  227. });
  228. },
  229. submitData() {
  230. let aihao = this.sel_tags.join(',')
  231. let obj2 = {
  232. uuid: getApp().globalData.uuid,
  233. avator: this.avator,
  234. nickname: this.nickname,
  235. content: this.content,
  236. sex: this.sex,
  237. birthday: this.birthday,
  238. xinzuo: this.xinzuo_sel,
  239. ziye: this.ziye,
  240. qianmin: this.qianmin,
  241. aihao: aihao
  242. }
  243. uni.request({
  244. url: this.$apiHost + '/Member/setinfoData',
  245. data: obj2,
  246. method: 'POST',
  247. header: {
  248. 'Content-Type': 'application/x-www-form-urlencoded',
  249. 'sign': getApp().globalData.headerSign
  250. },
  251. dataType: 'json',
  252. success: (res) => {
  253. console.log("res", res.data)
  254. this.$refs['ToastW3'].showToast({
  255. title: res.data.str,
  256. animation: 0
  257. });
  258. if (res.data.success == 'yes') {
  259. setTimeout(function() {
  260. uni.navigateBack()
  261. }, 800)
  262. }
  263. this.getInfoData()
  264. }
  265. });
  266. },
  267. upload() {
  268. this.checkRights();
  269. console.log("----upload");
  270. var _self = this;
  271. uni.chooseImage({
  272. count: 1,
  273. sizeType: ['compressed'],
  274. sourceType: ['album', 'camera'],
  275. success: function(res) {
  276. console.log('res:', res)
  277. if (res.tempFilePaths.length > 0) {
  278. _self.imglocal = res.tempFilePaths[0]
  279. const tempFilePaths = res.tempFilePaths[0];
  280. console.log('tempFilePaths:', tempFilePaths);
  281. const uploadTask = uni.uploadFile({
  282. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
  283. filePath: res.tempFilePaths[0],
  284. name: 'file',
  285. success: function(uploadFileRes) {
  286. let resdata = JSON.parse(uploadFileRes.data)
  287. console.log('Success11:', uploadFileRes);
  288. console.log('Success21:', resdata);
  289. if (resdata.success == 'yes') {
  290. _self.showRights = false;
  291. _self.avator = resdata.url;
  292. }
  293. },
  294. fail: function(uploadFileFail) {
  295. console.log('Error:', uploadFileFail.data);
  296. },
  297. complete: () => {
  298. console.log('Complete:');
  299. }
  300. });
  301. }
  302. },
  303. error: function(e) {
  304. console.log(e);
  305. }
  306. });
  307. },
  308. checkRights() {
  309. let that = this;
  310. that.showRights = true;
  311. requestAndroidPermission('android.permission.CAMERA')
  312. .then(result => {
  313. that.showRights = false;
  314. if (result === 1) {} else if (result === 0) {
  315. console.log('权限被拒绝');
  316. } else if (result === -1) {
  317. console.log('权限被永久拒绝');
  318. }
  319. })
  320. .catch(error => {
  321. that.showRights = true;
  322. console.log('权限申请失败:', error);
  323. });
  324. },
  325. onBirthdayChange(e) {
  326. this.birthday = e.detail.value;
  327. this.xinzuo_sel = this.getConstellation(this.birthday);
  328. },
  329. getConstellation(birthday) {
  330. if (!birthday) return '';
  331. const month = parseInt(birthday.split('-')[1]);
  332. const day = parseInt(birthday.split('-')[2]);
  333. // 星座日期数组
  334. const constellationDates = [
  335. [1, 20, "水瓶座"],
  336. [2, 19, "双鱼座"],
  337. [3, 21, "白羊座"],
  338. [4, 20, "金牛座"],
  339. [5, 21, "双子座"],
  340. [6, 22, "巨蟹座"],
  341. [7, 23, "狮子座"],
  342. [8, 23, "处女座"],
  343. [9, 23, "天秤座"],
  344. [10, 24, "天蝎座"],
  345. [11, 23, "射手座"],
  346. [12, 22, "摩羯座"]
  347. ];
  348. let constellation = "";
  349. if (day < constellationDates[month - 1][1]) {
  350. constellation = constellationDates[month - 1][2];
  351. } else {
  352. constellation = constellationDates[month % 12][2];
  353. }
  354. return constellation;
  355. }
  356. }
  357. }
  358. </script>
  359. <style scoped lang="scss">
  360. @import 'normal.scss';
  361. .popSel {
  362. position: fixed;
  363. z-index: 999999;
  364. top: 0;
  365. left: 0;
  366. background-color: #ffffff;
  367. width: 100vh;
  368. height: 100vh;
  369. }
  370. </style>