my-product.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="my-product">
  3. <view class="header">
  4. <view class="title">
  5. 我的商品
  6. </view>
  7. <view style="position: relative;">
  8. <view class="sub-title">全部商品</view>
  9. <view class="release">
  10. <navigator url="/pages/product/product-edit">发布商品</navigator>
  11. </view>
  12. </view>
  13. </view>
  14. <view v-if="products.length===0"
  15. style="margin: 20upx auto;text-align: center; font-size: 28upx;color: #999999;">
  16. 暂未发布任何商品
  17. </view>
  18. <view class="product-list">
  19. <view class="product-item" v-for="product in products" @tap="goToEdit(product.id)">
  20. <view class="product-image">
  21. <image class="image" :src="product.images|imagesFilter" mode="scaleToFill"></image>
  22. </view>
  23. <view>
  24. <view class="row row-1">
  25. <text class="title"><text class="sxzg-icon">省心直供</text>{{product.name}}</text>
  26. </view>
  27. <view class="row row-2">
  28. <text class="org-price">¥{{product.org_price}}</text>
  29. </view>
  30. <view class="row row-3">
  31. <text class="sxj-icon">省心价</text>
  32. <text class="price">¥{{product.price}}</text>
  33. </view>
  34. <view class="row row-4">
  35. <text>发布日期:</text>
  36. <text class="time">{{product.createtime|datetimeFilter}}</text>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. page: 1,
  48. pageLoading: false,
  49. products: []
  50. }
  51. },
  52. onLoad() {
  53. this.getProductData();
  54. },
  55. onPageScroll(e) {
  56. const query = uni.createSelectorQuery();
  57. query.select("#my-product").boundingClientRect(data => {
  58. if (e.scrollTop > data.height - uni.getSystemInfoSync().windowHeight * 2) {
  59. this.getProductData();
  60. }
  61. }).exec();
  62. },
  63. onPullDownRefresh() {
  64. this.refresh();
  65. },
  66. methods: {
  67. getProductData() {
  68. return new Promise((resolve, reject) => {
  69. this.$http.get({
  70. url: "/product/my",
  71. data: {
  72. limit: 10,
  73. page: this.page,
  74. },
  75. success: (res) => {
  76. this.products = [...this.products, ...res.data.data.rows];
  77. this.page++;
  78. this.pageLoading = false;
  79. resolve(res)
  80. },
  81. fail: (err) => {
  82. reject(err)
  83. }
  84. })
  85. })
  86. },
  87. goToEdit(id) {
  88. uni.navigateTo({
  89. url: "/pages/product/product-edit?id=" + id
  90. })
  91. },
  92. refresh() {
  93. this.page = 1;
  94. this.products = [];
  95. this.getProductData()
  96. .then(uni.stopPullDownRefresh())
  97. .catch(uni.stopPullDownRefresh());
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss" scoped>
  103. .my-product {
  104. overflow: hidden;
  105. }
  106. .header {
  107. margin: 20upx;
  108. background: white;
  109. text-align: center;
  110. border-radius: 20upx;
  111. padding-bottom: 10upx;
  112. .title {
  113. height: 100upx;
  114. font-size: 32upx;
  115. line-height: 100upx;
  116. // font-weight: bold;
  117. }
  118. .sub-title {
  119. font-size: 28upx;
  120. color: #999999;
  121. }
  122. .release {
  123. position: absolute;
  124. right: 20upx;
  125. font-size: 24upx;
  126. bottom: 4upx;
  127. }
  128. }
  129. .product-list {
  130. .product-item {
  131. display: flex;
  132. background: white;
  133. margin: 20upx;
  134. padding: 20upx;
  135. .product-image {
  136. width: 180upx;
  137. height: 180upx;
  138. margin-right: 20upx;
  139. }
  140. .image {
  141. width: 180upx;
  142. height: 180upx;
  143. background: #EEEEEE;
  144. }
  145. }
  146. .sxzg-icon {
  147. color: $primary-color;
  148. font-size: 16rpx;
  149. width: 80rpx;
  150. text-align: center;
  151. line-height: normal;
  152. border: 2rpx solid $primary-color;
  153. border-radius: 20rpx;
  154. display: inline-block;
  155. position: relative;
  156. top: -4rpx;
  157. margin-right: 10upx;
  158. // transform: scale(0.9);
  159. }
  160. .title {
  161. font-size: 24rpx;
  162. display: inline-block;
  163. white-space: normal;
  164. display: -webkit-box;
  165. -webkit-box-orient: vertical;
  166. -webkit-line-clamp: 2;
  167. overflow: hidden;
  168. height: 68upx;
  169. }
  170. .row {
  171. // padding: 0 10upx;
  172. }
  173. .row-2 {
  174. display: flex;
  175. justify-content: space-between;
  176. }
  177. .row-3 {
  178. display: flex;
  179. align-items: center;
  180. }
  181. .org-price {
  182. font-size: 26rpx;
  183. color: #cccccc;
  184. }
  185. .org-price {
  186. text-decoration: line-through;
  187. }
  188. .sxj-icon {
  189. background: $primary-color;
  190. color: white;
  191. font-size: 20upx;
  192. padding: 0 5upx;
  193. border-radius: 5upx;
  194. vertical-align: middle;
  195. }
  196. .price {
  197. font-size: 26rpx;
  198. color: $primary-color;
  199. font-weight: bold;
  200. }
  201. .row-4 {
  202. font-size: 24upx;
  203. color: #999999;
  204. }
  205. }
  206. </style>