index.vue 9.7 KB

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