my-stock.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <view class="page">
  3. <!-- 我的库存 -->
  4. <view class="content-top">
  5. <u-navbar :background="background" back-icon-color="#ffffff" is-fixed :border-bottom="false">
  6. <u-search placeholder="请输入轮胎规格" v-model="keyword" style="margin-right: 26rpx;color: #FFFFFF !important;" @custom="handleSearch"></u-search>
  7. </u-navbar>
  8. <u-tabs ref="tabs" name="brandName" :list="brandlLst" bg-color="#0094FE" active-color="#ffffff" inactive-color="#ffffff"
  9. font-size="30" :current="current" @change="handleFilterBrand"></u-tabs>
  10. </view>
  11. <scroll-view scroll-y @scrolltolower="scrollBottom" class="scroll-view-container">
  12. <view class="content-center">
  13. <view class="list-row u-flex list-title">
  14. <view class="list-left">轮胎规格</view>
  15. <view class="list-right">库存</view>
  16. </view>
  17. <template v-if="datalist&&datalist.length">
  18. <view class="list-row u-flex u-skeleton" v-for="item in datalist" :key="item.matDescribe">
  19. <view class="list-left u-skeleton-rect">{{item.matDescribe}}</view>
  20. <view class="list-right u-skeleton-rect">{{item.stock}}</view>
  21. </view>
  22. </template>
  23. <u-empty v-else text="暂无数据" mode="list"></u-empty>
  24. </view>
  25. <u-loadmore v-if="datalist&&datalist.length" :status="loadStatus" bgColor="#f2f2f2" :load-text="loadText"></u-loadmore>
  26. </scroll-view>
  27. </view>
  28. </template>
  29. <script>
  30. import {
  31. request
  32. } from '@/common/request/request';
  33. require("promise.prototype.finally").shim();
  34. export default {
  35. data() {
  36. return {
  37. background: {
  38. backgroundColor: "#0291FD",
  39. },
  40. current: 0,
  41. // 筛选条件
  42. keyword: "", //搜索规格
  43. currentBrand: "", //选中的品牌
  44. brandlLst: [{
  45. brandName: "全部"
  46. }],
  47. // 分页信息
  48. first: 0,
  49. pageSize: 10, //每页条数
  50. currentPage: 1, //当前页码
  51. totalPage: 0, //总页码数
  52. loadStatus: "loadmore",
  53. loadText: {
  54. loadmore: '轻轻上拉',
  55. loading: '努力加载中',
  56. nomore: '实在没有了'
  57. },
  58. // 数据信息
  59. datalist: []
  60. }
  61. },
  62. onLoad() {
  63. uni.showLoading({
  64. title: "加载中"
  65. });
  66. this.handleGetFilterData();
  67. this.handleGetData();
  68. },
  69. methods: {
  70. scrollBottom(v) {
  71. console.log(v);
  72. if (this.loadStatus == "loadmore") {
  73. this.loadStatus = 'loading';
  74. uni.showLoading({
  75. title: "加载中"
  76. });
  77. // 模拟数据加载
  78. this.first += 1;
  79. this.currentPage += 1;
  80. this.handleGetData();
  81. this.loadStatus = 'loadmore';
  82. }
  83. },
  84. handleSearch: function(v) {
  85. this.first = 0;
  86. this.currentPage = 1;
  87. console.log(v)
  88. this.handleGetData();
  89. },
  90. handleFilterBrand: function(v2) {
  91. this.first = 0;
  92. this.currentPage = 1;
  93. this.current = v2;
  94. this.currentBrand = this.brandlLst[this.current].brandCode;
  95. this.handleGetData();
  96. console.log(arguments);
  97. console.log(this.brandlLst[this.current].brandCode)
  98. },
  99. handleGetFilterData: function() {
  100. var _this = this;
  101. request({
  102. url: '/baseReq/getBrandListByStoreId',
  103. method: 'Post',
  104. data: {
  105. storeId: this.$store.state.storeInfo.storeId,
  106. userId: this.$store.state.storeInfo.userId
  107. }
  108. }).then(res => {
  109. if (res.data.code == 0) {
  110. console.log(res)
  111. // 获取品牌列表
  112. _this.brandlLst = res.data.data;
  113. _this.brandlLst.unshift({
  114. brandName: "全部",
  115. brandCode: "all"
  116. });
  117. } else {
  118. console.log(res)
  119. uni.showToast({
  120. title: res.data.msg,
  121. icon: "none",
  122. duration: _this.$store.state.showToastDuration
  123. });
  124. }
  125. }).catch(err => {
  126. console.log(err)
  127. uni.showToast({
  128. title: _this.$store.state.showServerErrorMsg,
  129. icon: "none",
  130. duration: _this.$store.state.showToastDuration
  131. });
  132. this.currentPage -= 1;
  133. }).finally(() => {
  134. setTimeout(() => {
  135. uni.hideLoading();
  136. this.loading = false;
  137. }, 1000)
  138. });
  139. },
  140. // 获取数据
  141. handleGetData() {
  142. uni.showLoading({
  143. title: "加载中"
  144. });
  145. var _this = this;
  146. request({
  147. url: '/homepage/storeGetStock',
  148. method: 'post',
  149. data: {
  150. storeId: this.$store.state.storeInfo.storeId,
  151. userId: this.$store.state.storeInfo.userId,
  152. current: _this.currentPage,
  153. pageSize: _this.pageSize,
  154. brandCode: _this.currentBrand == "all" ? "" : _this.currentBrand,
  155. specKey: _this.keyword
  156. }
  157. }).then(res => {
  158. if (res.data.code == 0) {
  159. console.log(res)
  160. // 获取数据列表
  161. if (_this.first == 0) {
  162. _this.datalist = [];
  163. _this.datalist = _this.datalist.concat(res.data.data);
  164. _this.total = parseInt(res.data.count);
  165. _this.totalPage = Math.ceil(_this.total / _this.pageSize);
  166. console.log(_this.totalPage)
  167. } else {
  168. console.log(_this.currentPage);
  169. console.log(_this.totalPage)
  170. _this.datalist = _this.datalist.concat(res.data.data);
  171. console.log(_this.datalist.length)
  172. };
  173. // 分页
  174. if (_this.currentPage < _this.totalPage) {
  175. _this.loadStatus = "loadmore"
  176. } else {
  177. console.log("nomore")
  178. _this.loadStatus = "nomore"
  179. }
  180. } else {
  181. console.log(res)
  182. uni.showToast({
  183. title: res.data.msg,
  184. icon: "none",
  185. duration: _this.$store.state.showToastDuration
  186. });
  187. }
  188. }).catch(err => {
  189. console.log(err)
  190. uni.showToast({
  191. title: _this.$store.state.showServerErrorMsg,
  192. icon: "none",
  193. duration: _this.$store.state.showToastDuration
  194. });
  195. this.currentPage -= 1;
  196. }).finally(() => {
  197. setTimeout(() => {
  198. uni.hideLoading();
  199. this.loading = false;
  200. }, 1000)
  201. });
  202. },
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .page {
  208. width: 100%;
  209. height: 100%;
  210. }
  211. .content-top {
  212. background-color: #0094FE;
  213. padding-bottom: 119rpx;
  214. }
  215. .scroll-view-container {
  216. margin-top: -106rpx;
  217. height: calc(100% - 206rpx);
  218. }
  219. .content-center {
  220. width: 712rpx;
  221. margin: 0 auto 0 auto;
  222. border-radius: 20rpx;
  223. background-color: #FFFFFF;
  224. padding: 26rpx;
  225. .list-row {
  226. justify-content: space-between;
  227. border-bottom: 1px solid #E8E8E8;
  228. padding: 32rpx 0;
  229. .list-right {
  230. color: #149EE2;
  231. text-decoration: underline;
  232. }
  233. }
  234. .list-row.list-title {
  235. padding-top: 0;
  236. font-weight: 600;
  237. .list-right {
  238. color: #4D4D4D;
  239. font-weight: 400;
  240. text-decoration: none;
  241. }
  242. }
  243. }
  244. </style>