index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="check-page">
  3. <u-navbar height="40px" title="盘点" bgColor="#fff" autoBack placeholder>
  4. </u-navbar>
  5. <view class="container_main">
  6. <u-sticky :offsetTop="offsetTop" bgColor="#fff">
  7. <view class="search-box">
  8. <u-search
  9. placeholder="请输入单据编号或名称"
  10. shape="square"
  11. v-model="query.number"
  12. :showAction="false"
  13. :clearabled="true"
  14. @search="handleSearch"
  15. @clear="handleSearch"
  16. ></u-search>
  17. </view>
  18. <view class="type-box">
  19. <u-tabs
  20. :list="tabList"
  21. :inactiveStyle="{ color: '#000', fontSize: '28rpx' }"
  22. :activeStyle="{ color: '#000', fontSize: '28rpx' }"
  23. lineColor="#0256FF"
  24. lineWidth="66rpx"
  25. :scrollable="false"
  26. @click="tabClick"
  27. >
  28. </u-tabs>
  29. </view>
  30. </u-sticky>
  31. <view class="content-box">
  32. <view class="content-box-val">
  33. <check-item
  34. v-for="item in list"
  35. :key="item.id"
  36. :info="item"
  37. @btnClick="handleBtnClick"
  38. ></check-item>
  39. </view>
  40. <!-- 加载更多 -->
  41. <u-loadmore :status="loadStatus" @loadmore="onLoadMore" />
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <script>
  47. import checkItem from "./components/check-item.vue";
  48. import {
  49. taskStocktakingList,
  50. startTask,
  51. } from "@/common/request/apis/inventoryTask";
  52. import { taskStatusList } from "../inventory-task/utils/index.js";
  53. export default {
  54. components: {
  55. checkItem,
  56. },
  57. data() {
  58. return {
  59. offsetTop: 0,
  60. tabList: taskStatusList,
  61. query: {
  62. number: "",
  63. status: "",
  64. },
  65. pageNum: 1,
  66. pageSize: 10,
  67. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  68. list: [],
  69. };
  70. },
  71. onLoad() {
  72. let systemInfo = uni.getSystemInfoSync();
  73. let statusBarHeight = systemInfo.statusBarHeight;
  74. this.offsetTop = statusBarHeight + 40;
  75. // 初始化数据
  76. this.loadData();
  77. },
  78. onPullDownRefresh() {
  79. // 下拉刷新
  80. this.onRefresh();
  81. },
  82. onReachBottom() {
  83. // 触底加载更多
  84. this.onLoadMore();
  85. },
  86. methods: {
  87. async onRefresh() {
  88. try {
  89. await this.loadData(true);
  90. } finally {
  91. uni.stopPullDownRefresh();
  92. }
  93. },
  94. async onLoadMore() {
  95. if (this.loadStatus !== "loadmore") return;
  96. this.loadStatus = "loading";
  97. try {
  98. await this.loadData();
  99. } catch (e) {
  100. this.loadStatus = "loadmore";
  101. }
  102. },
  103. async loadData(isRefresh = false) {
  104. if (isRefresh) {
  105. this.pageNum = 1;
  106. this.list = [];
  107. }
  108. try {
  109. this.loadStatus = "loading";
  110. const pageNum = this.pageNum;
  111. const pageSize = this.pageSize;
  112. const params = {
  113. pageNum,
  114. pageSize,
  115. ...this.query,
  116. };
  117. const res = await taskStocktakingList(params);
  118. const { rows, total } = res.data;
  119. this.list = [...this.list, ...rows];
  120. if (pageNum * pageSize < Number(total)) {
  121. this.pageNum++;
  122. this.loadStatus = "loadmore";
  123. } else {
  124. this.loadStatus = "nomore";
  125. }
  126. } catch (error) {}
  127. },
  128. tabClick({ index }) {
  129. this.query.status = this.tabList[index].value;
  130. this.loadData(true);
  131. },
  132. handleSearch(value) {
  133. this.loadData(true);
  134. },
  135. // 前往盘点任务详情
  136. handleBtnClick(data) {
  137. console.log(11111, data);
  138. // params.id--->任务id params.btnName--->按钮label
  139. const { btnName } = data;
  140. switch (btnName) {
  141. case "详情":
  142. uni.navigateTo({
  143. url: `/pages/inventory-task/taskDetail?id=${data.id}`,
  144. });
  145. break;
  146. case "去盘点":
  147. startTask(data.id).then((res) => {
  148. if (res.code === 200) {
  149. uni.navigateTo({
  150. url: `/pages/inventory-task/detail?id=${data.id}&pageType=1`,
  151. });
  152. } else {
  153. uni.$u.toast(res.data);
  154. }
  155. });
  156. break;
  157. case "去提交":
  158. break;
  159. }
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="scss" scoped>
  165. .check-page {
  166. min-height: 100vh;
  167. background-color: #f0f6fb;
  168. .container_main {
  169. .search-box {
  170. background-color: rgba(191, 200, 219, 0.2);
  171. margin: 0 32rpx;
  172. display: flex;
  173. align-items: center;
  174. justify-content: space-between;
  175. border-radius: 8rpx;
  176. ::v-deep .u-search__content {
  177. background-color: transparent !important;
  178. .u-search__content__input {
  179. background-color: transparent !important;
  180. }
  181. }
  182. .scan-icon {
  183. width: 100rpx;
  184. height: 100%;
  185. image {
  186. width: 40rpx;
  187. height: 40rpx;
  188. }
  189. }
  190. }
  191. .content-box {
  192. padding: 24rpx;
  193. &-val {
  194. border-radius: 16rpx 16rpx 0 0;
  195. overflow: hidden;
  196. }
  197. }
  198. }
  199. }
  200. </style>