promotion.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="content">
  3. <uni-nav-bar :fixed="true" shadow left-icon="left" title="推广团队" :statusBar="true" @clickLeft="handleToBack" />
  4. <view style="display: flex; justify-content: space-between; padding: 40upx">
  5. <view style="display: flex">
  6. <view style="margin-right: 41upx">
  7. <image
  8. class="card_thumbnail"
  9. :src="userData?.js?.avatar || '/static/account/avatar.png'"
  10. mode="aspectFill"
  11. style="width: 130upx; height: 130upx"
  12. />
  13. </view>
  14. <view
  15. style="display: flex; flex-direction: column; justify-content: center"
  16. >
  17. <view style="font-size: 40upx; font-weight: bold; color: #000000">{{
  18. userData?.js?.name
  19. }}</view>
  20. <view
  21. style="
  22. font-size: 26upx;
  23. font-weight: 400;
  24. color: #999;
  25. margin: 24upx 0 0;
  26. "
  27. >
  28. {{ userData?.mobile }}
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="card">
  34. <view
  35. style="
  36. width: 710upx;
  37. height: 80upx;
  38. background: linear-gradient(90deg, #37ecba 0%, #72afd3 100%);
  39. border-radius: 20upx 20upx 0px 0px;
  40. padding-top: 20upx;
  41. "
  42. >
  43. <uni-segmented-control
  44. :current="current"
  45. :values="items"
  46. style-type="text"
  47. active-color="#FFFFFF"
  48. @clickItem="onClickItem"
  49. />
  50. </view>
  51. <view>
  52. <view v-if="current === 0">
  53. <uni-list :border="true">
  54. <!-- 显示圆形头像 -->
  55. <uni-list-chat
  56. v-for="(item, index) in promotionData[current]"
  57. :key="index"
  58. :avatar-circle="true"
  59. :title="`${item?.user_nickname || item?.mobile}(${item?.mobile})`"
  60. :avatar="item?.avatar || '/static/account/avatar.png'"
  61. :note="verifyTime(item?.create_time)"
  62. time=" "
  63. >
  64. <view class="chat-custom-right">
  65. <text class="chat-custom-text">直接好友</text>
  66. </view>
  67. </uni-list-chat>
  68. </uni-list>
  69. </view>
  70. <view v-if="current === 1">
  71. <uni-list :border="true">
  72. <!-- 显示圆形头像 -->
  73. <uni-list-chat
  74. v-for="(item, index) in promotionData[current]"
  75. :key="index"
  76. :avatar-circle="true"
  77. :title="`${item?.user_nickname || item?.mobile}(${item?.mobile})`"
  78. :avatar="item?.avatar || '/static/account/avatar.png'"
  79. :note="verifyTime(item?.create_time)"
  80. time=" "
  81. >
  82. <view class="chat-custom-right">
  83. <text class="chat-custom-text">间接好友</text>
  84. </view>
  85. </uni-list-chat>
  86. </uni-list>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="loading_wrap" v-if="loading && params.page > 1">
  91. <uni-load-more status="loading"></uni-load-more>
  92. </view>
  93. <view class="footer">
  94. <image mode="widthFix" src="/static/common/footer.png" />
  95. </view>
  96. </view>
  97. </template>
  98. <script setup>
  99. import { ref, reactive } from "vue";
  100. import { onLoad, onShow, onReachBottom } from "@dcloudio/uni-app";
  101. import request from "/common/request.js";
  102. import auth from "/common/auth.js";
  103. const statusBarHeight = ref();
  104. const userData = ref();
  105. const current = ref(0);
  106. const items = ["直接好友", "间接好友"];
  107. const params = reactive({
  108. page: 1,
  109. type: 1,
  110. });
  111. const promotionData = ref([]);
  112. const stopReachBottom = ref(false);
  113. const loading = ref(false);
  114. const handleToBack = () => {
  115. const canNavBack = getCurrentPages();
  116. if (canNavBack && canNavBack.length > 1) uni.navigateBack();
  117. else history.back();
  118. };
  119. onLoad((option) => {
  120. statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight;
  121. initData();
  122. });
  123. onShow(() => {
  124. renderData();
  125. uni.$emit('fastOrderNum', false);
  126. uni.$emit('receiveOrdernum', false);
  127. });
  128. onReachBottom((option) => {
  129. if (stopReachBottom.value) return;
  130. getPromotionData(true);
  131. });
  132. async function initData() {
  133. if (auth(false)) {
  134. uni.pageScrollTo({ scrollTop: 0, duration: 0 });
  135. }
  136. }
  137. async function renderData() {
  138. if (auth()) {
  139. uni.pageScrollTo({ scrollTop: 0, duration: 0 });
  140. getUserInfo();
  141. getPromotionData();
  142. }
  143. }
  144. const getUserInfo = () => {
  145. uni.showLoading();
  146. request({
  147. url: "/api/user/getInfo",
  148. method: "GET",
  149. success: (res) => {
  150. console.log("客户信息", res);
  151. if (res.data.code == 1) {
  152. userData.value = res.data?.data ?? {};
  153. } else if (res.data.code == 10001) {
  154. uni.removeStorageSync("token");
  155. uni.removeStorageSync("id");
  156. uni.showToast({
  157. title: "登录已失效,请重新登录",
  158. duration: 2000,
  159. icon: "none",
  160. success: () => {
  161. uni.navigateTo({
  162. url: "/pages/account/login",
  163. });
  164. },
  165. });
  166. }
  167. },
  168. fail: () => {},
  169. complete: () => {
  170. uni.hideLoading();
  171. uni.stopPullDownRefresh();
  172. },
  173. });
  174. };
  175. const onClickItem = (e) => {
  176. if (current.value != e.currentIndex) {
  177. current.value = e.currentIndex;
  178. params.type = e.currentIndex + 1;
  179. getPromotionData();
  180. }
  181. };
  182. const getPromotionData = (next = false) => {
  183. if (loading.value) return;
  184. if (next) {
  185. params.page++;
  186. } else {
  187. params.page = 1;
  188. stopReachBottom.value = false;
  189. uni.showLoading();
  190. }
  191. loading.value = true;
  192. request({
  193. url: "/api/user/getxiaji",
  194. method: "GET",
  195. data: params,
  196. success: (res) => {
  197. console.log("好友", res);
  198. if (res.data?.code == 1) {
  199. promotionData.value[current.value] = res.data?.data;
  200. if (!res.data?.data || !res.data?.data?.length) {
  201. // if (params.page == 1) locationMessage.value = "暂无订单哦!";
  202. stopReachBottom.value = true;
  203. params.page--;
  204. }
  205. if (next) promotionData.value[current.value].push(...res.data?.data);
  206. else promotionData.value[current.value] = res.data?.data ?? [];
  207. }
  208. },
  209. fail: () => {},
  210. complete: () => {
  211. loading.value = false;
  212. uni.hideLoading();
  213. },
  214. });
  215. };
  216. const verifyTime = (timestamp) => {
  217. if (!timestamp) return "";
  218. // 此处时间戳以毫秒为单位
  219. let date = new Date(parseInt(timestamp) * 1000);
  220. let Year = date.getFullYear();
  221. let Moth =
  222. date.getMonth() + 1 < 10
  223. ? "0" + (date.getMonth() + 1)
  224. : date.getMonth() + 1;
  225. let Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  226. let Hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  227. let Minute =
  228. date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  229. // let Sechond =
  230. // date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  231. let GMT = Year + "-" + Moth + "-" + Day + " " + Hour + ":" + Minute;
  232. return GMT;
  233. };
  234. </script>
  235. <style lang="scss" scoped>
  236. .content {
  237. :deep(.segmented-control) {
  238. height: initial;
  239. width: 600upx;
  240. .segmented-control__text {
  241. opacity: 0.8;
  242. font-size: 29upx;
  243. font-weight: 400;
  244. color: #ffffff !important;
  245. &::after {
  246. content: "";
  247. width: 40upx;
  248. height: 4upx;
  249. background: transparent;
  250. border-radius: 2upx;
  251. display: block;
  252. margin: 6upx auto;
  253. }
  254. &.segmented-control__item--text {
  255. opacity: 1;
  256. font-weight: bold;
  257. font-size: 32upx;
  258. border: 0;
  259. &::after {
  260. background: #ffffff;
  261. }
  262. }
  263. }
  264. }
  265. :deep(.uni-list-chat) {
  266. .uni-list-chat__container {
  267. padding: 30upx;
  268. .uni-list-chat__content-extra {
  269. justify-content: center;
  270. font-size: 24upx;
  271. font-weight: 400;
  272. color: #ff490e;
  273. }
  274. }
  275. }
  276. }
  277. </style>