index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <!--
  2. 我的
  3. http://localhost:5173/actMgt/#/pages/my/index
  4. https://oss-mbh5.colormaprun.com/actMgt/#/pages/my/index
  5. -->
  6. <template>
  7. <view class="body">
  8. <view class="content uni-column">
  9. <view class="uni-column top">
  10. <view class="top-content uni-row">
  11. <image class="tc-headimg" mode="aspectFit" src="/static/headimg.png"></image>
  12. <view class="tc-userBox uni-column uni-ais uni-jcse">
  13. <view class="userBox-name">{{selfInfo.name}}</view>
  14. <view class="userBox-info uni-row">
  15. <view class="">等级:{{userLevel[selfInfo.level]}}</view>
  16. <!-- <view class="" style="margin-left: 20px;">余额:¥120.00</view> -->
  17. </view>
  18. </view>
  19. <view class="btnQuit" @click="btnQuit">退出</view>
  20. </view>
  21. </view>
  22. <view class="main uni-column">
  23. <uni-list class="center-list" v-for="(sublist , index) in ucenterList" :key="index">
  24. <uni-list-item v-for="(item,i) in sublist" :title="item.title" :showArrow="item.to != ''" :rightText="item.rightText"
  25. :key="i" :clickable="true" :to="item.to" @click="ucenterListClick(item)" :show-extra-icon="true"
  26. :extraIcon="{type:item.icon,color:'#999'}">
  27. <template v-slot:footer>
  28. <view v-if="item.rightCustom" class="item-footer" :class="item.rightCustomCss">
  29. <view class="item-footer-text" v-html="item.rightText"></view>
  30. </view>
  31. </template>
  32. </uni-list-item>
  33. </uni-list>
  34. </view>
  35. </view>
  36. <uni-popup ref="confirmDialog" type="dialog">
  37. <uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="提示" :content="confirmContent"
  38. @confirm="confirmDialogConfirm"></uni-popup-dialog>
  39. </uni-popup>
  40. </view>
  41. </template>
  42. <script>
  43. import {
  44. mapState,
  45. mapGetters
  46. } from 'vuex';
  47. import tools from '/utils/tools.js';
  48. import { userLevel } from '/utils/define.js';
  49. import {
  50. apiSignOut,
  51. apiGetSelfInfo,
  52. checkResCode
  53. } from '/utils/api.js';
  54. export default {
  55. components: {},
  56. data() {
  57. return {
  58. userLevel: userLevel,
  59. queryObj: {},
  60. queryString: "",
  61. confirmContent: "",
  62. selfInfo: {
  63. name: "", // 姓名
  64. phone: "", // 手机号
  65. balance: "",// 余额
  66. level: "", // 等级
  67. },
  68. ucenterList: [
  69. [{
  70. "title": "姓名",
  71. "rightText": "",
  72. "icon": "person",
  73. "to": ""
  74. },
  75. {
  76. "title": "手机号",
  77. "rightText": "",
  78. "icon": "phone",
  79. "event": '',
  80. "to": ""
  81. }
  82. ],
  83. [{
  84. "title": "余额",
  85. "rightCustom": true,
  86. "rightCustomCss": "item-balance",
  87. "rightText": "",
  88. "icon": "wallet",
  89. "to": ""
  90. /* }, {
  91. "title": "费用明细",
  92. "icon": "list",
  93. "to": "/pages/my/costList"
  94. }, {
  95. "title": "在线充值",
  96. "icon": "shop",
  97. "to": "/pages/my/onlinePay" */
  98. }]
  99. ],
  100. }
  101. },
  102. computed: {
  103. ...mapState([
  104. 'username', // 映射 this.username 为 store.state.username
  105. 'token'
  106. ]),
  107. ...mapGetters([
  108. 'metadata'
  109. ]),
  110. },
  111. onLoad(query) {
  112. this.init();
  113. },
  114. onShow() {
  115. // console.log("metadata:", this.metadata);
  116. this.init();
  117. },
  118. methods: {
  119. init() {
  120. this.getSelfInfo();
  121. },
  122. // 获取个人信息
  123. getSelfInfo() {
  124. uni.request({
  125. url: apiGetSelfInfo,
  126. header: this.metadata,
  127. method: "POST",
  128. data: {
  129. },
  130. success: (res) => {
  131. console.log("getSelfInfo", res);
  132. if (checkResCode(res)) {
  133. const data = res.data.data;
  134. this.selfInfo = data;
  135. this.ucenterList[0][0]["rightText"] = this.selfInfo.name;
  136. this.ucenterList[0][1]["rightText"] = this.selfInfo.phone;
  137. this.ucenterList[1][0]["rightText"] = this.selfInfo.balance + " 元";
  138. }
  139. },
  140. fail: (err) => {
  141. console.log("getSelfInfo err", err)
  142. },
  143. });
  144. },
  145. // 用户退出
  146. signOut() {
  147. uni.request({
  148. url: apiSignOut,
  149. header: this.metadata,
  150. method: "POST",
  151. data: {
  152. username: this.username,
  153. password: this.password
  154. },
  155. success: (res) => {
  156. console.log("signOut", res);
  157. if (res.data.code == 0) {
  158. this.$store.commit("setUsername", "");
  159. this.$store.commit("setUserlevel", 0);
  160. this.$store.commit("setToken", "");
  161. uni.showToast({
  162. title: `账号已退出`,
  163. icon: 'none',
  164. duration: 3000
  165. });
  166. const url = '/pages/login/login';
  167. tools.appAction(url, "uni.navigateTo");
  168. } else {
  169. uni.showToast({
  170. title: `退出失败: ${res.data.message}`,
  171. icon: 'none',
  172. duration: 5000
  173. });
  174. }
  175. },
  176. fail: (err) => {
  177. console.log("signOut err", err);
  178. },
  179. });
  180. },
  181. /* showDetail(data) {
  182. console.log("showDetail data:", data);
  183. this.queryObj.actId = data.actId;
  184. this.queryString = tools.objectToQueryString(this.queryObj);
  185. const url = '/pages/exchange/style1/goodsDetail?' + this.queryString;
  186. tools.appAction(url, "uni.navigateTo");
  187. }, */
  188. btnQuit() {
  189. this.confirmContent = `您确定要退出吗?`;
  190. this.$refs.confirmDialog.open();
  191. },
  192. confirmDialogConfirm() {
  193. this.signOut();
  194. },
  195. ucenterListClick(item) {
  196. if (!item.to && item.event) {
  197. this[item.event]();
  198. }
  199. },
  200. }
  201. }
  202. </script>
  203. <style scoped>
  204. /deep/ uni-page {
  205. background-color: #F6F6F6;
  206. }
  207. .top {
  208. background: url("../../static/bg_topbar.png") no-repeat;
  209. background-size: 100% 100%;
  210. }
  211. .top-content {
  212. position: relative;
  213. width: 90%;
  214. height: 90px;
  215. }
  216. .tc-headimg {
  217. width: 48px;
  218. height: 48px;
  219. }
  220. .tc-userBox {
  221. height: 80%;
  222. margin-left: 20px;
  223. flex-grow: 1;
  224. }
  225. .userBox-name {
  226. font-size: 16px;
  227. font-weight: 550;
  228. color: #ffffff;
  229. }
  230. .userBox-info {
  231. width: 90%;
  232. font-size: 14px;
  233. font-weight: 500;
  234. color: #ffffff;
  235. }
  236. .btnQuit {
  237. width: 45px;
  238. height: 26px;
  239. border-radius: 4px;
  240. background: #FFE19C;
  241. line-height: 26px;
  242. text-align: center;
  243. font-size: 14px;
  244. font-weight: 400;
  245. color: #383838;
  246. }
  247. .center-list {
  248. width: 100%;
  249. margin-top: 10px;
  250. }
  251. ::v-deep .uni-list-item__extra-text {
  252. font-size: 14px;
  253. }
  254. .item-footer {
  255. flex-direction: row;
  256. align-items: center;
  257. }
  258. .item-balance {
  259. color: #383838;
  260. font-size: 18px;
  261. font-weight: 500;
  262. /* padding-right: 10rpx; */
  263. }
  264. </style>