金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

368 lines
9.0 KiB

  1. <template>
  2. <view id="user-setting">
  3. <view class="head_box">
  4. <view class="head_message">
  5. 个人头像
  6. </view>
  7. <view class="head_right">
  8. <view class="headImg" @tap="changeImage">
  9. <image :src="detail.avatar" alt></image>
  10. </view>
  11. <view class="iconfont icon-jiantou head_under"></view>
  12. </view>
  13. </view>
  14. <view class="user_setting">
  15. <view class="code">
  16. <view class="detail">昵称</view>
  17. <input type="text" placeholder="填写您的昵称" @input="changeName" :value="detail.nick_name"></input>
  18. </view>
  19. <view class="code">
  20. <view class="detail">性别</view>
  21. <picker :value="selectedIndex" :range="list" @change="change">
  22. <!--<view class="picker">{{list[selectedIndex]}}</view>-->
  23. <input type="text" placeholder="选择你的性别" disabled :value="list[selectedIndex]"></input>
  24. </picker>
  25. <view class="iconfont icon-jiantou under"></view>
  26. <!--<input type="text" placeholder="选择你的性别"/>-->
  27. </view>
  28. <view class="code" v-if="isChangeB">
  29. <view class="detail">出生日期</view>
  30. <picker mode="date" :end="end" @change="changeDate">
  31. <input type="text" placeholder="请输入出生日期" disabled :value="birthdaydate"></input>
  32. </picker>
  33. <view class="iconfont icon-jiantou under"></view>
  34. </view>
  35. <view class="code" v-if="!isChangeB" @tap="changeB">
  36. <view class="detail">出生日期</view>
  37. <view style="position: relative; flex: 1">
  38. <input type="text" placeholder="请输入出生日期" disabled :value="birthdaydate"></input>
  39. <!--<view class="iconfont icon-jiantou under"></view>-->
  40. </view>
  41. </view>
  42. <!-- <view class="code">
  43. <view class="detail">QQ</view>
  44. <input type="text" placeholder="请输入QQ号码" :value="QQnum" @input="changeQQ"></input>
  45. </view> -->
  46. <view class="code">
  47. <view class="detail">手机号码</view>
  48. <input type="text" placeholder="请输入手机号码" :value="mobileNum" disabled></input>
  49. <view @tap="changeMobile" class="iconfont icon-jiantou phone_under"></view>
  50. </view>
  51. <!-- <view class="code">
  52. <view class="detail">邮箱</view>
  53. <input type="text" placeholder="请输入邮箱" :value="emailSet" @input="changeEmail"></input>
  54. </view> -->
  55. </view>
  56. <view class="submit" @tap="updateUserInfo">
  57. <button type="primary" :style="'background: ' + config.mainColor">确定</button>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. pageLogin,
  64. getUrl,
  65. config,
  66. is
  67. } from '@/common/js/utils.js';
  68. export default {
  69. data() {
  70. return {
  71. list: ['男', '女'],
  72. selectedIndex:-1,
  73. detail: "",
  74. birthdaydate: '',
  75. QQnum: '',
  76. mobileNum: "",
  77. emailSet: "",
  78. config: '',
  79. isChangeB: '',
  80. newImage:''
  81. };
  82. },
  83. onShow() {
  84. pageLogin(getUrl(), () => {
  85. this.gitUserInfo();
  86. });
  87. },
  88. onLoad() {
  89. // 第三方平台配置颜色
  90. var bgConfig = this.$cookieStorage.get('globalConfig') || '';
  91. var initData = this.$cookieStorage.get('init');
  92. this.config = bgConfig;
  93. this.initData = initData;
  94. Date.prototype.format = function(fmt) {
  95. var o = {
  96. "M+": this.getMonth() + 1,
  97. //月份
  98. "d+": this.getDate(),
  99. //日
  100. "h+": this.getHours(),
  101. //小时
  102. "m+": this.getMinutes(),
  103. //分
  104. "s+": this.getSeconds(),
  105. //秒
  106. "q+": Math.floor((this.getMonth() + 3) / 3),
  107. //季度
  108. "S": this.getMilliseconds() //毫秒
  109. };
  110. if (/(y+)/.test(fmt)) {
  111. fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  112. }
  113. for (var k in o) {
  114. if (new RegExp("(" + k + ")").test(fmt)) {
  115. fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
  116. }
  117. }
  118. return fmt;
  119. };
  120. var time = new Date().format("yyyy-MM-dd");
  121. this.end = time;
  122. },
  123. methods: {
  124. change: function(e) {
  125. // console.log(e);
  126. // 修改选中项文案
  127. this.setData({
  128. selectedIndex: e.detail.value
  129. });
  130. },
  131. changeName(e) {
  132. this.setData({
  133. 'detail.nick_name': e.detail.value
  134. });
  135. },
  136. changeDate(e) {
  137. this.setData({
  138. birthdaydate: e.detail.value
  139. });
  140. },
  141. changeQQ(e) {
  142. this.setData({
  143. QQnum: e.detail.value
  144. });
  145. },
  146. changeB() {
  147. wx.showModal({
  148. content: '暂时无法修改',
  149. showCancel: false
  150. });
  151. },
  152. changeMobile() {
  153. wx.navigateTo({
  154. url: '/pages/user/bindingphone/bindingphone'
  155. });
  156. },
  157. changeEmail(e) {
  158. this.setData({
  159. emailSet: e.detail.value
  160. });
  161. },
  162. gitUserInfo() {
  163. this.$http.get({
  164. api: 'api/me',
  165. header: {
  166. Authorization: this.$cookieStorage.get('user_token')
  167. }
  168. }).then(res => {
  169. if (res.data.status) {
  170. var sex = res.data.data.sex;
  171. var index = this.list.findIndex(val => {
  172. return val == sex;
  173. });
  174. if (index == -1) index = "";
  175. var isChangeB = true;
  176. if (this.initData && this.initData.vip_plan_status == 1 && res.data.data.birthday != '') {
  177. isChangeB = false;
  178. }
  179. // this.setData({
  180. // detail: res.data.data,
  181. // selectedIndex: index,
  182. // birthdaydate: res.data.data.birthday,
  183. // QQnum: res.data.data.qq,
  184. // mobileNum: res.data.data.mobile,
  185. // emailSet: res.data.data.email,
  186. // isChangeB: isChangeB
  187. // });
  188. this.detail = res.data.data;
  189. this.selectedIndex = index;
  190. this.birthdaydate = res.data.data.birthday;
  191. this.QQnum = res.data.data.qq;
  192. this.mobileNum = res.data.data.mobile;
  193. this.emailSet = res.data.data.email;
  194. this.isChangeB = isChangeB;
  195. }
  196. });
  197. },
  198. changeImage: function() {
  199. uni.chooseImage({
  200. count: 1,
  201. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  202. sourceType: ['album'], //从相册选择
  203. success: res => {
  204. var tempFilePaths = res.tempFilePaths;
  205. this.newImage = tempFilePaths[0];
  206. var token = this.$cookieStorage.get('user_token');
  207. /* this.$http.uploadFile({
  208. header: {
  209. 'content-type': 'multipart/form-data',
  210. Authorization: token
  211. },
  212. api: 'api/users/upload/avatar',
  213. //仅为示例,非真实的接口地址
  214. filePath: tempFilePaths[0],
  215. name: 'avatar_file'
  216. }).then(res => {
  217. console.log(result);
  218. this.setData({
  219. 'detail.avatar': result.data.url
  220. });
  221. }); */
  222. uni.uploadFile({
  223. header: {
  224. Authorization: token
  225. },
  226. url: config.GLOBAL.baseUrl + 'api/users/upload/avatar',
  227. filePath: tempFilePaths[0],
  228. fileType: 'image',
  229. name: 'avatar_file',
  230. success: res => {
  231. var result = JSON.parse(res.data);
  232. this.setData({
  233. 'detail.avatar': result.data.url
  234. });
  235. }
  236. })
  237. }
  238. });
  239. },
  240. updateUserInfo() {
  241. var message = null;
  242. if (!this.detail.nick_name) {
  243. message = "请填写用户昵称";
  244. }
  245. /* else if (this.emailSet != "" && !is.email(this.emailSet)) {
  246. message = "请填写正确的邮箱";
  247. } */
  248. // else if (!this.birthdaydate) {
  249. // message = "请选择出生日期";
  250. // }
  251. if (message) {
  252. wx.showModal({
  253. content: message,
  254. showCancel: false
  255. });
  256. return;
  257. } // this.updateBirthday();
  258. var token = this.$cookieStorage.get('user_token');
  259. this.$http.post({
  260. api: 'api/users/update/info',
  261. header: {
  262. Authorization:token
  263. },
  264. data: {
  265. nick_name: this.detail.nick_name,
  266. sex: this.list[this.selectedIndex],
  267. avatar: this.detail.avatar,
  268. birthday: this.birthdaydate,
  269. /* qq: this.QQnum, */
  270. /* email: this.emailSet */
  271. }
  272. }).then(res => {
  273. if (res.statusCode == 200) {
  274. res = res.data;
  275. if(res.status){
  276. wx.showToast({
  277. title:"修改成功",
  278. duration: 1500,
  279. success: () => {
  280. setTimeout(() => {
  281. wx.switchTab({
  282. url: '/pages/user/personal/personal'
  283. });
  284. }, 1500);
  285. }
  286. });
  287. }
  288. } else {
  289. wx.showModal({
  290. title: "提示",
  291. content: "修改失败"
  292. });
  293. }
  294. });
  295. },
  296. updateBirthday() {
  297. this.$http.post({
  298. api: 'api/uto/update/birthday',
  299. header: {
  300. Authorization: this.$cookieStorage.get('user_token')
  301. },
  302. data: {
  303. birthday: this.birthdaydate
  304. }
  305. }).then(res => {
  306. console.log(res);
  307. });
  308. },
  309. setData: function(obj) {
  310. let that = this;
  311. let keys = [];
  312. let val, data;
  313. Object.keys(obj).forEach(function(key) {
  314. keys = key.split('.');
  315. val = obj[key];
  316. data = that.$data;
  317. keys.forEach(function(key2, index) {
  318. if (index + 1 == keys.length) {
  319. that.$set(data, key2, val);
  320. } else {
  321. if (!data[key2]) {
  322. that.$set(data, key2, {});
  323. }
  324. }
  325. data = data[key2];
  326. });
  327. });
  328. }
  329. }
  330. };
  331. </script>
  332. <style rel="stylesheet/less" lang="less">
  333. @import "usersetting";
  334. </style>