footprint.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <view class="container">
  3. <view class="no-footprint" v-if="footprintList.length <= 0">
  4. <view class="c">
  5. <text>没有浏览足迹</text>
  6. </view>
  7. </view>
  8. <view class="footprint" v-if="footprintList.length > 0">
  9. <view class="day-item" v-for="(item, index) in footprintList" :key="index">
  10. <view class="day-hd" v-if="item.length > 0">{{ item[0].addDate }}</view>
  11. <view class="day-list" v-if="item.length > 0">
  12. <view
  13. class="item"
  14. :data-index="index"
  15. :data-iindex="iindex"
  16. @touchstart="touchStartFun"
  17. @touchend="touchEndFun"
  18. @tap="deleteItem"
  19. v-for="(iitem, iindex) in item"
  20. :key="iindex"
  21. >
  22. <image class="img" :src="iitem.picUrl"></image>
  23. <view class="info">
  24. <view class="name">{{ iitem.name }}</view>
  25. <view class="subtitle">{{ iitem.brief }}</view>
  26. <view class="price">¥{{ iitem.retailPrice }}</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. var util = require('../../../utils/util.js');
  36. var api = require('../../../config/api.js');
  37. var app = getApp();
  38. export default {
  39. data() {
  40. return {
  41. footprintList: [],
  42. page: 1,
  43. limit: 10,
  44. totalPages: 1,
  45. touchStart: '',
  46. touchEnd: '',
  47. iindex: 0,
  48. iitem: {
  49. picUrl: '',
  50. name: '',
  51. brief: '',
  52. retailPrice: ''
  53. }
  54. };
  55. },
  56. onLoad: function (options) {
  57. this.getFootprintList();
  58. },
  59. onReachBottom() {
  60. if (this.totalPages > this.page) {
  61. this.setData({
  62. page: this.page + 1
  63. });
  64. this.getFootprintList();
  65. } else {
  66. uni.showToast({
  67. title: '没有更多用户足迹了',
  68. icon: 'none',
  69. duration: 2000
  70. });
  71. return false;
  72. }
  73. },
  74. onReady: function () {},
  75. onShow: function () {},
  76. onHide: function () {
  77. // 页面隐藏
  78. },
  79. onUnload: function () {
  80. // 页面关闭
  81. },
  82. methods: {
  83. getFootprintList() {
  84. uni.showLoading({
  85. title: '加载中...'
  86. });
  87. let that = this;
  88. util.request(api.FootprintList, {
  89. page: that.page,
  90. limit: that.limit
  91. }).then(function (res) {
  92. if (res.errno === 0) {
  93. let f1 = that.footprintList;
  94. let f2 = res.data.list;
  95. for (let i = 0; i < f2.length; i++) {
  96. f2[i].addDate = f2[i].addTime.substring(0, 10);
  97. let last = f1.length - 1;
  98. if (last >= 0 && f1[last][0].addDate === f2[i].addDate) {
  99. f1[last].push(f2[i]);
  100. } else {
  101. let tmp = [];
  102. tmp.push(f2[i]);
  103. f1.push(tmp);
  104. }
  105. }
  106. that.setData({
  107. footprintList: f1,
  108. totalPages: res.data.pages
  109. });
  110. }
  111. uni.hideLoading();
  112. });
  113. },
  114. deleteItem(event) {
  115. let that = this;
  116. let index = event.currentTarget.dataset.index;
  117. let iindex = event.currentTarget.dataset.iindex;
  118. let footprintId = this.footprintList[index][iindex].id;
  119. let goodsId = this.footprintList[index][iindex].goodsId;
  120. var touchTime = that.touchEnd - that.touchStart;
  121. console.log(touchTime);
  122. //如果按下时间大于350为长按
  123. if (touchTime > 350) {
  124. uni.showModal({
  125. title: '',
  126. content: '要删除所选足迹?',
  127. success: function (res) {
  128. if (res.confirm) {
  129. util.request(
  130. api.FootprintDelete,
  131. {
  132. id: footprintId
  133. },
  134. 'POST'
  135. ).then(function (res) {
  136. if (res.errno === 0) {
  137. uni.showToast({
  138. title: '删除成功',
  139. icon: 'success',
  140. duration: 2000
  141. });
  142. that.footprintList[index].splice(iindex, 1);
  143. if (that.footprintList[index].length == 0) {
  144. that.footprintList.splice(index, 1);
  145. }
  146. that.setData({
  147. footprintList: that.footprintList
  148. });
  149. }
  150. });
  151. }
  152. }
  153. });
  154. } else {
  155. uni.navigateTo({
  156. url: '/pages/goods/goods?id=' + goodsId
  157. });
  158. }
  159. },
  160. //按下事件开始
  161. touchStartFun: function (e) {
  162. let that = this;
  163. that.setData({
  164. touchStart: e.timeStamp
  165. });
  166. console.log(e.timeStamp + '- touchStart');
  167. },
  168. //按下事件结束
  169. touchEndFun: function (e) {
  170. let that = this;
  171. that.setData({
  172. touchEnd: e.timeStamp
  173. });
  174. console.log(e.timeStamp + '- touchEnd');
  175. }
  176. }
  177. };
  178. </script>
  179. <style>
  180. page {
  181. background: #f4f4f4;
  182. min-height: 100%;
  183. }
  184. .container {
  185. background: #f4f4f4;
  186. min-height: 100%;
  187. width: 100%;
  188. height: auto;
  189. overflow: hidden;
  190. }
  191. .no-footprint {
  192. width: 100%;
  193. height: auto;
  194. margin: 0 auto;
  195. }
  196. .no-footprint .c {
  197. width: 100%;
  198. height: auto;
  199. margin-top: 400rpx;
  200. }
  201. .no-footprint .c text {
  202. margin: 0 auto;
  203. display: block;
  204. width: 258rpx;
  205. height: 29rpx;
  206. line-height: 29rpx;
  207. text-align: center;
  208. font-size: 29rpx;
  209. color: #999;
  210. }
  211. .footprint {
  212. height: auto;
  213. overflow: hidden;
  214. width: 100%;
  215. border-top: 1px solid #e1e1e1;
  216. }
  217. .day-item {
  218. height: auto;
  219. overflow: hidden;
  220. width: 100%;
  221. margin-bottom: 20rpx;
  222. }
  223. .day-hd {
  224. height: 94rpx;
  225. width: 100%;
  226. line-height: 94rpx;
  227. background: #fff;
  228. padding-left: 30rpx;
  229. color: #333;
  230. font-size: 28rpx;
  231. }
  232. .day-list {
  233. width: 100%;
  234. height: auto;
  235. overflow: hidden;
  236. background: #fff;
  237. padding-left: 30rpx;
  238. border-top: 1px solid #e1e1e1;
  239. }
  240. .item {
  241. height: 212rpx;
  242. width: 720rpx;
  243. background: #fff;
  244. padding: 30rpx 30rpx 30rpx 0;
  245. border-bottom: 1px solid #e1e1e1;
  246. }
  247. .item:last-child {
  248. border-bottom: 1px solid #fff;
  249. }
  250. .item .img {
  251. float: left;
  252. width: 150rpx;
  253. height: 150rpx;
  254. }
  255. .item .info {
  256. float: right;
  257. width: 540rpx;
  258. height: 150rpx;
  259. display: flex;
  260. flex-direction: column;
  261. justify-content: center;
  262. padding-left: 20rpx;
  263. }
  264. .item .info .name {
  265. font-size: 28rpx;
  266. color: #333;
  267. line-height: 40rpx;
  268. }
  269. .item .info .subtitle {
  270. margin-top: 8rpx;
  271. font-size: 24rpx;
  272. color: #888;
  273. line-height: 40rpx;
  274. }
  275. .item .info .price {
  276. margin-top: 8rpx;
  277. font-size: 28rpx;
  278. color: #333;
  279. line-height: 40rpx;
  280. }
  281. </style>