index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. <!-- 加载更多 -->
  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. scanCode() {
  190. this.$scan.scanCode();
  191. },
  192. async getTreeData() {
  193. try {
  194. const res = await inventoryPositionTree();
  195. console.log("res=====", res);
  196. this.treeData = res.data;
  197. } catch (error) {}
  198. },
  199. async getMaterialCategoryTree() {
  200. try {
  201. const res = await materialCategoryTree();
  202. console.log("res=====", res);
  203. this.treeData2 = res.data;
  204. } catch (error) {}
  205. },
  206. async onRefresh() {
  207. try {
  208. await this.loadData(true);
  209. } finally {
  210. }
  211. },
  212. async onLoadMore() {
  213. if (this.loadStatus !== "loadmore") return;
  214. this.loadStatus = "loading";
  215. try {
  216. await this.loadData();
  217. } catch (e) {
  218. this.loadStatus = "loadmore";
  219. }
  220. },
  221. async loadData(isRefresh = false) {
  222. if (isRefresh) {
  223. this.pageNum = 1;
  224. this.goodsList = [];
  225. }
  226. try {
  227. this.loadStatus = "loading";
  228. const pageNum = this.pageNum;
  229. const pageSize = this.pageSize;
  230. const params = {
  231. pageNum,
  232. pageSize,
  233. ...this.queryParams,
  234. };
  235. const res = await inventoryInquiry(params);
  236. console.log("res====", res);
  237. const { rows, total } = res.data;
  238. const list = rows.map((item) => {
  239. return {
  240. ...item,
  241. src: item.imgName,
  242. };
  243. });
  244. this.goodsList = [...this.goodsList, ...list];
  245. if (pageNum * pageSize < Number(total)) {
  246. this.pageNum++;
  247. this.loadStatus = "loadmore";
  248. } else {
  249. this.loadStatus = "nomore";
  250. }
  251. } catch (error) {}
  252. },
  253. handleSearch() {
  254. this.loadData(true);
  255. },
  256. nodeClick(e) {
  257. console.log("nodeClick======", e);
  258. this.queryParams.position = e.value;
  259. this.loadData(true);
  260. },
  261. nodeClick2(e) {
  262. console.log("nodeClick======", e);
  263. this.queryParams.categoryId = e.id;
  264. this.loadData(true);
  265. },
  266. tabClick(e) {
  267. console.log(e);
  268. this.queryParams.type = e.value;
  269. this.loadData(true);
  270. },
  271. typeClick() {
  272. let index = this.columnsList[0].findIndex(
  273. (item) => item == this.typeName
  274. );
  275. this.defaultIndex = [index];
  276. this.typeShow = true;
  277. },
  278. pickerConfirm(val) {
  279. console.log("val===========", val);
  280. this.typeName = val.value[0];
  281. if (this.typeName === "按分类展示") {
  282. this.queryParams.position = "";
  283. }
  284. if (this.typeName === "按库位展示") {
  285. this.queryParams.categoryId = "";
  286. }
  287. this.typeShow = false;
  288. },
  289. },
  290. };
  291. </script>
  292. <style lang="scss" scoped>
  293. .inventory-page {
  294. min-height: 100vh;
  295. background: #f0f6fb;
  296. .container_main {
  297. .head-box {
  298. background-color: #fff;
  299. }
  300. .search-box {
  301. background-color: rgba(191, 200, 219, 0.2);
  302. margin: 0 32rpx;
  303. display: flex;
  304. align-items: center;
  305. justify-content: space-between;
  306. border-radius: 8rpx;
  307. ::v-deep .u-search__content {
  308. background-color: transparent !important;
  309. .u-search__content__input {
  310. background-color: transparent !important;
  311. }
  312. }
  313. .scan-icon {
  314. width: 100rpx;
  315. height: 100%;
  316. image {
  317. width: 40rpx;
  318. height: 40rpx;
  319. }
  320. }
  321. }
  322. .goods-box {
  323. margin-top: 24rpx;
  324. .goods-type {
  325. display: flex;
  326. align-items: center;
  327. padding-left: 24rpx;
  328. height: 102rpx;
  329. background-color: #fff;
  330. &-text {
  331. color: #0256ff;
  332. font-size: 28rpx;
  333. font-weight: bold;
  334. margin-right: 10rpx;
  335. }
  336. }
  337. .goods-cont {
  338. display: flex;
  339. .goods-cont-left {
  340. width: 160rpx;
  341. background-color: #f0f6fb;
  342. .type-item {
  343. width: 100%;
  344. height: 84rpx;
  345. display: flex;
  346. align-items: center;
  347. justify-content: center;
  348. color: #666;
  349. font-family: "PingFang SC";
  350. font-size: 28rpx;
  351. font-weight: 400;
  352. }
  353. .active-item {
  354. background-color: #fff;
  355. color: #333;
  356. font-weight: bold;
  357. }
  358. }
  359. .goods-cont-right {
  360. flex: 1;
  361. background-color: #fff;
  362. }
  363. }
  364. }
  365. }
  366. }
  367. </style>