index.vue 6.5 KB

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