my-stock.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="page">
  3. <!-- 我的库存 -->
  4. <view class="content-top">
  5. <u-navbar :background="background" back-icon-color="#ffffff" is-fixed>
  6. <u-search placeholder="请输入轮胎规格" v-model="keyword" style="margin-right: 26rpx;" @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" v-for="item in datalist" :key="item.matDescribe">
  19. <view class="list-left">{{item.matDescribe}}</view>
  20. <view class="list-right">{{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: 20, //每页条数
  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. console.log(v)
  86. this.handleGetData();
  87. },
  88. handleFilterBrand: function(v2) {
  89. this.current = v2;
  90. this.currentBrand = this.brandlLst[this.current].brandName;
  91. this.handleGetData();
  92. console.log(arguments);
  93. console.log(this.brandlLst[this.current].brandName)
  94. },
  95. handleGetFilterData: function() {
  96. var _this = this;
  97. request({
  98. url: '/baseReq/getBrandListByStoreId',
  99. method: 'Post',
  100. data: {
  101. storeId: 1000,
  102. userId: "1"
  103. }
  104. }).then(res => {
  105. if (res.data.code == 0) {
  106. console.log(res)
  107. // 获取品牌列表
  108. _this.brandlLst = res.data.data;
  109. _this.brandlLst.unshift({
  110. brandName: "全部",
  111. brandCode: "all"
  112. });
  113. } else {
  114. console.log(res)
  115. uni.showToast({
  116. title: res.data.msg,
  117. icon: "none",
  118. duration: _this.$store.state.showToastDuration
  119. });
  120. }
  121. }).catch(err => {
  122. console.log(err)
  123. uni.showToast({
  124. title: _this.$store.state.showServerErrorMsg,
  125. icon: "none",
  126. duration: _this.$store.state.showToastDuration
  127. });
  128. this.currentPage -= 1;
  129. }).finally(() => {
  130. setTimeout(() => {
  131. uni.hideLoading();
  132. this.loading = false;
  133. }, 1000)
  134. });
  135. },
  136. // 获取数据
  137. handleGetData() {
  138. uni.showLoading({
  139. title: "加载中"
  140. });
  141. var _this = this;
  142. request({
  143. url: '/homepage/storeGetStock',
  144. method: 'post',
  145. data: {
  146. storeId: "990289",
  147. userId: "1",
  148. current: _this.currentPage,
  149. pageSize: _this.pageSize,
  150. brandCode: _this.currentBrand,
  151. specKey: _this.keyword
  152. }
  153. }).then(res => {
  154. if (res.data.code == 0) {
  155. console.log(res)
  156. // 获取数据列表
  157. if (_this.first == 0) {
  158. _this.datalist = res.data.data;
  159. _this.total = parseInt(res.data.data.count);
  160. _this.totalPage = Math.ceil(_this.total / _this.pageSize);
  161. console.log(_this.totalPage)
  162. } else {
  163. console.log(_this.currentPage);
  164. console.log(_this.totalPage)
  165. _this.datalist = _this.datalist.concat(res.data.data);
  166. console.log(_this.datalist.length)
  167. };
  168. // 分页
  169. if (_this.currentPage < _this.totalPage) {
  170. _this.loadStatus = "loadmore"
  171. } else {
  172. console.log("nomore")
  173. _this.loadStatus = "nomore"
  174. }
  175. } else {
  176. console.log(res)
  177. uni.showToast({
  178. title: res.data.msg,
  179. icon: "none",
  180. duration: _this.$store.state.showToastDuration
  181. });
  182. }
  183. }).catch(err => {
  184. console.log(err)
  185. uni.showToast({
  186. title: _this.$store.state.showServerErrorMsg,
  187. icon: "none",
  188. duration: _this.$store.state.showToastDuration
  189. });
  190. this.currentPage -= 1;
  191. }).finally(() => {
  192. setTimeout(() => {
  193. uni.hideLoading();
  194. this.loading = false;
  195. }, 1000)
  196. });
  197. },
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .page{
  203. width: 100%;
  204. height: 100%;
  205. }
  206. .content-top {
  207. background-color: #0094FE;
  208. padding-bottom: 119rpx;
  209. }
  210. .scroll-view-container {
  211. margin-top: -106rpx;
  212. height: calc(100% - 206rpx);
  213. }
  214. .content-center {
  215. width: 712rpx;
  216. margin: 0 auto 0 auto;
  217. border-radius: 20rpx;
  218. background-color: #FFFFFF;
  219. padding: 26rpx;
  220. .list-row {
  221. justify-content: space-between;
  222. border-bottom: 1px solid #E8E8E8;
  223. padding: 32rpx 0;
  224. .list-right {
  225. color: #149EE2;
  226. text-decoration: underline;
  227. }
  228. }
  229. .list-row.list-title {
  230. padding-top: 0;
  231. font-weight: 600;
  232. .list-right {
  233. color: #4D4D4D;
  234. font-weight: 400;
  235. text-decoration: none;
  236. }
  237. }
  238. }
  239. </style>