index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. /* {
  71. "title": "姓名",
  72. "rightText": "",
  73. "icon": "person",
  74. "to": ""
  75. }, */
  76. {
  77. "title": "手机号",
  78. "rightText": "",
  79. "icon": "phone",
  80. "event": '',
  81. "to": ""
  82. }
  83. ],
  84. [{
  85. "title": "余额",
  86. "rightCustom": true,
  87. "rightCustomCss": "item-balance",
  88. "rightText": "",
  89. "icon": "wallet",
  90. "to": ""
  91. /* }, {
  92. "title": "费用明细",
  93. "icon": "list",
  94. "to": "/pages/my/costList"
  95. }, {
  96. "title": "在线充值",
  97. "icon": "shop",
  98. "to": "/pages/my/onlinePay" */
  99. }]
  100. ],
  101. }
  102. },
  103. computed: {
  104. ...mapState([
  105. 'username', // 映射 this.username 为 store.state.username
  106. 'token'
  107. ]),
  108. ...mapGetters([
  109. 'metadata'
  110. ]),
  111. },
  112. onLoad(query) {
  113. // this.init();
  114. },
  115. onShow() {
  116. // console.log("metadata:", this.metadata);
  117. this.init();
  118. },
  119. methods: {
  120. init() {
  121. this.getSelfInfo();
  122. },
  123. // 获取个人信息
  124. getSelfInfo() {
  125. uni.request({
  126. url: apiGetSelfInfo,
  127. header: this.metadata,
  128. method: "POST",
  129. data: {
  130. },
  131. success: (res) => {
  132. // console.log("getSelfInfo", res);
  133. if (checkResCode(res)) {
  134. const data = res.data.data;
  135. this.selfInfo = data;
  136. // this.ucenterList[0][0]["rightText"] = this.selfInfo.name;
  137. // this.ucenterList[0][1]["rightText"] = this.selfInfo.phone;
  138. this.ucenterList[0][0]["rightText"] = this.selfInfo.phone;
  139. this.ucenterList[1][0]["rightText"] = this.selfInfo.balance + " 元";
  140. }
  141. },
  142. fail: (err) => {
  143. console.log("getSelfInfo err", err)
  144. },
  145. });
  146. },
  147. // 用户退出
  148. signOut() {
  149. uni.request({
  150. url: apiSignOut,
  151. header: this.metadata,
  152. method: "POST",
  153. data: {
  154. username: this.username,
  155. password: this.password
  156. },
  157. success: (res) => {
  158. // console.log("signOut", res);
  159. if (res.data.code == 0) {
  160. this.$store.commit("setUsername", "");
  161. this.$store.commit("setUserlevel", 0);
  162. this.$store.commit("setToken", "");
  163. uni.showToast({
  164. title: `账号已退出`,
  165. icon: 'none',
  166. duration: 3000
  167. });
  168. const url = '/pages/login/login';
  169. tools.appAction(url, "uni.navigateTo");
  170. } else {
  171. uni.showToast({
  172. title: `退出失败: ${res.data.message}`,
  173. icon: 'none',
  174. duration: 5000
  175. });
  176. }
  177. },
  178. fail: (err) => {
  179. console.log("signOut err", err);
  180. },
  181. });
  182. },
  183. /* showDetail(data) {
  184. console.log("showDetail data:", data);
  185. this.queryObj.actId = data.actId;
  186. this.queryString = tools.objectToQueryString(this.queryObj);
  187. const url = '/pages/exchange/style1/goodsDetail?' + this.queryString;
  188. tools.appAction(url, "uni.navigateTo");
  189. }, */
  190. btnQuit() {
  191. this.confirmContent = `您确定要退出吗?`;
  192. this.$refs.confirmDialog.open();
  193. },
  194. confirmDialogConfirm() {
  195. this.signOut();
  196. },
  197. ucenterListClick(item) {
  198. if (!item.to && item.event) {
  199. this[item.event]();
  200. }
  201. },
  202. }
  203. }
  204. </script>
  205. <style scoped>
  206. /deep/ uni-page {
  207. background-color: #F6F6F6;
  208. }
  209. .top {
  210. background: url("../../static/bg_topbar.png") no-repeat;
  211. background-size: 100% 100%;
  212. }
  213. .top-content {
  214. position: relative;
  215. width: 90%;
  216. height: 90px;
  217. }
  218. .tc-headimg {
  219. width: 48px;
  220. height: 48px;
  221. }
  222. .tc-userBox {
  223. height: 80%;
  224. margin-left: 20px;
  225. flex-grow: 1;
  226. }
  227. .userBox-name {
  228. font-size: 16px;
  229. font-weight: 550;
  230. color: #ffffff;
  231. }
  232. .userBox-info {
  233. width: 90%;
  234. font-size: 14px;
  235. font-weight: 500;
  236. color: #ffffff;
  237. }
  238. .btnQuit {
  239. width: 45px;
  240. height: 26px;
  241. border-radius: 4px;
  242. background: #FFE19C;
  243. line-height: 26px;
  244. text-align: center;
  245. font-size: 14px;
  246. font-weight: 400;
  247. color: #383838;
  248. }
  249. .center-list {
  250. width: 100%;
  251. margin-top: 10px;
  252. }
  253. ::v-deep .uni-list-item__extra-text {
  254. font-size: 14px;
  255. }
  256. .item-footer {
  257. flex-direction: row;
  258. align-items: center;
  259. }
  260. .item-balance {
  261. color: #383838;
  262. font-size: 18px;
  263. font-weight: 500;
  264. /* padding-right: 10rpx; */
  265. }
  266. </style>