index.vue 12 KB

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