index.vue 7.7 KB

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