myTracks.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="myTracks">
  3. <u-empty text="暂无历史记录" style="margin-top:200rpx;" mode="history" v-if="whetherEmpty"></u-empty>
  4. <div v-else>
  5. <view v-for="(item, index) in trackList" :key="index">
  6. <view class="myTracks-title" @click="navgaiteToStore(item)">{{item.storeName}}</view>
  7. <view class="myTracks-items">
  8. <view class="myTracks-item">
  9. <u-checkbox-group>
  10. <u-checkbox v-model="item.___isDel" v-if="editFlag" active-color="#ff6b35" style="margin-right: 10rpx" @change="changeChecked(item)"></u-checkbox>
  11. </u-checkbox-group>
  12. <view class="myTracks-item-img" @click.stop="navgaiteToDetail(item)">
  13. <image :src="item.thumbnail"></image>
  14. </view>
  15. <view class="myTracks-item-content" @click.stop="navgaiteToDetail(item)">
  16. <view class="myTracks-item-title">
  17. {{ item.goodsName }}
  18. <view class="myTracks-item-title-desc"> </view>
  19. </view>
  20. <view class="myTracks-item-price">
  21. ¥{{ item.price | unitPrice }}
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="myTracks-divider"></view>
  27. </view>
  28. <uni-load-more :status="loadStatus"></uni-load-more>
  29. </div>
  30. <view v-if="editFlag">
  31. <view class="myTracks-action-placeholder"></view>
  32. <view class="myTracks-action">
  33. <view class="myTracks-action-check">
  34. <u-checkbox-group>
  35. <u-checkbox v-model="allChecked" v-if="editFlag" active-color="#ff6b35" style="margin-right: 10rpx" @change="checkedAllitem"></u-checkbox>
  36. 全选
  37. </u-checkbox-group>
  38. </view>
  39. <view>
  40. <u-button type="warning" plain="true" @click="delAllTracks" class="myTracks-action-btn">
  41. 删除
  42. </u-button>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import { myTrackList, deleteHistoryListId } from "@/api/members.js";
  50. export default {
  51. data() {
  52. return {
  53. editFlag: false, //是否编辑
  54. allChecked: false, //是否全选
  55. loadStatus: "more", //底部下拉加载状态
  56. whetherEmpty: false, //是否数据为空
  57. params: {
  58. pageNumber: 1,
  59. pageSize: 10,
  60. },
  61. trackList: [], //足迹列表
  62. };
  63. },
  64. /**
  65. * 滑到底部加载下一页数据
  66. */
  67. onReachBottom() {
  68. if (this.loadStatus != "noMore") {
  69. this.params.pageNumber++;
  70. this.getList();
  71. }
  72. },
  73. onLoad() {
  74. this.getList();
  75. },
  76. methods: {
  77. /**
  78. * 导航到店铺
  79. */
  80. navgaiteToStore(val) {
  81. uni.navigateTo({
  82. url: "/pages/product/shopPage?id=" + val.storeId,
  83. });
  84. },
  85. /**
  86. * 设置右侧导航栏文本
  87. */
  88. setStyle(text) {
  89. //导航按钮文本设置
  90. let pages = getCurrentPages();
  91. let page = pages[pages.length - 1];
  92. // #ifdef APP-PLUS
  93. let currentWebview = page.$getAppWebview();
  94. let titleNView = currentWebview.getStyle().titleNView;
  95. titleNView.buttons[0].text = text;
  96. if (text == "完成") {
  97. this.trackList.forEach((key) => {
  98. key.history.forEach((item) => {
  99. this.$set(item, "___isDel", false);
  100. });
  101. });
  102. }
  103. currentWebview.setStyle({
  104. titleNView: titleNView,
  105. });
  106. // #endif
  107. // #ifdef H5
  108. // h5 临时方案
  109. document.getElementsByClassName("uni-btn-icon")[1].innerText = text;
  110. // #endif
  111. },
  112. /**
  113. * 跳转详情
  114. */
  115. navgaiteToDetail(item) {
  116. uni.navigateTo({
  117. url: "/pages/product/goods?id=" + item.id + "&goodsId=" + item.goodsId,
  118. });
  119. },
  120. /**
  121. * 获取我的足迹列表
  122. */
  123. getList() {
  124. uni.showLoading({
  125. title: "加载中",
  126. });
  127. myTrackList(this.params).then((res) => {
  128. uni.stopPullDownRefresh();
  129. uni.hideLoading();
  130. if (res.statusCode == 200) {
  131. res.data.result &&
  132. res.data.result.forEach((item) => {
  133. item.___isDel = false;
  134. });
  135. let data = res.data.result;
  136. if (data.total == 0) {
  137. this.whetherEmpty = true;
  138. } else if (data.total < 10) {
  139. this.loadStatus = "noMore";
  140. this.trackList.push(...data);
  141. } else {
  142. this.trackList.push(...data);
  143. if (data.length < 10) this.loadStatus = "noMore";
  144. }
  145. }
  146. });
  147. },
  148. /**
  149. * 点击后判断是不是全选
  150. */
  151. changeChecked(val) {
  152. const isCheckedAll = this.trackList.every((key) => {
  153. return key.___isDel == val.___isDel;
  154. });
  155. this.allChecked = isCheckedAll;
  156. },
  157. /**
  158. * 点击全选按钮
  159. */
  160. checkedAllitem() {
  161. //全选按钮
  162. this.trackList.forEach((key) => {
  163. this.$set(key, "___isDel", this.allChecked);
  164. });
  165. },
  166. /**
  167. * 删除足迹
  168. */
  169. delAllTracks() {
  170. let way = [];
  171. this.trackList.forEach((key) => {
  172. if (key.___isDel) {
  173. way.push(key.goodsId);
  174. }
  175. });
  176. if (way.length == 0) return false;
  177. deleteHistoryListId(way).then((res) => {
  178. if (res.data.code == 200) {
  179. this.trackList = [];
  180. this.allChecked = false;
  181. this.getList();
  182. } else {
  183. uni.showToast({
  184. title: res.data.message,
  185. duration: 2000,
  186. icon: "none",
  187. });
  188. }
  189. });
  190. },
  191. },
  192. /**
  193. * 右侧标签栏切换
  194. */
  195. onNavigationBarButtonTap(e) {
  196. if (!this.editFlag) {
  197. this.setStyle("完成");
  198. } else {
  199. this.setStyle("编辑");
  200. }
  201. this.editFlag = !this.editFlag;
  202. },
  203. };
  204. </script>
  205. <style lang="scss" scoped>
  206. .myTracks {
  207. width: 100%;
  208. padding-top: 2rpx;
  209. }
  210. .myTracks-title {
  211. width: 100%;
  212. height: 110rpx;
  213. padding-left: 20rpx;
  214. font-size: 28rpx;
  215. color: #666;
  216. font-weight: bold;
  217. background-color: #fff;
  218. align-items: center;
  219. display: -webkit-box;
  220. display: -webkit-flex;
  221. display: flex;
  222. }
  223. .myTracks-items {
  224. padding-top: 2rpx;
  225. align-items: center;
  226. display: -webkit-box;
  227. display: -webkit-flex;
  228. display: flex;
  229. flex-direction: column;
  230. }
  231. .myTracks-item {
  232. width: 100%;
  233. height: 226rpx;
  234. padding-left: 20rpx;
  235. padding-right: 20rpx;
  236. margin-bottom: 2rpx;
  237. // border-radius: 6/@px;
  238. background-color: #fff;
  239. position: relative;
  240. align-items: center;
  241. display: -webkit-box;
  242. display: -webkit-flex;
  243. display: flex;
  244. }
  245. .myTracks-item-img {
  246. margin-right: 20rpx;
  247. border-radius: 8rpx;
  248. image {
  249. width: 130rpx;
  250. height: 130rpx;
  251. border-radius: 8rpx;
  252. }
  253. }
  254. .myTracks-item-title {
  255. font-size: 28rpx;
  256. color: #333;
  257. }
  258. .myTracks-item-title-desc {
  259. font-size: 28rpx;
  260. color: #999;
  261. }
  262. .myTracks-item-price {
  263. font-size: 28rpx;
  264. color: $light-color;
  265. padding: 10rpx 0 0 0;
  266. }
  267. .myTracks-action-btn {
  268. width: 130rpx;
  269. height: 60rpx;
  270. line-height: 60rpx;
  271. }
  272. .myTracks-divider {
  273. width: 100%;
  274. height: 20rpx;
  275. }
  276. .myTracks-action-placeholder {
  277. height: 110rpx;
  278. }
  279. .myTracks-action-check {
  280. align-items: center;
  281. display: -webkit-box;
  282. display: -webkit-flex;
  283. display: flex;
  284. }
  285. </style>