index.vue 7.5 KB

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