index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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">
  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. <!-- 加载更多 -->
  80. <u-loadmore :status="loadStatus" @loadmore="onLoadMore" />
  81. </scroll-view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <u-picker
  87. :show="typeShow"
  88. :defaultIndex="defaultIndex"
  89. :columns="columnsList"
  90. @confirm="pickerConfirm"
  91. @cancel="typeShow = false"
  92. ></u-picker>
  93. </view>
  94. </template>
  95. <script>
  96. import leoTree from "@/components/leo-tree/leo-tree.vue";
  97. import {
  98. inventoryInquiry,
  99. inventoryPositionTree,
  100. materialCategoryTree,
  101. } from "@/common/request/apis/inventoryInquiry";
  102. import goodItem from "@/components/good-item/good-item.vue";
  103. export default {
  104. components: {
  105. goodItem,
  106. leoTree,
  107. },
  108. data() {
  109. return {
  110. offsetTop: 0,
  111. current: 0,
  112. typeShow: false,
  113. defaultIndex: [],
  114. typeName: "按分类展示",
  115. scrollH: 0,
  116. columnsList: [["按分类展示", "按库位展示"]],
  117. treeData: [],
  118. treeData2: [],
  119. tabList: [
  120. {
  121. value: "have",
  122. name: "有库存",
  123. },
  124. {
  125. value: "none",
  126. name: "无库存",
  127. },
  128. {
  129. value: "all",
  130. name: "全部",
  131. },
  132. ],
  133. defaultProps: {
  134. id: "value",
  135. children: "children",
  136. label: "label",
  137. },
  138. defaultProps2: {
  139. id: "id",
  140. children: "children",
  141. label: "title",
  142. },
  143. loadStatus: "loadmore", //加载前值为loadmore,加载中为loading,没有数据为nomore
  144. goodsList: [],
  145. pageSize: 10,
  146. pageNum: 1,
  147. queryParams: {
  148. type: "have",
  149. categoryId: "",
  150. position: "",
  151. keyword: "",
  152. },
  153. };
  154. },
  155. mounted() {
  156. let systemInfo = uni.getSystemInfoSync();
  157. let statusBarHeight = systemInfo.statusBarHeight;
  158. let headH = 0;
  159. const query = uni.createSelectorQuery().in(this);
  160. query
  161. .select(".head-box")
  162. .boundingClientRect((rect) => {
  163. headH = rect.height;
  164. this.scrollH = statusBarHeight + headH;
  165. })
  166. .exec();
  167. },
  168. onLoad() {
  169. // let systemInfo = uni.getSystemInfoSync();
  170. // let statusBarHeight = systemInfo.statusBarHeight;
  171. // this.offsetTop = statusBarHeight + 40
  172. this.getTreeData();
  173. this.getMaterialCategoryTree();
  174. this.loadData();
  175. },
  176. onShow() {
  177. uni.$on("scanFinish", (data) => {
  178. this.params.keyword = data;
  179. this.onRefresh();
  180. });
  181. },
  182. onHide() {
  183. uni.$off("scanFinish");
  184. },
  185. onUnload() {
  186. uni.$off("scanFinish");
  187. },
  188. methods: {
  189. async getTreeData() {
  190. try {
  191. const res = await inventoryPositionTree();
  192. console.log("res=====", res);
  193. this.treeData = res.data;
  194. } catch (error) {}
  195. },
  196. async getMaterialCategoryTree() {
  197. try {
  198. const res = await materialCategoryTree();
  199. console.log("res=====", res);
  200. this.treeData2 = res.data;
  201. } catch (error) {}
  202. },
  203. async onRefresh() {
  204. try {
  205. await this.loadData(true);
  206. } finally {
  207. }
  208. },
  209. async onLoadMore() {
  210. if (this.loadStatus !== "loadmore") return;
  211. this.loadStatus = "loading";
  212. try {
  213. await this.loadData();
  214. } catch (e) {
  215. this.loadStatus = "loadmore";
  216. }
  217. },
  218. async loadData(isRefresh = false) {
  219. if (isRefresh) {
  220. this.pageNum = 1;
  221. this.goodsList = [];
  222. }
  223. try {
  224. this.loadStatus = "loading";
  225. const pageNum = this.pageNum;
  226. const pageSize = this.pageSize;
  227. const params = {
  228. pageNum,
  229. pageSize,
  230. ...this.queryParams,
  231. };
  232. const res = await inventoryInquiry(params);
  233. console.log("res====", res);
  234. const { rows, total } = res.data;
  235. const list = rows.map((item) => {
  236. return {
  237. ...item,
  238. src: item.imgName,
  239. };
  240. });
  241. this.goodsList = [...this.goodsList, ...list];
  242. if (pageNum * pageSize < Number(total)) {
  243. this.pageNum++;
  244. this.loadStatus = "loadmore";
  245. } else {
  246. this.loadStatus = "nomore";
  247. }
  248. } catch (error) {}
  249. },
  250. handleSearch() {
  251. this.loadData(true);
  252. },
  253. nodeClick(e) {
  254. console.log("nodeClick======", e);
  255. this.queryParams.position = e.value;
  256. this.loadData(true);
  257. },
  258. nodeClick2(e) {
  259. console.log("nodeClick======", e);
  260. this.queryParams.categoryId = e.id;
  261. this.loadData(true);
  262. },
  263. tabClick(e) {
  264. console.log(e);
  265. this.queryParams.type = e.value;
  266. this.loadData(true);
  267. },
  268. typeClick() {
  269. let index = this.columnsList[0].findIndex(
  270. (item) => item == this.typeName
  271. );
  272. this.defaultIndex = [index];
  273. this.typeShow = true;
  274. },
  275. pickerConfirm(val) {
  276. console.log("val===========", val);
  277. this.typeName = val.value[0];
  278. if (this.typeName === "按分类展示") {
  279. this.queryParams.position = "";
  280. }
  281. if (this.typeName === "按库位展示") {
  282. this.queryParams.categoryId = "";
  283. }
  284. this.typeShow = false;
  285. },
  286. },
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .inventory-page {
  291. min-height: 100vh;
  292. background: #f0f6fb;
  293. .container_main {
  294. .head-box {
  295. background-color: #fff;
  296. }
  297. .search-box {
  298. background-color: rgba(191, 200, 219, 0.2);
  299. margin: 0 32rpx;
  300. display: flex;
  301. align-items: center;
  302. justify-content: space-between;
  303. border-radius: 8rpx;
  304. ::v-deep .u-search__content {
  305. background-color: transparent !important;
  306. .u-search__content__input {
  307. background-color: transparent !important;
  308. }
  309. }
  310. .scan-icon {
  311. width: 100rpx;
  312. height: 100%;
  313. image {
  314. width: 40rpx;
  315. height: 40rpx;
  316. }
  317. }
  318. }
  319. .goods-box {
  320. margin-top: 24rpx;
  321. .goods-type {
  322. display: flex;
  323. align-items: center;
  324. padding-left: 24rpx;
  325. height: 102rpx;
  326. background-color: #fff;
  327. &-text {
  328. color: #0256ff;
  329. font-size: 28rpx;
  330. font-weight: bold;
  331. margin-right: 10rpx;
  332. }
  333. }
  334. .goods-cont {
  335. display: flex;
  336. .goods-cont-left {
  337. width: 160rpx;
  338. background-color: #f0f6fb;
  339. .type-item {
  340. width: 100%;
  341. height: 84rpx;
  342. display: flex;
  343. align-items: center;
  344. justify-content: center;
  345. color: #666;
  346. font-family: "PingFang SC";
  347. font-size: 28rpx;
  348. font-weight: 400;
  349. }
  350. .active-item {
  351. background-color: #fff;
  352. color: #333;
  353. font-weight: bold;
  354. }
  355. }
  356. .goods-cont-right {
  357. flex: 1;
  358. background-color: #fff;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. </style>