index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template>
  2. <view class="inventory-page">
  3. <u-navbar
  4. height="40px"
  5. title="存货查询"
  6. bgColor="#fff"
  7. autoBack
  8. placeholder
  9. >
  10. <view class="u-nav-slot depot-label" slot="right">
  11. <view class="name">{{ curDepotName }}</view>
  12. </view>
  13. </u-navbar>
  14. <view class="container_main">
  15. <view class="head-box">
  16. <view class="search-box">
  17. <u-search
  18. placeholder="输入关键字进行货物的模糊查询"
  19. shape="square"
  20. :showAction="false"
  21. @search="handleSearch"
  22. @clear="handleSearch"
  23. v-model="queryParams.keyword"
  24. ></u-search>
  25. <view class="scan-icon flex_box flex_row_center" @click="scanCode">
  26. <image src="@/static/image/scan-icon-2.png" mode=""></image>
  27. </view>
  28. </view>
  29. <view class="type-box">
  30. <u-tabs
  31. :list="tabList"
  32. :inactiveStyle="{ color: '#000', fontSize: '24rpx' }"
  33. :activeStyle="{ color: '#000', fontSize: '24rpx' }"
  34. lineColor="#0256FF"
  35. lineWidth="66rpx"
  36. :scrollable="false"
  37. @click="tabClick"
  38. >
  39. </u-tabs>
  40. </view>
  41. </view>
  42. <view class="goods-box">
  43. <view class="goods-type" @click="typeClick">
  44. <view class="goods-type-text">{{ typeName }}</view>
  45. <u-icon name="arrow-down-fill" color="#999999" size="10"></u-icon>
  46. </view>
  47. <view class="goods-cont">
  48. <view class="goods-cont-left">
  49. <scroll-view
  50. scroll-y
  51. :style="{
  52. height: `calc(100vh - ${scrollH}px - 40px - 24rpx - 102rpx)`,
  53. }"
  54. >
  55. <leo-tree
  56. v-if="typeName === '按库位展示'"
  57. :data="treeData"
  58. :defaultProps="defaultProps"
  59. @node-click="nodeClick"
  60. v-model="queryParams.position"
  61. ></leo-tree>
  62. <leo-tree
  63. v-if="typeName === '按分类展示'"
  64. :data="treeData2"
  65. :defaultProps="defaultProps2"
  66. @node-click="nodeClick2"
  67. v-model="queryParams.categoryId"
  68. ></leo-tree>
  69. </scroll-view>
  70. </view>
  71. <view class="goods-cont-right">
  72. <scroll-view
  73. scroll-y
  74. :style="{
  75. height: `calc(100vh - ${scrollH}px - 40px - 24rpx - 102rpx)`,
  76. }"
  77. @scrolltolower="onLoadMore"
  78. >
  79. <block v-for="(item, i) in goodsList" :key="i">
  80. <good-item :item="item"></good-item>
  81. </block>
  82. <block v-if="goodsList.length == 0">
  83. <u-empty
  84. mode="data"
  85. text="暂无内容"
  86. marginTop="60"
  87. icon="https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com/APP/no-notifcations.png"
  88. ></u-empty>
  89. </block>
  90. <!-- 加载更多 -->
  91. <u-loadmore
  92. v-if="goodsList.length > 0"
  93. :status="loadStatus"
  94. @loadmore="onLoadMore"
  95. />
  96. </scroll-view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. <u-picker
  102. :show="typeShow"
  103. :defaultIndex="defaultIndex"
  104. :columns="columnsList"
  105. @confirm="pickerConfirm"
  106. @cancel="typeShow = false"
  107. ></u-picker>
  108. </view>
  109. </template>
  110. <script>
  111. import leoTree from "@/components/leo-tree/leo-tree.vue";
  112. import {
  113. inventoryInquiry,
  114. inventoryPositionTree,
  115. materialCategoryTree,
  116. } from "@/common/request/apis/inventoryInquiry";
  117. import goodItem from "./components/good-item.vue";
  118. import { mapGetters } from "vuex";
  119. export default {
  120. components: {
  121. goodItem,
  122. leoTree,
  123. },
  124. data() {
  125. return {
  126. offsetTop: 0,
  127. current: 0,
  128. typeShow: false,
  129. defaultIndex: [],
  130. typeName: "按分类展示",
  131. scrollH: 0,
  132. columnsList: [["按分类展示", "按库位展示"]],
  133. treeData: [],
  134. treeData2: [],
  135. tabList: [
  136. {
  137. value: "all",
  138. name: "全部",
  139. },
  140. {
  141. value: "have",
  142. name: "有库存",
  143. },
  144. {
  145. value: "none",
  146. name: "无库存",
  147. },
  148. ],
  149. defaultProps: {
  150. id: "value",
  151. children: "children",
  152. label: "label",
  153. },
  154. defaultProps2: {
  155. id: "id",
  156. children: "children",
  157. label: "title",
  158. },
  159. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  160. goodsList: [],
  161. pageSize: 10,
  162. currentPage: 1,
  163. queryParams: {
  164. type: "all",
  165. categoryId: "",
  166. position: "",
  167. keyword: "",
  168. },
  169. };
  170. },
  171. computed: {
  172. ...mapGetters(["depotInfo"]),
  173. curDepotId() {
  174. return this.depotInfo ? this.depotInfo.id : "";
  175. },
  176. curDepotName() {
  177. return this.depotInfo ? this.depotInfo.depotName : "";
  178. },
  179. },
  180. mounted() {
  181. let systemInfo = uni.getSystemInfoSync();
  182. let statusBarHeight = systemInfo.statusBarHeight;
  183. let headH = 0;
  184. const query = uni.createSelectorQuery().in(this);
  185. query
  186. .select(".head-box")
  187. .boundingClientRect((rect) => {
  188. headH = rect.height;
  189. this.scrollH = statusBarHeight + headH;
  190. })
  191. .exec();
  192. },
  193. onLoad() {
  194. // let systemInfo = uni.getSystemInfoSync();
  195. // let statusBarHeight = systemInfo.statusBarHeight;
  196. // this.offsetTop = statusBarHeight + 40
  197. this.getMaterialCategoryTree();
  198. this.getTreeData();
  199. this.loadData();
  200. },
  201. onShow() {
  202. uni.$on("scanFinish", (data) => {
  203. this.queryParams.keyword = data;
  204. this.onRefresh();
  205. });
  206. },
  207. onHide() {
  208. uni.$off("scanFinish");
  209. },
  210. onUnload() {
  211. uni.$off("scanFinish");
  212. },
  213. methods: {
  214. scanCode() {
  215. this.$scan.scanCode();
  216. },
  217. async getTreeData() {
  218. try {
  219. const res = await inventoryPositionTree({
  220. depotId: this.curDepotId,
  221. });
  222. console.log("res=====", res);
  223. this.treeData = res.data;
  224. } catch (error) {}
  225. },
  226. async getMaterialCategoryTree() {
  227. try {
  228. const res = await materialCategoryTree();
  229. console.log("res=====", res);
  230. this.treeData2 = res.data;
  231. } catch (error) {}
  232. },
  233. async onRefresh() {
  234. try {
  235. await this.loadData(true);
  236. } finally {
  237. }
  238. },
  239. async onLoadMore() {
  240. if (this.loadStatus !== "loadmore") return;
  241. this.loadStatus = "loading";
  242. try {
  243. await this.loadData();
  244. } catch (e) {
  245. this.loadStatus = "loadmore";
  246. }
  247. },
  248. async loadData(isRefresh = false) {
  249. if (isRefresh) {
  250. this.currentPage = 1;
  251. this.goodsList = [];
  252. }
  253. try {
  254. this.loadStatus = "loading";
  255. const currentPage = this.currentPage;
  256. const pageSize = this.pageSize;
  257. const params = {
  258. ...this.queryParams,
  259. depotId: this.curDepotId,
  260. currentPage,
  261. pageSize,
  262. };
  263. const res = await inventoryInquiry(params);
  264. console.log("inventoryInquiry====", params);
  265. console.log("res====", res);
  266. const { rows, total } = res.data;
  267. const list = rows.map((item) => {
  268. return {
  269. ...item,
  270. imgNameArr:
  271. item.imgName && item.imgName.length > 0
  272. ? item.imgName.split(",")
  273. : [],
  274. };
  275. });
  276. this.goodsList = [...this.goodsList, ...list];
  277. if (currentPage * pageSize < Number(total)) {
  278. this.currentPage++;
  279. this.loadStatus = "loadmore";
  280. } else {
  281. this.loadStatus = "nomore";
  282. }
  283. } catch (error) {}
  284. },
  285. handleSearch() {
  286. this.loadData(true);
  287. },
  288. nodeClick(e) {
  289. console.log("nodeClick======", e);
  290. this.queryParams.position = e.value;
  291. this.loadData(true);
  292. },
  293. nodeClick2(e) {
  294. console.log("nodeClick======", e);
  295. this.queryParams.categoryId = e.id;
  296. this.loadData(true);
  297. },
  298. tabClick(e) {
  299. console.log(e);
  300. this.queryParams.type = e.value;
  301. this.loadData(true);
  302. },
  303. typeClick() {
  304. let index = this.columnsList[0].findIndex(
  305. (item) => item == this.typeName
  306. );
  307. this.defaultIndex = [index];
  308. this.typeShow = true;
  309. },
  310. pickerConfirm(val) {
  311. console.log("val===========", val);
  312. this.typeName = val.value[0];
  313. if (this.typeName === "按分类展示") {
  314. this.queryParams.position = "";
  315. }
  316. if (this.typeName === "按库位展示") {
  317. this.queryParams.categoryId = "";
  318. }
  319. this.typeShow = false;
  320. },
  321. },
  322. };
  323. </script>
  324. <style lang="scss" scoped>
  325. .inventory-page {
  326. min-height: 100vh;
  327. background: #f0f6fb;
  328. .container_main {
  329. .head-box {
  330. background-color: #fff;
  331. }
  332. .search-box {
  333. background-color: rgba(191, 200, 219, 0.2);
  334. margin: 0 32rpx;
  335. display: flex;
  336. align-items: center;
  337. justify-content: space-between;
  338. border-radius: 8rpx;
  339. ::v-deep .u-search__content {
  340. background-color: transparent !important;
  341. .u-search__content__input {
  342. background-color: transparent !important;
  343. }
  344. }
  345. .scan-icon {
  346. width: 100rpx;
  347. height: 100%;
  348. image {
  349. width: 40rpx;
  350. height: 40rpx;
  351. }
  352. }
  353. }
  354. .goods-box {
  355. margin-top: 24rpx;
  356. .goods-type {
  357. display: flex;
  358. align-items: center;
  359. padding-left: 24rpx;
  360. height: 102rpx;
  361. background-color: #fff;
  362. &-text {
  363. color: #0256ff;
  364. font-size: 28rpx;
  365. font-weight: bold;
  366. margin-right: 10rpx;
  367. }
  368. }
  369. .goods-cont {
  370. display: flex;
  371. .goods-cont-left {
  372. width: 190rpx;
  373. background-color: #f0f6fb;
  374. .type-item {
  375. width: 100%;
  376. height: 84rpx;
  377. display: flex;
  378. align-items: center;
  379. justify-content: center;
  380. color: #666;
  381. font-family: "PingFang SC";
  382. font-size: 28rpx;
  383. font-weight: 400;
  384. }
  385. .active-item {
  386. background-color: #fff;
  387. color: #333;
  388. font-weight: bold;
  389. }
  390. }
  391. .goods-cont-right {
  392. flex: 1;
  393. background-color: #fff;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. </style>