index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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. <goodCard
  81. :goodImg="
  82. item.imgNameArr && item.imgNameArr[0]
  83. ? item.imgNameArr[0]
  84. : ''
  85. "
  86. :goodName="item.materialName"
  87. :goodDesValue="item.sku"
  88. goodDesTitle="SKU"
  89. :columns="columns"
  90. :item="item"
  91. >
  92. </goodCard>
  93. </block>
  94. <block v-if="goodsList.length == 0">
  95. <u-empty
  96. mode="data"
  97. text="暂无内容"
  98. marginTop="60"
  99. icon="https://xiangli-erp.oss-cn-hangzhou.aliyuncs.com/APP/no-notifcations.png"
  100. ></u-empty>
  101. </block>
  102. <!-- 加载更多 -->
  103. <u-loadmore
  104. v-if="goodsList.length > 0"
  105. :status="loadStatus"
  106. @loadmore="onLoadMore"
  107. />
  108. </scroll-view>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. <u-picker
  114. :show="typeShow"
  115. :defaultIndex="defaultIndex"
  116. :columns="columnsList"
  117. @confirm="pickerConfirm"
  118. @cancel="typeShow = false"
  119. ></u-picker>
  120. </view>
  121. </template>
  122. <script>
  123. import leoTree from "@/components/leo-tree/leo-tree.vue";
  124. import {
  125. inventoryInquiry,
  126. inventoryPositionTree,
  127. materialCategoryTree,
  128. } from "@/common/request/apis/inventoryInquiry";
  129. import goodCard from "@/components/good-card/good-card.vue";
  130. import { mapGetters } from "vuex";
  131. export default {
  132. components: {
  133. goodCard,
  134. leoTree,
  135. },
  136. data() {
  137. const that = this;
  138. return {
  139. offsetTop: 0,
  140. current: 0,
  141. typeShow: false,
  142. defaultIndex: [],
  143. typeName: "按分类展示",
  144. scrollH: 0,
  145. columnsList: [["按分类展示", "按库位展示"]],
  146. treeData: [],
  147. treeData2: [],
  148. tabList: [
  149. {
  150. value: "all",
  151. name: "全部",
  152. },
  153. {
  154. value: "have",
  155. name: "有库存",
  156. },
  157. {
  158. value: "none",
  159. name: "无库存",
  160. },
  161. ],
  162. defaultProps: {
  163. id: "value",
  164. children: "children",
  165. label: "label",
  166. },
  167. defaultProps2: {
  168. id: "id",
  169. children: "children",
  170. label: "title",
  171. },
  172. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  173. goodsList: [],
  174. pageSize: 10,
  175. currentPage: 1,
  176. columns: [
  177. { title: "规格", key: "materialStandard" },
  178. {
  179. title: "生产日期",
  180. key: "productionDate",
  181. formatter: (key, formData) => {
  182. return formData.productionDate
  183. ? that.$u.timeFormat(formData.productionDate, "yyyy-mm-dd")
  184. : "/";
  185. },
  186. },
  187. {
  188. title: "库存",
  189. key: "inventory",
  190. formatter: (key, formData) => {
  191. const inventory = formData.inventory
  192. ? (formData.inventory * 1).toFixed(0)
  193. : "0";
  194. return `${inventory}${formData.commodityUnit || ""}`;
  195. },
  196. },
  197. { title: "库位", key: "position" },
  198. ],
  199. queryParams: {
  200. type: "all",
  201. categoryId: "",
  202. position: "",
  203. keyword: "",
  204. },
  205. };
  206. },
  207. computed: {
  208. ...mapGetters(["depotInfo"]),
  209. curDepotId() {
  210. return this.depotInfo ? this.depotInfo.id : "";
  211. },
  212. curDepotName() {
  213. return this.depotInfo ? this.depotInfo.depotName : "";
  214. },
  215. },
  216. mounted() {
  217. let systemInfo = uni.getSystemInfoSync();
  218. let statusBarHeight = systemInfo.statusBarHeight;
  219. let headH = 0;
  220. const query = uni.createSelectorQuery().in(this);
  221. query
  222. .select(".head-box")
  223. .boundingClientRect((rect) => {
  224. headH = rect.height;
  225. this.scrollH = statusBarHeight + headH;
  226. })
  227. .exec();
  228. },
  229. onLoad() {
  230. // let systemInfo = uni.getSystemInfoSync();
  231. // let statusBarHeight = systemInfo.statusBarHeight;
  232. // this.offsetTop = statusBarHeight + 40
  233. this.getMaterialCategoryTree();
  234. this.getTreeData();
  235. this.loadData();
  236. },
  237. onShow() {
  238. uni.$on("scanFinish", (data) => {
  239. this.queryParams.keyword = data;
  240. this.onRefresh();
  241. });
  242. },
  243. onHide() {
  244. uni.$off("scanFinish");
  245. },
  246. onUnload() {
  247. uni.$off("scanFinish");
  248. },
  249. methods: {
  250. scanCode() {
  251. this.$scan.scanCode();
  252. },
  253. async getTreeData() {
  254. try {
  255. const res = await inventoryPositionTree({
  256. depotId: this.curDepotId,
  257. });
  258. console.log("res=====", res);
  259. this.treeData = res.data;
  260. } catch (error) {}
  261. },
  262. async getMaterialCategoryTree() {
  263. try {
  264. const res = await materialCategoryTree();
  265. console.log("res=====", res);
  266. this.treeData2 = res.data;
  267. } catch (error) {}
  268. },
  269. async onRefresh() {
  270. try {
  271. await this.loadData(true);
  272. } finally {
  273. }
  274. },
  275. async onLoadMore() {
  276. if (this.loadStatus !== "loadmore") return;
  277. this.loadStatus = "loading";
  278. try {
  279. await this.loadData();
  280. } catch (e) {
  281. this.loadStatus = "loadmore";
  282. }
  283. },
  284. async loadData(isRefresh = false) {
  285. if (isRefresh) {
  286. this.currentPage = 1;
  287. this.goodsList = [];
  288. }
  289. try {
  290. this.loadStatus = "loading";
  291. const currentPage = this.currentPage;
  292. const pageSize = this.pageSize;
  293. const params = {
  294. ...this.queryParams,
  295. depotId: this.curDepotId,
  296. currentPage,
  297. pageSize,
  298. };
  299. const res = await inventoryInquiry(params);
  300. console.log("inventoryInquiry====", params);
  301. console.log("res====", res);
  302. const { rows, total } = res.data;
  303. const list = rows.map((item) => {
  304. return {
  305. ...item,
  306. imgNameArr:
  307. item.imgName && item.imgName.length > 0
  308. ? item.imgName.split(",")
  309. : [],
  310. };
  311. });
  312. this.goodsList = [...this.goodsList, ...list];
  313. if (currentPage * pageSize < Number(total)) {
  314. this.currentPage++;
  315. this.loadStatus = "loadmore";
  316. } else {
  317. this.loadStatus = "nomore";
  318. }
  319. } catch (error) {}
  320. },
  321. handleSearch() {
  322. this.loadData(true);
  323. },
  324. nodeClick(e) {
  325. console.log("nodeClick======", e);
  326. this.queryParams.position = e.value;
  327. this.loadData(true);
  328. },
  329. nodeClick2(e) {
  330. console.log("nodeClick======", e);
  331. this.queryParams.categoryId = e.id;
  332. this.loadData(true);
  333. },
  334. tabClick(e) {
  335. console.log(e);
  336. this.queryParams.type = e.value;
  337. this.loadData(true);
  338. },
  339. typeClick() {
  340. let index = this.columnsList[0].findIndex(
  341. (item) => item == this.typeName
  342. );
  343. this.defaultIndex = [index];
  344. this.typeShow = true;
  345. },
  346. pickerConfirm(val) {
  347. console.log("val===========", val);
  348. this.typeName = val.value[0];
  349. if (this.typeName === "按分类展示") {
  350. this.queryParams.position = "";
  351. }
  352. if (this.typeName === "按库位展示") {
  353. this.queryParams.categoryId = "";
  354. }
  355. this.typeShow = false;
  356. },
  357. },
  358. };
  359. </script>
  360. <style lang="scss" scoped>
  361. .inventory-page {
  362. min-height: 100vh;
  363. background: #f0f6fb;
  364. .container_main {
  365. .head-box {
  366. background-color: #fff;
  367. }
  368. .search-box {
  369. background-color: rgba(191, 200, 219, 0.2);
  370. margin: 0 32rpx;
  371. display: flex;
  372. align-items: center;
  373. justify-content: space-between;
  374. border-radius: 8rpx;
  375. ::v-deep .u-search__content {
  376. background-color: transparent !important;
  377. .u-search__content__input {
  378. background-color: transparent !important;
  379. }
  380. }
  381. .scan-icon {
  382. width: 100rpx;
  383. height: 100%;
  384. image {
  385. width: 40rpx;
  386. height: 40rpx;
  387. }
  388. }
  389. }
  390. .goods-box {
  391. margin-top: 24rpx;
  392. .goods-type {
  393. display: flex;
  394. align-items: center;
  395. padding-left: 24rpx;
  396. height: 102rpx;
  397. background-color: #fff;
  398. &-text {
  399. color: #0256ff;
  400. font-size: 28rpx;
  401. font-weight: bold;
  402. margin-right: 10rpx;
  403. }
  404. }
  405. .goods-cont {
  406. display: flex;
  407. .goods-cont-left {
  408. width: 190rpx;
  409. background-color: #f0f6fb;
  410. .type-item {
  411. width: 100%;
  412. height: 84rpx;
  413. display: flex;
  414. align-items: center;
  415. justify-content: center;
  416. color: #666;
  417. font-family: "PingFang SC";
  418. font-size: 28rpx;
  419. font-weight: 400;
  420. }
  421. .active-item {
  422. background-color: #fff;
  423. color: #333;
  424. font-weight: bold;
  425. }
  426. }
  427. .goods-cont-right {
  428. flex: 1;
  429. background-color: #fff;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. </style>