editInfo.vue 11 KB

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