index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. startTaskId:null,
  90. };
  91. },
  92. onLoad() {
  93. let systemInfo = uni.getSystemInfoSync();
  94. let statusBarHeight = systemInfo.statusBarHeight;
  95. this.offsetTop = statusBarHeight + 40;
  96. // 初始化数据
  97. this.loadData();
  98. },
  99. onShow() {
  100. if(this.startTaskId) {
  101. let index = this.list.findIndex(item=>item.id == this.startTaskId)
  102. this.list[index].taskStatus = 2
  103. this.startTaskId = null
  104. }
  105. },
  106. onPullDownRefresh() {
  107. // 下拉刷新
  108. this.onRefresh();
  109. },
  110. onReachBottom() {
  111. // 触底加载更多
  112. this.onLoadMore();
  113. },
  114. methods: {
  115. async onRefresh() {
  116. try {
  117. await this.loadData(true);
  118. } finally {
  119. uni.stopPullDownRefresh();
  120. }
  121. },
  122. async onLoadMore() {
  123. if (this.loadStatus !== "loadmore") return;
  124. this.loadStatus = "loading";
  125. try {
  126. await this.loadData();
  127. } catch (e) {
  128. this.loadStatus = "loadmore";
  129. }
  130. },
  131. async loadData(isRefresh = false) {
  132. if (isRefresh) {
  133. this.pageNum = 1;
  134. this.list = [];
  135. }
  136. try {
  137. this.loadStatus = "loading";
  138. const pageNum = this.pageNum;
  139. const pageSize = this.pageSize;
  140. const params = {
  141. pageNum,
  142. pageSize,
  143. ...this.query,
  144. };
  145. const res = await taskStocktakingList(params);
  146. const { rows, total } = res.data;
  147. this.list = [...this.list, ...rows];
  148. if (pageNum * pageSize < Number(total)) {
  149. this.pageNum++;
  150. this.loadStatus = "loadmore";
  151. } else {
  152. this.loadStatus = "nomore";
  153. }
  154. } catch (error) {}
  155. },
  156. tabClick({ index }) {
  157. this.query.status = this.tabList[index].value;
  158. this.loadData(true);
  159. },
  160. handleSearch(value) {
  161. this.loadData(true);
  162. },
  163. // 前往盘点任务详情
  164. handleBtnClick(data) {
  165. console.log(11111, data);
  166. // params.id--->任务id params.btnName--->按钮label
  167. const { btnName } = data;
  168. switch (btnName) {
  169. case "详情":
  170. uni.navigateTo({
  171. url: `/pages/inventory-task/taskDetail?id=${data.id}`,
  172. });
  173. break;
  174. case "去盘点":
  175. startTask(data.id).then((res) => {
  176. if (res.code === 200) {
  177. uni.navigateTo({
  178. url: `/pages/inventory-task/detail?id=${data.id}&pageType=1`,
  179. });
  180. this.startTaskId = data.id
  181. } else {
  182. uni.$u.toast(res.data);
  183. }
  184. });
  185. break;
  186. case "去提交":
  187. taskStocktakingDetail(data.id).then((res) => {
  188. let { finishCount, materialCount } = res.data;
  189. const a = Number(finishCount || 0);
  190. const b = Number(materialCount || 0);
  191. this.activeTaskId = data.id;
  192. this.actionPop.errorShow = true;
  193. if (a === b) {
  194. // 进度100%
  195. this.actionPop.errorText = "是否提交盘点?";
  196. this.actionPop.submitActionFlag = true;
  197. } else {
  198. this.actionPop.errorText = "尚有货物未完成盘点,请先去盘点";
  199. this.actionPop.submitActionFlag = false;
  200. }
  201. });
  202. break;
  203. }
  204. },
  205. resetErrorPopData() {
  206. this.actionPop.errorShow = false;
  207. this.actionPop.submitActionFlag = false;
  208. this.actionPop.errorShow = "";
  209. },
  210. submit() {
  211. if (this.actionPop.submitActionFlag) {
  212. taskComplete(this.activeTaskId).then((res) => {
  213. this.resetErrorPopData();
  214. if (res.code === 200) {
  215. uni.$u.toast(res.msg);
  216. this.actionPop.errorShow = false
  217. this.onRefresh();
  218. } else {
  219. uni.$u.toast(res.data);
  220. }
  221. });
  222. } else {
  223. this.resetErrorPopData();
  224. }
  225. },
  226. },
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .check-page {
  231. min-height: 100vh;
  232. background-color: #f0f6fb;
  233. .container_main {
  234. .search-box {
  235. background-color: rgba(191, 200, 219, 0.2);
  236. margin: 0 32rpx;
  237. display: flex;
  238. align-items: center;
  239. justify-content: space-between;
  240. border-radius: 8rpx;
  241. ::v-deep .u-search__content {
  242. background-color: transparent !important;
  243. .u-search__content__input {
  244. background-color: transparent !important;
  245. }
  246. }
  247. .scan-icon {
  248. width: 100rpx;
  249. height: 100%;
  250. image {
  251. width: 40rpx;
  252. height: 40rpx;
  253. }
  254. }
  255. }
  256. .content-box {
  257. padding: 24rpx;
  258. &-val {
  259. border-radius: 16rpx 16rpx 0 0;
  260. overflow: hidden;
  261. }
  262. }
  263. }
  264. }
  265. </style>