index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <view class="one_1">{{shopInfo.name||'店铺暂无'}}</view>
  5. <view class="one_2">电话:{{shopInfo.tel||'暂无'}}</view>
  6. </view>
  7. <view class="two">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  9. <view class="list-scroll-view">
  10. <view class="two_1">
  11. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  12. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''"
  13. mode="aspectFill">
  14. </image>
  15. <view class="name textOver">{{item.name||'暂无'}}</view>
  16. <view class="other">
  17. <view class="left">¥{{item.money||'暂无'}}</view>
  18. <view class="right">销量:{{item.sell_num||'0'}}</view>
  19. </view>
  20. </view>
  21. <view class="is_bottom" v-if="is_bottom">
  22. <text>{{config.bottom_title}}</text>
  23. </view>
  24. </view>
  25. </view>
  26. </scroll-view>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. data() {
  33. return {
  34. // 系统设置
  35. config: {},
  36. user: {},
  37. shopInfo: {},
  38. id: '',
  39. searchInfo: {},
  40. list: [],
  41. total: 0,
  42. skip: 0,
  43. limit: 6,
  44. page: 0,
  45. // 数据是否触底
  46. is_bottom: false,
  47. scrollTop: 0,
  48. }
  49. },
  50. onLoad: function(e) {
  51. const that = this;
  52. that.$set(that, `id`, e.id || '');
  53. that.searchToken();
  54. that.searchConfig();
  55. },
  56. onPullDownRefresh: async function() {
  57. const that = this;
  58. that.clearPage();
  59. await that.search();
  60. uni.stopPullDownRefresh();
  61. },
  62. methods: {
  63. searchConfig() {
  64. const that = this;
  65. try {
  66. const res = uni.getStorageSync('config');
  67. if (res) that.$set(that, `config`, res);
  68. } catch (e) {
  69. uni.showToast({
  70. title: err.errmsg,
  71. icon: 'error',
  72. duration: 2000
  73. });
  74. }
  75. },
  76. searchToken() {
  77. const that = this;
  78. try {
  79. const res = uni.getStorageSync('token');
  80. if (res) {
  81. that.$set(that, `user`, res);
  82. that.clearPage();
  83. that.search();
  84. }
  85. } catch (e) {
  86. uni.showToast({
  87. title: err.errmsg,
  88. icon: 'error',
  89. duration: 2000
  90. });
  91. }
  92. },
  93. async search() {
  94. const that = this;
  95. let user = that.user;
  96. let info = {
  97. skip: that.skip,
  98. limit: that.limit,
  99. supplier_id: that.id,
  100. is_use: '0'
  101. };
  102. let res;
  103. res = await that.$api(`/User/${that.id}`, 'GET', {});
  104. if (res.errcode === 0) that.$set(that, `shopInfo`, res.data);
  105. res = await that.$api(`/Good`, 'GET', {
  106. ...info,
  107. ...that.searchInfo
  108. });
  109. if (res.errcode === 0) {
  110. let list = [...that.list, ...res.data];
  111. for (let val of list) {
  112. const specs = await that.$api(`/Specs`, 'GET', {
  113. goods: val._id
  114. });
  115. if (specs.errcode == 0) {
  116. const arr = specs.data.sort((a, b) => {
  117. return a.money - b.money
  118. })
  119. val.money = arr[0].money
  120. }
  121. }
  122. that.$set(that, `list`, list);
  123. that.$set(that, `total`, res.total)
  124. } else {
  125. uni.showToast({
  126. title: res.errmsg,
  127. icon: 'none'
  128. })
  129. }
  130. },
  131. // 购买
  132. toBuy(e) {
  133. const that = this;
  134. uni.navigateTo({
  135. url: `/pagesGoods/index/index?id=${e.id||e._id}`
  136. })
  137. },
  138. // 分页
  139. toPage(e) {
  140. const that = this;
  141. let list = that.list;
  142. let limit = that.limit;
  143. if (that.total > list.length) {
  144. uni.showLoading({
  145. title: '加载中',
  146. mask: true
  147. })
  148. let page = that.page + 1;
  149. that.$set(that, `page`, page)
  150. let skip = page * limit;
  151. that.$set(that, `skip`, skip)
  152. that.search();
  153. uni.hideLoading();
  154. } else that.$set(that, `is_bottom`, true)
  155. },
  156. // 触底
  157. toScroll(e) {
  158. const that = this;
  159. let up = that.scrollTop;
  160. that.$set(that, `scrollTop`, e.detail.scrollTop);
  161. let num = Math.sign(up - e.detail.scrollTop);
  162. if (num == 1) that.$set(that, `is_bottom`, false);
  163. },
  164. // 输入框
  165. toInput(e) {
  166. const that = this;
  167. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  168. else that.$set(that, `searchInfo`, {})
  169. that.clearPage();
  170. that.search();
  171. },
  172. // 清空列表
  173. clearPage() {
  174. const that = this;
  175. that.$set(that, `list`, [])
  176. that.$set(that, `skip`, 0)
  177. that.$set(that, `limit`, 6)
  178. that.$set(that, `page`, 0)
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. .content {
  185. display: flex;
  186. flex-direction: column;
  187. width: 100vw;
  188. height: 100vh;
  189. .one {
  190. padding: 2vw;
  191. background-color: var(--f3CColor);
  192. color: var(--mainColor);
  193. .one_1 {
  194. font-size: var(--font16Size);
  195. font-weight: 600;
  196. }
  197. .one_2 {
  198. padding: 2vw 0;
  199. font-size: var(--font14Size);
  200. }
  201. }
  202. .two {
  203. position: relative;
  204. flex-grow: 1;
  205. background-color: var(--f9Color);
  206. .two_1 {
  207. display: flex;
  208. justify-content: space-between;
  209. flex-wrap: wrap;
  210. padding: 2vw;
  211. .list {
  212. display: flex;
  213. flex-direction: column;
  214. justify-content: inherit;
  215. width: 43vw;
  216. padding: 2vw;
  217. margin: 0 0 2vw 0;
  218. border-radius: 10px;
  219. background-color: var(--mainColor);
  220. .image {
  221. width: 100%;
  222. height: 40vw;
  223. border-top-right-radius: 10px;
  224. border-top-left-radius: 10px;
  225. }
  226. .name {
  227. font-size: var(--font14Size);
  228. }
  229. .other {
  230. padding: 1vw 0 0 0;
  231. display: flex;
  232. justify-content: space-between;
  233. .left {
  234. font-size: var(--font14Size);
  235. color: var(--fF0Color);
  236. }
  237. .right {
  238. font-size: var(--font12Size);
  239. color: var(--f85Color);
  240. }
  241. }
  242. }
  243. }
  244. }
  245. }
  246. .scroll-view {
  247. position: absolute;
  248. top: 0;
  249. left: 0;
  250. right: 0;
  251. bottom: 0;
  252. .list-scroll-view {
  253. display: flex;
  254. flex-direction: column;
  255. }
  256. }
  257. .is_bottom {
  258. width: 100%;
  259. text-align: center;
  260. text {
  261. padding: 2vw 0;
  262. display: inline-block;
  263. color: var(--f85Color);
  264. font-size: var(--font14Size);
  265. }
  266. }
  267. </style>