index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. <template>
  2. <gui-page :customHeader="true">
  3. <view slot="gHeader">
  4. <view class="gui-flex gui-nowrap gui-rows gui-align-items-center gui-padding">
  5. <!-- 使用组件实现返回按钮及返回首页按钮 -->
  6. <gui-header-leading :onlyBack="true"></gui-header-leading>
  7. <!-- 导航文本此处也可以是其他自定义内容 -->
  8. <text class="gui-h4 gui-ellipsis gui-text-center gui-header-content gui-primary-color">个人资料</text>
  9. <!-- 如果右侧有其他内容可以利用条件编译和定位来实现-->
  10. </view>
  11. </view>
  12. <view slot="gBody" class="container">
  13. <view class="brand">
  14. <image :src="fetch.avatar" @click="avatarSet(0)" class="avatar"></image>
  15. <avatar @upload="avatarUpload" ref="avatar"></avatar>
  16. <view class="username">{{fetch.name}}</view>
  17. </view>
  18. <view class="user-form">
  19. <list-cell line-right padding="30rpx">
  20. <view class="form-item">
  21. <view class="label">昵称</view>
  22. <input type="text" v-model="fetch.name"/>
  23. </view>
  24. </list-cell>
  25. <list-cell line-right padding="30rpx">
  26. <view class="form-item">
  27. <view class="label">头衔</view>
  28. <input type="text" v-model="fetch.title"/>
  29. </view>
  30. </list-cell>
  31. <list-cell line-right padding="30rpx">
  32. <view class="form-item">
  33. <view class="label">签名</view>
  34. <input type="text" v-model="fetch.info"/>
  35. </view>
  36. </list-cell>
  37. <list-cell line-right padding="30rpx" style="display: none;">
  38. <view class="form-item">
  39. <view class="label">手机号码</view>
  40. <input type="text" v-model="fetch.mobile" />
  41. <button type="default" plain class="font-size-sm" @tap="showTelphoneModal">更换手机</button>
  42. </view>
  43. </list-cell>
  44. <list-cell line-right padding="30rpx">
  45. <view class="form-item">
  46. <view class="label">性别</view>
  47. <view class="radio" @tap="fetch.sex = 1">
  48. <image :src="fetch.sex == 1 ? '/static/images/common/round-black-selected.png' : '/static/images/common/gouxuankuang.png'"></image>
  49. <view>男</view>
  50. </view>
  51. <view class="radio" @tap="fetch.sex = 2">
  52. <image :src="fetch.sex == 2 ? '/static/images/common/round-black-selected.png' : '/static/images/common/gouxuankuang.png'"></image>
  53. <view>女</view>
  54. </view>
  55. <view class="radio" @tap="fetch.sex = 3">
  56. <image :src="fetch.sex == 3 ? '/static/images/common/round-black-selected.png' : '/static/images/common/gouxuankuang.png'"></image>
  57. <view>不显示</view>
  58. </view>
  59. </view>
  60. </list-cell>
  61. <list-cell line-right padding="30rpx" last>
  62. <view class="form-item">
  63. <view class="label">生日</view>
  64. <picker class="flex-fill" mode="date" :value="fetch.birthday" @change="handleBirthdayChange">
  65. <view v-if="fetch.birthday">{{ fetch.birthday }}</view>
  66. <view v-if="!fetch.birthday">请选择生日</view>
  67. </picker>
  68. </view>
  69. </list-cell>
  70. </view>
  71. <view class="save-btn">
  72. <wButton
  73. class="wbutton"
  74. text="修改资料"
  75. :rotate="isRotate"
  76. @click.native="update()"
  77. ></wButton>
  78. </view>
  79. <modal :show="telphoneModalVisible" custom padding="40rpx 30rpx">
  80. <view class="telphone-modal">
  81. <view class="header">
  82. <view>温馨提示</view>
  83. <image src="/static/images/common/closex.png" class="close-icon" @tap="closeTelphoneModal"></image>
  84. </view>
  85. <view class="tips">
  86. 请在绑定前确定新手机号未绑定合小记。
  87. </view>
  88. <view class="telphone-form">
  89. <list-cell padding="30rpx 0">
  90. <view class="telphone-input">
  91. <view class="prefix">+86</view>
  92. <input type="text" v-model="telphoneForm.telphone" placeholder="请填写有效手机号码" placeholder-class="font-size-base text-color-assist"/>
  93. </view>
  94. </list-cell>
  95. <list-cell padding="30rpx 0">
  96. <view class="verfiycode-input">
  97. <input type="text" v-model="telphoneForm.verifyCode" placeholder="6位数字验证码" placeholder-class="font-size-base text-color-assist">
  98. <view class="countdown" :class="{'text-color-assist': !countdown, 'text-color-base': countdown}" @tap="getVerifyCode">
  99. {{ !countdown ? '获取验证码' : countdown + '秒可获取' }}
  100. </view>
  101. </view>
  102. </list-cell>
  103. </view>
  104. <view class="footer">
  105. <button type="primary" @tap="closeTelphoneModal">确认</button>
  106. </view>
  107. </view>
  108. </modal>
  109. </view>
  110. </gui-page>
  111. </template>
  112. <script>
  113. import wInput from '@/lib/watch-login/watch-input.vue' //input
  114. import wButton from '@/lib/watch-login/watch-button.vue' //button
  115. import avatar from "@/lib/yq-avatar/yq-avatar.vue";
  116. import listCell from '@/lib/list-cell/list-cell.vue'
  117. import modal from '@/lib/modal/modal.vue'
  118. export default {
  119. components: {
  120. listCell,
  121. modal,
  122. wInput,
  123. wButton,
  124. avatar
  125. },
  126. data() {
  127. return {
  128. fetch : {
  129. name : '',
  130. avatar : '',
  131. sex : 3,
  132. },
  133. isRotate: false, //是否加载旋转
  134. openAvatar : false,
  135. telphoneModalVisible: false,
  136. telphoneForm: {
  137. telphone: '',
  138. verifyCode: ''
  139. },
  140. countdown: 0
  141. }
  142. },
  143. // 重新加载
  144. onPullDownRefresh: function() {
  145. this.getData();
  146. },
  147. onLoad() {
  148. this.Dever.checkLogin();
  149. this.getData();
  150. },
  151. methods: {
  152. getData : function() {
  153. this.Dever.get(this, 'app/user/?l=api.getBaseUser');
  154. },
  155. bind_weixin : function() {
  156. var self = this;
  157. this.Dever.confirm('即将开始微信授权,授权后您的微信信息将覆盖现有个人信息,但不会影响您已设置好的某个合小记中的个人信息。', function() {
  158. if (self.Dever.source == 'h5') {
  159. var host = self.Dever.api_host + 'package/oauth/?l=request.auth&account=1&system=1&system_source=' + self.Dever.source_id + '&signature=' + self.Dever.getToken();
  160. self.Dever.location(host, 'go');
  161. } else if (self.Dever.source == 'wx_applet') {
  162. uni.authorize({
  163. scope: 'scope.userInfo',
  164. success() {
  165. uni.login({
  166. provider: 'weixin',
  167. success: function (loginRes) {
  168. console.log(loginRes.authResult);
  169. // 获取用户信息
  170. uni.getUserInfo({
  171. provider: 'weixin',
  172. lang : 'zh_CN',
  173. success: function (infoRes) {
  174. console.log('用户昵称为:' + infoRes.userInfo.nickName);
  175. }
  176. });
  177. }
  178. });
  179. }
  180. })
  181. } else {
  182. self.Dever.alert('暂时不支持app登录');
  183. }
  184. });
  185. },
  186. index : function() {
  187. this.Dever.location('index/index');
  188. },
  189. tixian : function() {
  190. this.Dever.alert('敬请期待');
  191. },
  192. update : function() {
  193. if(this.isRotate){
  194. //判断是否加载中,避免重复点击请求
  195. return false;
  196. }
  197. if (!this.fetch.name) {
  198. this.Dever.alert('昵称不能为空');
  199. return false;
  200. }
  201. this.isRotate = true;
  202. var self = this;
  203. this.Dever.post('package/passport/?l=app.update', {noloading:1, username: this.fetch.name, info: this.fetch.info, gender: this.fetch.sex, title:this.fetch.title, birthday:this.fetch.birthday}, function(t) {
  204. self.isRotate = false;
  205. self.Dever.alert('已保存资料,仅影响未修改过信息的合小记');
  206. }, function(t) {
  207. self.Dever.alert(t.msg);
  208. self.isRotate = false;
  209. });
  210. },
  211. avatarUpload : function(e) {
  212. var self = this;
  213. this.openAvatar = false;
  214. this.Dever.uploadFile(e.path, 'avatar', 1, function(type, file) {
  215. self.fetch.avatar = file;
  216. self.Dever.post('package/passport/?l=app.update', {avatar:file, noloading:1});
  217. });
  218. },
  219. avatarSet : function(index) {
  220. this.openAvatar = true;
  221. this.$refs.avatar.fChooseImg(index,{
  222. selWidth: "300rpx", selHeight: "300rpx",
  223. expWidth: '260rpx', expHeight: '260rpx',
  224. avatarSrc : this.fetch.avatar,
  225. bgImage : this.fetch.avatar,
  226. noTab : true,
  227. });
  228. },
  229. handleBirthdayChange({target: {value}}) {
  230. this.fetch.birthday = value
  231. },
  232. showTelphoneModal() {
  233. this.telphoneModalVisible = true
  234. },
  235. closeTelphoneModal() {
  236. this.telphoneModalVisible = false
  237. this.telphoneForm = this.$options.data().telphoneForm
  238. },
  239. getVerifyCode() {
  240. if(this.countdown) return
  241. if(!this.telphoneForm.telphone) {
  242. uni.showToast({
  243. title: '请填写手机号码',
  244. icon: 'none'
  245. })
  246. return
  247. }
  248. this.countdown = 60
  249. let interval = setInterval(() => {
  250. if(!this.countdown) {
  251. clearInterval(interval)
  252. return
  253. }
  254. this.countdown -= 1
  255. }, 1000)
  256. }
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .brand {
  262. background-color: $bg-color-white;
  263. display: flex;
  264. flex-direction: column;
  265. align-items: center;
  266. justify-content: center;
  267. padding: 40rpx 0;
  268. margin-bottom: 20rpx;
  269. .avatar {
  270. width: 200rpx;
  271. height: 200rpx;
  272. border-radius: 100%;
  273. margin-bottom: 30rpx;
  274. }
  275. .username {
  276. color: $font-size-medium;
  277. font-weight: bold;
  278. }
  279. }
  280. .user-form {
  281. .form-item {
  282. width: 100%;
  283. display: flex;
  284. align-items: center;
  285. .label {
  286. width: 160rpx;
  287. }
  288. input {
  289. flex: 1;
  290. }
  291. .radio {
  292. display: flex;
  293. margin-right: 50rpx;
  294. image {
  295. width: 40rpx;
  296. height: 40rpx;
  297. margin-right: 20rpx;
  298. }
  299. }
  300. }
  301. }
  302. .save-btn {
  303. padding: 0 30rpx;
  304. margin-top: 60rpx;
  305. button {
  306. width: 100%;
  307. font-size: $font-size-extra-lg;
  308. }
  309. }
  310. .telphone-modal {
  311. .header {
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. position: relative;
  316. font-size: $font-size-extra-lg;
  317. font-weight: bold;
  318. margin-bottom: 30rpx;
  319. .close-icon {
  320. width: 60rpx;
  321. height: 60rpx;
  322. position: absolute;
  323. right: 0;
  324. }
  325. }
  326. .tips {
  327. color: $text-color-grey;
  328. line-height: 1.2rem;
  329. margin-bottom: 50rpx;
  330. }
  331. .telphone-form {
  332. font-size: $font-size-base;
  333. .telphone-input {
  334. width: 100%;
  335. display: flex;
  336. align-items: center;
  337. .prefix {
  338. color: $color-primary;
  339. display: flex;
  340. align-items: center;
  341. padding-right: 20rpx;
  342. position: relative;
  343. margin-right: 10rpx;
  344. &::after {
  345. content: " ";
  346. position: absolute;
  347. width: 4rpx;
  348. background-color: $border-color;
  349. }
  350. }
  351. input {
  352. flex: 1;
  353. }
  354. }
  355. .verfiycode-input {
  356. width: 100%;
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. .countdown {
  361. font-size: $font-size-base;
  362. }
  363. }
  364. }
  365. .footer {
  366. margin-top: 30rpx;
  367. button {
  368. font-size: $font-size-lg;
  369. }
  370. }
  371. }
  372. </style>