index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. @click="tabClick"
  26. >
  27. </u-tabs>
  28. </view>
  29. </u-sticky>
  30. <view class="content-box">
  31. <view class="content-box-val">
  32. <check-item
  33. v-for="item in list"
  34. :key="item.id"
  35. :info="item"
  36. @btnClick="handleBtnClick"
  37. ></check-item>
  38. </view>
  39. <!-- 加载更多 -->
  40. <u-loadmore :status="loadStatus" @loadmore="onLoadMore" />
  41. </view>
  42. </view>
  43. <error-pop
  44. v-model="actionPop.errorShow"
  45. isCenter
  46. cancelBtnText="取消"
  47. confirmBtnText="确定"
  48. @close="actionPop.errorShow = false"
  49. @confirm="submit"
  50. :content="actionPop.errorText"
  51. ></error-pop>
  52. </view>
  53. </template>
  54. <script>
  55. import checkItem from "./components/check-item.vue";
  56. import errorPop from "@/components/error-pop/error-pop.vue";
  57. import {
  58. taskStocktakingList,
  59. startTask,
  60. taskComplete,
  61. taskStocktakingDetail,
  62. } from "@/common/request/apis/inventoryTask";
  63. import { taskStatusList } from "../inventory-task/utils/index.js";
  64. export default {
  65. components: {
  66. checkItem,
  67. errorPop,
  68. },
  69. data() {
  70. return {
  71. offsetTop: 0,
  72. tabList: taskStatusList,
  73. query: {
  74. number: "",
  75. status: "",
  76. },
  77. pageNum: 1,
  78. pageSize: 10,
  79. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  80. list: [],
  81. activeTaskId: null,
  82. actionPop: {
  83. // 警告提示弹框状态
  84. errorShow: false,
  85. submitActionFlag: false,
  86. errorText: "是否提交盘点?",
  87. },
  88. startTaskId:null,
  89. toStock:false,//是否跳转盘点
  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. this.toStock = true
  201. }
  202. });
  203. break;
  204. }
  205. },
  206. resetErrorPopData() {
  207. this.actionPop.errorShow = false;
  208. this.actionPop.submitActionFlag = false;
  209. this.actionPop.errorShow = "";
  210. },
  211. submit() {
  212. if (this.actionPop.submitActionFlag) {
  213. taskComplete(this.activeTaskId).then((res) => {
  214. this.resetErrorPopData();
  215. if (res.code === 200) {
  216. uni.$u.toast(res.msg);
  217. this.actionPop.errorShow = false
  218. this.onRefresh();
  219. } else {
  220. uni.$u.toast(res.data);
  221. }
  222. });
  223. } else {
  224. this.resetErrorPopData();
  225. if(this.toStock) {
  226. this.toStock = false
  227. uni.navigateTo({
  228. url: `/pages/inventory-task/detail?id=${this.activeTaskId}&pageType=1`,
  229. });
  230. }
  231. }
  232. },
  233. },
  234. };
  235. </script>
  236. <style lang="scss" scoped>
  237. .check-page {
  238. min-height: 100vh;
  239. background-color: #f0f6fb;
  240. .container_main {
  241. .search-box {
  242. background-color: rgba(191, 200, 219, 0.2);
  243. margin: 0 32rpx;
  244. display: flex;
  245. align-items: center;
  246. justify-content: space-between;
  247. border-radius: 8rpx;
  248. ::v-deep .u-search__content {
  249. background-color: transparent !important;
  250. .u-search__content__input {
  251. background-color: transparent !important;
  252. }
  253. }
  254. .scan-icon {
  255. width: 100rpx;
  256. height: 100%;
  257. image {
  258. width: 40rpx;
  259. height: 40rpx;
  260. }
  261. }
  262. }
  263. .content-box {
  264. padding: 24rpx;
  265. &-val {
  266. border-radius: 16rpx 16rpx 0 0;
  267. overflow: hidden;
  268. }
  269. }
  270. }
  271. }
  272. </style>