my-stock.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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="$t('stock.tips')" v-model="keyword" :action-text="$t('unified.search')" 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">{{$t('stock.specifications')}}</view>
  15. <view class="list-right">{{$t('stock.stock')}}</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="$t('unified.nodata')" 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: this.$t('stock.tabs_a')
  46. }],
  47. // 分页信息
  48. first: 0,
  49. pageSize: 10, //每页条数
  50. currentPage: 1, //当前页码
  51. totalPage: 0, //总页码数
  52. loadStatus: "loadmore",
  53. loadText: {
  54. loadmore: this.$t('stock.loadmore'),
  55. loading: this.$t('stock.loading'),
  56. nomore: this.$t('stock.nomore')
  57. },
  58. // 数据信息
  59. datalist: []
  60. }
  61. },
  62. onLoad() {
  63. uni.showLoading({
  64. title: this.$t('unified.Loading')
  65. });
  66. this.handleGetFilterData();
  67. this.handleGetData();
  68. },
  69. methods: {
  70. scrollBottom(v) {
  71. if (this.loadStatus == "loadmore") {
  72. this.loadStatus = 'loading';
  73. uni.showLoading({
  74. title: this.$t('unified.Loading')
  75. });
  76. // 模拟数据加载
  77. this.first += 1;
  78. this.currentPage += 1;
  79. this.handleGetData();
  80. this.loadStatus = 'loadmore';
  81. }
  82. },
  83. handleSearch: function(v) {
  84. this.first = 0;
  85. this.currentPage = 1;
  86. this.handleGetData();
  87. },
  88. handleFilterBrand: function(v2) {
  89. this.first = 0;
  90. this.currentPage = 1;
  91. this.current = v2;
  92. this.currentBrand = this.brandlLst[this.current].brandCode;
  93. this.handleGetData();
  94. },
  95. handleGetFilterData: function() {
  96. var _this = this;
  97. request({
  98. url: '/baseReq/getBrandListByStoreId',
  99. method: 'Post',
  100. data: {
  101. storeId: this.$store.state.storeInfo.storeId,
  102. userId: this.$store.state.storeInfo.userId
  103. }
  104. }).then(res => {
  105. if (res.data.code == 0) {
  106. // 获取品牌列表
  107. _this.brandlLst = res.data.data;
  108. _this.brandlLst.unshift({
  109. brandName: _this.$t('stock.tabs_a'),
  110. brandCode: "all"
  111. });
  112. } else {
  113. uni.showToast({
  114. title: res.data.msg,
  115. icon: "none",
  116. duration: _this.$store.state.showToastDuration
  117. });
  118. }
  119. }).catch(err => {
  120. uni.showToast({
  121. title: _this.$store.state.showServerErrorMsg,
  122. icon: "none",
  123. duration: _this.$store.state.showToastDuration
  124. });
  125. this.currentPage -= 1;
  126. }).finally(() => {
  127. setTimeout(() => {
  128. uni.hideLoading();
  129. this.loading = false;
  130. }, 1000)
  131. });
  132. },
  133. // 获取数据
  134. handleGetData() {
  135. uni.showLoading({
  136. title: this.$t('unified.Loading')
  137. });
  138. var _this = this;
  139. request({
  140. url: '/homepage/storeGetStock',
  141. method: 'post',
  142. data: {
  143. storeId: this.$store.state.storeInfo.storeId,
  144. userId: this.$store.state.storeInfo.userId,
  145. current: _this.currentPage,
  146. pageSize: _this.pageSize,
  147. brandCode: _this.currentBrand == "all" ? "" : _this.currentBrand,
  148. specKey: _this.keyword
  149. }
  150. }).then(res => {
  151. if (res.data.code == 0) {
  152. // 获取数据列表
  153. if (_this.first == 0) {
  154. _this.datalist = [];
  155. _this.datalist = _this.datalist.concat(res.data.data);
  156. _this.total = parseInt(res.data.count);
  157. _this.totalPage = Math.ceil(_this.total / _this.pageSize);
  158. } else {
  159. _this.datalist = _this.datalist.concat(res.data.data);
  160. };
  161. // 分页
  162. if (_this.currentPage < _this.totalPage) {
  163. _this.loadStatus = "loadmore"
  164. } else {
  165. _this.loadStatus = "nomore"
  166. }
  167. } else {
  168. uni.showToast({
  169. title: res.data.msg,
  170. icon: "none",
  171. duration: _this.$store.state.showToastDuration
  172. });
  173. }
  174. }).catch(err => {
  175. uni.showToast({
  176. title: _this.$store.state.showServerErrorMsg,
  177. icon: "none",
  178. duration: _this.$store.state.showToastDuration
  179. });
  180. this.currentPage -= 1;
  181. }).finally(() => {
  182. setTimeout(() => {
  183. uni.hideLoading();
  184. this.loading = false;
  185. }, 1000)
  186. });
  187. },
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .page {
  193. width: 100%;
  194. height: 100%;
  195. }
  196. .content-top {
  197. background-color: #0094FE;
  198. padding-bottom: 119rpx;
  199. }
  200. .scroll-view-container {
  201. margin-top: -106rpx;
  202. height: calc(100% - 206rpx);
  203. }
  204. .content-center {
  205. width: 712rpx;
  206. margin: 0 auto 0 auto;
  207. border-radius: 20rpx;
  208. background-color: #FFFFFF;
  209. padding: 26rpx;
  210. .list-row {
  211. justify-content: space-between;
  212. border-bottom: 1px solid #E8E8E8;
  213. padding: 32rpx 0;
  214. .list-right {
  215. color: #149EE2;
  216. text-decoration: underline;
  217. }
  218. }
  219. .list-row.list-title {
  220. padding-top: 0;
  221. font-weight: 600;
  222. .list-right {
  223. color: #4D4D4D;
  224. font-weight: 400;
  225. text-decoration: none;
  226. }
  227. }
  228. }
  229. </style>