index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view class="check-page">
  3. <u-navbar height="40px" title="盘点" bgColor="#fff" autoBack placeholder>
  4. <view class="u-nav-slot btn-right" slot="right" @click="stashClick">
  5. <view class="cang-name">{{ cangName }}</view>
  6. <u-icon name="arrow-down-fill" color="#999999" size="12"></u-icon>
  7. </view>
  8. </u-navbar>
  9. <view class="container_main">
  10. <u-sticky :offsetTop="offsetTop" bgColor="#fff">
  11. <view class="search-box">
  12. <u-search
  13. placeholder="请输入单据编号或名称"
  14. shape="square"
  15. v-model="query.number"
  16. :showAction="false"
  17. :clearabled="true"
  18. @search="handleSearch"
  19. @clear="handleSearch"
  20. ></u-search>
  21. </view>
  22. <view class="type-box">
  23. <u-tabs
  24. :list="tabList"
  25. :inactiveStyle="{ color: '#000', fontSize: '28rpx' }"
  26. :activeStyle="{ color: '#000', fontSize: '28rpx' }"
  27. lineColor="#0256FF"
  28. lineWidth="66rpx"
  29. @click="tabClick"
  30. >
  31. </u-tabs>
  32. </view>
  33. </u-sticky>
  34. <view class="content-box">
  35. <view class="content-box-val">
  36. <check-item
  37. v-for="item in list"
  38. :key="item.id"
  39. :info="item"
  40. @btnClick="handleBtnClick"
  41. ></check-item>
  42. </view>
  43. <u-empty
  44. mode="data"
  45. text="暂无内容"
  46. marginTop="60"
  47. icon="https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com/APP/no-notifcations.png"
  48. v-if="list.length == 0"
  49. ></u-empty>
  50. <!-- 加载更多 -->
  51. <u-loadmore
  52. v-if="list.length > 0"
  53. :status="loadStatus"
  54. @loadmore="onLoadMore"
  55. />
  56. </view>
  57. </view>
  58. <error-pop
  59. v-model="actionPop.errorShow"
  60. isCenter
  61. cancelBtnText="取消"
  62. confirmBtnText="确定"
  63. @close="actionPop.errorShow = false"
  64. @confirm="submit"
  65. :content="actionPop.errorText"
  66. ></error-pop>
  67. <!-- 中心仓弹窗 -->
  68. <u-picker
  69. :show="stashShow"
  70. keyName="label"
  71. :defaultIndex="defaultIndex2"
  72. :columns="stashColumns"
  73. @confirm="pickerConfirm2"
  74. @cancel="stashShow = false"
  75. ></u-picker>
  76. </view>
  77. </template>
  78. <script>
  79. import checkItem from "./components/check-item.vue";
  80. import errorPop from "@/components/error-pop/error-pop.vue";
  81. import {
  82. taskStocktakingList,
  83. startTask,
  84. taskComplete,
  85. taskStocktakingDetail,
  86. } from "@/common/request/apis/inventoryTask";
  87. import { taskStatusList } from "../inventory-task/utils/index.js";
  88. import { depotSpinnerList } from "@/common/request/apis/purchase";
  89. export default {
  90. components: {
  91. checkItem,
  92. errorPop,
  93. },
  94. data() {
  95. return {
  96. offsetTop: 0,
  97. tabList: taskStatusList,
  98. query: {
  99. number: "",
  100. status: "",
  101. depotId: "",
  102. },
  103. currentPage: 1,
  104. pageSize: 10,
  105. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  106. list: [],
  107. activeTaskId: null,
  108. actionPop: {
  109. // 警告提示弹框状态
  110. errorShow: false,
  111. submitActionFlag: false,
  112. errorText: "是否提交盘点?",
  113. },
  114. startTaskId: null,
  115. toStock: false, //是否跳转盘点
  116. // 中心仓
  117. stashShow: false,
  118. cangName: "",
  119. stashColumns: [],
  120. defaultIndex2: [],
  121. };
  122. },
  123. onLoad() {
  124. let systemInfo = uni.getSystemInfoSync();
  125. let statusBarHeight = systemInfo.statusBarHeight;
  126. this.offsetTop = statusBarHeight + 40;
  127. // 初始化数据
  128. this.getDepotSpinnerList();
  129. },
  130. onShow() {
  131. if (this.startTaskId) {
  132. let index = this.list.findIndex((item) => item.id == this.startTaskId);
  133. this.list[index].taskStatus = 2;
  134. this.startTaskId = null;
  135. }
  136. },
  137. onPullDownRefresh() {
  138. // 下拉刷新
  139. this.onRefresh();
  140. },
  141. onReachBottom() {
  142. // 触底加载更多
  143. this.onLoadMore();
  144. },
  145. methods: {
  146. getDepotSpinnerList() {
  147. depotSpinnerList().then((res) => {
  148. if (res.code == 200) {
  149. this.stashColumns = [res.data];
  150. this.cangName = res.data[0].label;
  151. this.query.depotId = res.data[0].value;
  152. this.$store.commit("setcangName", this.cangName);
  153. this.$store.commit("setDepotInfo", {
  154. depotName: res.data[0].label,
  155. id: res.data[0].value,
  156. });
  157. this.loadData();
  158. }
  159. });
  160. },
  161. async onRefresh() {
  162. try {
  163. await this.loadData(true);
  164. } finally {
  165. uni.stopPullDownRefresh();
  166. }
  167. },
  168. async onLoadMore() {
  169. if (this.loadStatus !== "loadmore") return;
  170. this.loadStatus = "loading";
  171. try {
  172. await this.loadData();
  173. } catch (e) {
  174. this.loadStatus = "loadmore";
  175. }
  176. },
  177. async loadData(isRefresh = false) {
  178. if (isRefresh) {
  179. this.currentPage = 1;
  180. this.list = [];
  181. }
  182. try {
  183. this.loadStatus = "loading";
  184. const currentPage = this.currentPage;
  185. const pageSize = this.pageSize;
  186. const params = {
  187. currentPage,
  188. pageSize,
  189. ...this.query,
  190. };
  191. console.log("params=====", params);
  192. const res = await taskStocktakingList(params);
  193. const { rows, total } = res.data;
  194. this.list = [...this.list, ...rows];
  195. if (currentPage * pageSize < Number(total)) {
  196. this.currentPage++;
  197. this.loadStatus = "loadmore";
  198. } else {
  199. this.loadStatus = "nomore";
  200. }
  201. } catch (error) {}
  202. },
  203. tabClick({ index }) {
  204. this.query.status = this.tabList[index].value;
  205. this.loadData(true);
  206. },
  207. handleSearch(value) {
  208. this.loadData(true);
  209. },
  210. // 前往盘点任务详情
  211. handleBtnClick(data) {
  212. console.log(11111, data);
  213. // params.id--->任务id params.btnName--->按钮label
  214. const { btnName } = data;
  215. switch (btnName) {
  216. case "详情":
  217. uni.navigateTo({
  218. url: `/pages/inventory-task/taskDetail?id=${data.id}`,
  219. });
  220. break;
  221. case "去盘点":
  222. startTask(data.id).then((res) => {
  223. if (res.code === 200) {
  224. uni.navigateTo({
  225. url: `/pages/inventory-task/detail?id=${data.id}&pageType=1`,
  226. });
  227. this.startTaskId = data.id;
  228. } else {
  229. uni.$u.toast(res.data);
  230. }
  231. });
  232. break;
  233. case "去提交":
  234. taskStocktakingDetail(data.id).then((res) => {
  235. let { finishCount, materialCount } = res.data;
  236. const a = Number(finishCount || 0);
  237. const b = Number(materialCount || 0);
  238. this.activeTaskId = data.id;
  239. this.actionPop.errorShow = true;
  240. if (a === b) {
  241. // 进度100%
  242. this.actionPop.errorText = "是否提交盘点?";
  243. this.actionPop.submitActionFlag = true;
  244. } else {
  245. this.actionPop.errorText = "尚有货物未完成盘点,请先去盘点";
  246. this.actionPop.submitActionFlag = false;
  247. this.toStock = true;
  248. }
  249. });
  250. break;
  251. }
  252. },
  253. resetErrorPopData() {
  254. this.actionPop.errorShow = false;
  255. this.actionPop.submitActionFlag = false;
  256. this.actionPop.errorShow = "";
  257. },
  258. submit() {
  259. if (this.actionPop.submitActionFlag) {
  260. taskComplete(this.activeTaskId).then((res) => {
  261. this.resetErrorPopData();
  262. if (res.code === 200) {
  263. uni.$u.toast(res.msg);
  264. this.actionPop.errorShow = false;
  265. this.onRefresh();
  266. } else {
  267. uni.$u.toast(res.data);
  268. }
  269. });
  270. } else {
  271. this.resetErrorPopData();
  272. if (this.toStock) {
  273. this.toStock = false;
  274. this.actionPop.errorShow = false;
  275. uni.navigateTo({
  276. url: `/pages/inventory-task/detail?id=${this.activeTaskId}&pageType=1`,
  277. });
  278. }
  279. }
  280. },
  281. stashClick() {
  282. this.defaultIndex2 = this.getDefaultIndex(
  283. this.cangName,
  284. this.stashColumns
  285. );
  286. this.stashShow = true;
  287. },
  288. pickerConfirm2(val) {
  289. console.log("pickerConfirm2======", val);
  290. this.cangName = val.value[0].label;
  291. this.query.depotId = val.value[0].value;
  292. this.stashShow = false;
  293. this.$store.commit("setcangName", this.cangName);
  294. this.$store.commit("setDepotInfo", {
  295. depotName: val.value[0].label,
  296. id: val.value[0].value,
  297. });
  298. this.onRefresh();
  299. },
  300. // 获取picker默认index
  301. getDefaultIndex(val, list) {
  302. let arr = [];
  303. let index = list[0].findIndex((item) => item.label == val);
  304. arr = [index];
  305. return arr;
  306. },
  307. },
  308. };
  309. </script>
  310. <style lang="scss" scoped>
  311. .btn-right {
  312. display: flex;
  313. align-items: center;
  314. .cang-name {
  315. color: #0256ff;
  316. text-align: center;
  317. font-family: "PingFang SC";
  318. font-size: 28rpx;
  319. font-weight: 600;
  320. margin-right: 10rpx;
  321. }
  322. }
  323. .check-page {
  324. min-height: 100vh;
  325. background-color: #f0f6fb;
  326. .container_main {
  327. .search-box {
  328. background-color: rgba(191, 200, 219, 0.2);
  329. margin: 0 32rpx;
  330. display: flex;
  331. align-items: center;
  332. justify-content: space-between;
  333. border-radius: 8rpx;
  334. ::v-deep .u-search__content {
  335. background-color: transparent !important;
  336. .u-search__content__input {
  337. background-color: transparent !important;
  338. }
  339. }
  340. .scan-icon {
  341. width: 100rpx;
  342. height: 100%;
  343. image {
  344. width: 40rpx;
  345. height: 40rpx;
  346. }
  347. }
  348. }
  349. .content-box {
  350. padding: 24rpx;
  351. &-val {
  352. border-radius: 16rpx 16rpx 0 0;
  353. overflow: hidden;
  354. }
  355. }
  356. }
  357. }
  358. </style>