index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. <error-pop
  45. v-model="actionPop.errorShow"
  46. isCenter
  47. cancelBtnText="取消"
  48. confirmBtnText="确定"
  49. @close="actionPop.errorShow = false"
  50. @confirm="submit"
  51. :content="actionPop.errorText"
  52. ></error-pop>
  53. </view>
  54. </template>
  55. <script>
  56. import checkItem from "./components/check-item.vue";
  57. import errorPop from "@/components/error-pop/error-pop.vue";
  58. import {
  59. taskStocktakingList,
  60. startTask,
  61. taskComplete,
  62. taskStocktakingDetail,
  63. } from "@/common/request/apis/inventoryTask";
  64. import { taskStatusList } from "../inventory-task/utils/index.js";
  65. export default {
  66. components: {
  67. checkItem,
  68. errorPop,
  69. },
  70. data() {
  71. return {
  72. offsetTop: 0,
  73. tabList: taskStatusList,
  74. query: {
  75. number: "",
  76. status: "",
  77. },
  78. pageNum: 1,
  79. pageSize: 10,
  80. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  81. list: [],
  82. activeTaskId: null,
  83. actionPop: {
  84. // 警告提示弹框状态
  85. errorShow: false,
  86. submitActionFlag: false,
  87. errorText: "是否提交盘点?",
  88. },
  89. };
  90. },
  91. onLoad() {
  92. let systemInfo = uni.getSystemInfoSync();
  93. let statusBarHeight = systemInfo.statusBarHeight;
  94. this.offsetTop = statusBarHeight + 40;
  95. // 初始化数据
  96. this.loadData();
  97. },
  98. onPullDownRefresh() {
  99. // 下拉刷新
  100. this.onRefresh();
  101. },
  102. onReachBottom() {
  103. // 触底加载更多
  104. this.onLoadMore();
  105. },
  106. methods: {
  107. async onRefresh() {
  108. try {
  109. await this.loadData(true);
  110. } finally {
  111. uni.stopPullDownRefresh();
  112. }
  113. },
  114. async onLoadMore() {
  115. if (this.loadStatus !== "loadmore") return;
  116. this.loadStatus = "loading";
  117. try {
  118. await this.loadData();
  119. } catch (e) {
  120. this.loadStatus = "loadmore";
  121. }
  122. },
  123. async loadData(isRefresh = false) {
  124. if (isRefresh) {
  125. this.pageNum = 1;
  126. this.list = [];
  127. }
  128. try {
  129. this.loadStatus = "loading";
  130. const pageNum = this.pageNum;
  131. const pageSize = this.pageSize;
  132. const params = {
  133. pageNum,
  134. pageSize,
  135. ...this.query,
  136. };
  137. const res = await taskStocktakingList(params);
  138. const { rows, total } = res.data;
  139. this.list = [...this.list, ...rows];
  140. if (pageNum * pageSize < Number(total)) {
  141. this.pageNum++;
  142. this.loadStatus = "loadmore";
  143. } else {
  144. this.loadStatus = "nomore";
  145. }
  146. } catch (error) {}
  147. },
  148. tabClick({ index }) {
  149. this.query.status = this.tabList[index].value;
  150. this.loadData(true);
  151. },
  152. handleSearch(value) {
  153. this.loadData(true);
  154. },
  155. // 前往盘点任务详情
  156. handleBtnClick(data) {
  157. console.log(11111, data);
  158. // params.id--->任务id params.btnName--->按钮label
  159. const { btnName } = data;
  160. switch (btnName) {
  161. case "详情":
  162. uni.navigateTo({
  163. url: `/pages/inventory-task/taskDetail?id=${data.id}`,
  164. });
  165. break;
  166. case "去盘点":
  167. startTask(data.id).then((res) => {
  168. if (res.code === 200) {
  169. uni.navigateTo({
  170. url: `/pages/inventory-task/detail?id=${data.id}&pageType=1`,
  171. });
  172. } else {
  173. uni.$u.toast(res.data);
  174. }
  175. });
  176. break;
  177. case "去提交":
  178. taskStocktakingDetail(data.id).then((res) => {
  179. console.log("taskStocktakingDetail=======", res);
  180. let { finishCount, materialCount } = res.data;
  181. const a = Number(finishCount || 0);
  182. const b = Number(materialCount || 0);
  183. this.activeTaskId = data.id;
  184. this.actionPop.errorShow = true;
  185. if (a === b) {
  186. // 进度100%
  187. this.actionPop.errorText = "是否提交盘点?";
  188. this.actionPop.submitActionFlag = true;
  189. } else {
  190. this.actionPop.errorText = "尚有货物未完成盘点,请先去盘点";
  191. this.actionPop.submitActionFlag = false;
  192. }
  193. });
  194. break;
  195. }
  196. },
  197. resetErrorPopData() {
  198. this.actionPop.errorShow = false;
  199. this.actionPop.submitActionFlag = false;
  200. this.actionPop.errorShow = "";
  201. },
  202. submit() {
  203. if (this.actionPop.submitActionFlag) {
  204. taskComplete(this.activeTaskId).then((res) => {
  205. this.resetErrorPopData();
  206. if (res.code === 200) {
  207. uni.$u.toast(res.msg);
  208. this.onRefresh();
  209. } else {
  210. uni.$u.toast(res.data);
  211. }
  212. });
  213. } else {
  214. this.resetErrorPopData();
  215. }
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. .check-page {
  222. min-height: 100vh;
  223. background-color: #f0f6fb;
  224. .container_main {
  225. .search-box {
  226. background-color: rgba(191, 200, 219, 0.2);
  227. margin: 0 32rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. border-radius: 8rpx;
  232. ::v-deep .u-search__content {
  233. background-color: transparent !important;
  234. .u-search__content__input {
  235. background-color: transparent !important;
  236. }
  237. }
  238. .scan-icon {
  239. width: 100rpx;
  240. height: 100%;
  241. image {
  242. width: 40rpx;
  243. height: 40rpx;
  244. }
  245. }
  246. }
  247. .content-box {
  248. padding: 24rpx;
  249. &-val {
  250. border-radius: 16rpx 16rpx 0 0;
  251. overflow: hidden;
  252. }
  253. }
  254. }
  255. }
  256. </style>