index.vue 10.0 KB

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