selectOutType copy.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. :title="`选择${warehousingName}`"
  8. @clickLeft="backAdd"
  9. >
  10. <!--右菜单-->
  11. <template slot="right">
  12. <u-button
  13. type="success"
  14. size="small"
  15. class="u-reset-button"
  16. @click="$refs.treePicker._show()"
  17. text="选择分类"
  18. ></u-button>
  19. </template>
  20. </uni-nav-bar>
  21. <view class="wrapper">
  22. <view class="searchBox">
  23. <input
  24. v-model="searchVal"
  25. placeholder="请输入关键字搜索"
  26. class="searchInput"
  27. />
  28. <u-button
  29. type="icon-shixiangxinzeng"
  30. size="30"
  31. @click="doSearch"
  32. data-icon="Search"
  33. class="searchBtn"
  34. >
  35. <view class="iconfont icon-sousuo"> </view>
  36. <view class="text"> 搜索 </view>
  37. </u-button>
  38. </view>
  39. <view class="listContent">
  40. <checkbox-group
  41. v-for="(item, index) in listData"
  42. :key="index"
  43. @change="e => selectVal(e, item, index)"
  44. >
  45. <label>
  46. <view class="listBox">
  47. <view class="listBox-sel">
  48. <checkbox
  49. :value="item.code"
  50. color="#fff"
  51. :disabled="item.disabled"
  52. :checked="item.checked"
  53. />
  54. </view>
  55. <view class="listBox-con">
  56. <view class="listBox-top">
  57. <view class="listBox-name">
  58. {{ item.assetName }}
  59. </view>
  60. <view class="listBox-code">
  61. {{ item.assetCode }}
  62. </view>
  63. </view>
  64. <view class="listBox-bottom">
  65. <view
  66. v-for="(itm, index) in tableHeader"
  67. :key="index"
  68. class="items"
  69. >
  70. {{ itm.label }}:{{ item[itm.prop] }}
  71. </view>
  72. <view class="items">
  73. 可用库存:{{ item.realInventoryNum || 0 }}
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </label>
  79. </checkbox-group>
  80. <u-empty style="margin-top: 20vh" v-if="!listData.length"> </u-empty>
  81. </view>
  82. </view>
  83. <view class="footer">
  84. <view class="bottom">
  85. <checkbox
  86. v-if="!seletedAll"
  87. color="#fff"
  88. :checked="seletedAll"
  89. @tap="_seletedAll"
  90. >全选</checkbox
  91. >
  92. <checkbox
  93. class="select-all"
  94. color="#fff"
  95. v-else
  96. :checked="seletedAll"
  97. @tap="_seletedAll"
  98. >取消全选
  99. </checkbox>
  100. </view>
  101. <u-button
  102. type="success"
  103. size="small"
  104. class="u-reset-button"
  105. :disabled="!checkListLen"
  106. @click="jumpAdd"
  107. >
  108. <view class="selBtn"> 选择( {{ checkListLen }} ) </view>
  109. </u-button>
  110. </view>
  111. <ba-tree-picker
  112. ref="treePicker"
  113. key="verify"
  114. :multiple="false"
  115. @select-change="confirm"
  116. title="选择分类"
  117. :localdata="classificationList"
  118. valueKey="id"
  119. textKey="name"
  120. childrenKey="children"
  121. />
  122. </view>
  123. </template>
  124. <script>
  125. import { warehousingType, tableContentData } from '../enum.js'
  126. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  127. import { post, postJ, get } from '@/utils/api.js'
  128. import { tableHeader } from '../common'
  129. let [page, size, isEnd] = [1, 20, true]
  130. export default {
  131. components: {
  132. baTreePicker
  133. },
  134. data () {
  135. return {
  136. searchVal: '',
  137. pickTabIndex: 1,
  138. popupShow: false, //右侧搜索窗
  139. typeIndex: 1,
  140. listData: [], //列表数据
  141. classificationList: [], //分类数据
  142. seletedAll: false, //全选状态
  143. warehousingName: '',
  144. warehousingType: '',
  145. curId: '',
  146. warehouseId: '',
  147. memoList: []
  148. }
  149. },
  150. //选择的列表长度
  151. computed: {
  152. tableHeader () {
  153. return tableHeader(+this.warehousingType)
  154. },
  155. checkListLen () {
  156. return this.memoList.length
  157. },
  158. curTab () {
  159. return warehousingType.find(i => i.id == this.warehousingType) || {}
  160. }
  161. },
  162. onLoad ({ warehousingType, warehousingName, storageKey, warehouseId }) {
  163. this.warehousingName = warehousingName
  164. this.warehousingType = warehousingType
  165. this.warehouseId = warehouseId
  166. this.memoList = (storageKey && uni.getStorageSync(storageKey)) || []
  167. console.log(this.memoList, 222)
  168. },
  169. //触底刷新
  170. onReachBottom: function () {
  171. if (isEnd) {
  172. return
  173. }
  174. // 显示加载图标
  175. uni.showLoading({
  176. title: '数据加载中'
  177. })
  178. //获取更多数据
  179. page++
  180. this.getList()
  181. },
  182. mounted () {
  183. this.getClassify()
  184. },
  185. methods: {
  186. //列表数据
  187. async getList () {
  188. isEnd = false
  189. const curId = this.curId
  190. const params = {
  191. page,
  192. size: 12,
  193. code: this.warehousingType,
  194. dimension: 1,
  195. name: this.searchVal
  196. }
  197. if (this.curId) {
  198. params.materialType = this.curId
  199. }
  200. if (this.warehouseId) {
  201. params.warehouseId = this.warehouseId
  202. }
  203. const res = await get(
  204. this.apiUrl + `/outInWarehouse/select/outWarehouse/info`,
  205. params
  206. )
  207. uni.hideLoading()
  208. if (res?.success) {
  209. if (page == 1) {
  210. this.listData = []
  211. }
  212. this.listData.push(
  213. ...res.data.records.map(i => {
  214. const curId = i.assetCode
  215. const checked =
  216. this.memoList.findIndex(itm => itm.curId === curId) > -1
  217. return {
  218. checked,
  219. curId,
  220. ...i
  221. }
  222. })
  223. )
  224. if (curId === this.curId) {
  225. isEnd = this.listData.length >= res.data.total
  226. }
  227. }
  228. },
  229. confirm ([id], name) {
  230. this.curId = name === this.warehousingName ? '' : id
  231. page = 1
  232. this.getList()
  233. },
  234. async getClassify () {
  235. const res = await get(
  236. this.apiUrl + `/classify/getClassify`,
  237. {
  238. id: '0',
  239. type: this.warehousingType
  240. },
  241. true
  242. )
  243. if (res?.success) {
  244. this.classificationList = res.data
  245. this.confirm([res.data[0].id], res.data[0].name)
  246. }
  247. },
  248. doSearch () {
  249. page = 1
  250. this.getList()
  251. },
  252. //勾选
  253. selectVal (e, val, index) {
  254. // console.log(this.listData);
  255. this.listData[index].checked = !this.listData[index].checked
  256. this.seletedAll = !this.listData.some(item => !item.checked)
  257. const idx = this.memoList.findIndex(
  258. item => item.curId === this.listData[index].curId
  259. )
  260. console.log(index, this.memoList, this.listData[index])
  261. if (this.listData[index].checked) {
  262. if (idx === -1) {
  263. this.memoList.push(this.listData[index])
  264. }
  265. } else {
  266. if (idx > -1) {
  267. this.memoList.splice(idx, 1)
  268. }
  269. }
  270. },
  271. //全选按钮
  272. _seletedAll () {
  273. if (!this.seletedAll) {
  274. this.seletedAll = true
  275. this.listData.map(item => {
  276. this.$set(item, 'checked', true)
  277. console.log(
  278. this.memoList.map(i => i.curId),
  279. 'this.memoList'
  280. )
  281. const idx = this.memoList.findIndex(itm => itm.curId === item.curId)
  282. console.log(idx, item.curId)
  283. if (idx === -1) {
  284. this.memoList.push(item)
  285. }
  286. })
  287. } else {
  288. this.seletedAll = false
  289. //this.checkListLen = 0;
  290. this.listData.map(item => {
  291. this.$set(item, 'checked', false)
  292. console.log(this.memoList, 'this.memoList')
  293. const idx = this.memoList.findIndex(itm => itm.curId === item.curId)
  294. console.log(idx, item.curId)
  295. if (idx > -1) {
  296. this.memoList.splice(idx, 1)
  297. }
  298. })
  299. }
  300. },
  301. //跳转回添加页面
  302. jumpAdd () {
  303. uni.$emit('setSelectList', this.memoList)
  304. uni.navigateBack()
  305. },
  306. //返回添加页
  307. backAdd () {
  308. uni.navigateBack()
  309. }
  310. }
  311. }
  312. </script>
  313. <style lang="scss" scoped>
  314. .mainBox {
  315. .wrapper {
  316. padding-top: 50px;
  317. position: relative;
  318. }
  319. .searchBox {
  320. position: absolute;
  321. top: 0;
  322. z-index: 99;
  323. background-color: #dedede;
  324. height: 50px;
  325. width: 100%;
  326. line-height: 50px;
  327. display: flex;
  328. justify-content: space-around;
  329. align-items: center;
  330. input {
  331. height: 40px;
  332. width: 65%;
  333. background: #f9f9f9 !important;
  334. margin-left: 20rpx;
  335. padding-left: 10rpx;
  336. border-radius: 5rpx;
  337. }
  338. .searchBtn {
  339. height: 40px;
  340. background: #f9f9f9 !important;
  341. color: #676767;
  342. font-size: 28rpx;
  343. width: 260rpx;
  344. padding: 0 42rpx;
  345. outline: none;
  346. border: none;
  347. .icon-sousuo {
  348. font-size: 22px;
  349. }
  350. .text {
  351. font-size: 16px;
  352. margin-left: 10px;
  353. }
  354. }
  355. }
  356. .tab-title {
  357. position: fixed;
  358. top: 190rpx;
  359. z-index: 99;
  360. width: 100%;
  361. display: flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. height: $tab-height;
  365. line-height: $tab-height;
  366. background-color: #ffffff;
  367. border-bottom: 2rpx solid #f2f2f2;
  368. box-sizing: border-box;
  369. .tab-item {
  370. width: 25%;
  371. text-align: center;
  372. font-size: 32rpx;
  373. color: $uni-text-color-grey;
  374. }
  375. .tab-item.active {
  376. color: $j-primary-border-green;
  377. border-bottom: 1px solid $j-primary-border-green;
  378. font-weight: bold;
  379. }
  380. .tab-item.filter {
  381. flex: 1;
  382. padding: 0px 30rpx;
  383. .uni-icons {
  384. display: flex;
  385. padding-top: 5px;
  386. }
  387. }
  388. .screenIcon {
  389. display: flex;
  390. width: 80px;
  391. justify-content: center;
  392. .screenText {
  393. font-size: 32rpx;
  394. color: $uni-text-color-grey;
  395. }
  396. }
  397. }
  398. .listContent {
  399. // margin-top: 100rpx;
  400. padding-bottom: 100rpx;
  401. .listBox {
  402. display: flex;
  403. // height: 180rpx;
  404. padding: 20rpx 0;
  405. border-bottom: 2rpx solid #e5e5e5;
  406. .listBox-sel {
  407. height: 90rpx;
  408. width: 80rpx;
  409. line-height: 90rpx;
  410. text-align: center;
  411. checkbox {
  412. transform: scale(1.2);
  413. }
  414. }
  415. .listBox-con {
  416. width: 100%;
  417. // display: flex;
  418. // flex-wrap: wrap;
  419. // justify-content: space-between;
  420. align-items: center;
  421. padding: 0 18rpx 0 0;
  422. .listBox-top {
  423. width: 100%;
  424. display: flex;
  425. justify-content: space-between;
  426. padding-bottom: 10rpx;
  427. .listBox-name,
  428. .listBox-code {
  429. display: inline-block;
  430. font-size: $uni-font-size-sm;
  431. font-weight: bold;
  432. }
  433. .listBox-code {
  434. }
  435. }
  436. .listBox-bottom {
  437. width: 100%;
  438. display: flex;
  439. justify-content: space-between;
  440. flex-wrap: wrap;
  441. font-size: $uni-font-size-sm;
  442. .items {
  443. width: 50%;
  444. margin-bottom: 10rpx;
  445. }
  446. .bot-left,
  447. .bot-right {
  448. display: inline-block;
  449. color: $uni-text-color-grey;
  450. }
  451. .bot-right {
  452. }
  453. }
  454. }
  455. }
  456. }
  457. //底部按钮
  458. .footer {
  459. position: fixed;
  460. display: flex;
  461. justify-content: space-between;
  462. align-items: center;
  463. bottom: 0;
  464. width: 100%;
  465. height: 100rpx;
  466. border-top: 1rpx solid #eeecec;
  467. background-color: #ffffff;
  468. z-index: 999;
  469. .bottom {
  470. margin-left: 10rpx;
  471. }
  472. .u-reset-button {
  473. position: absolute;
  474. right: 10rpx;
  475. top: 20rpx;
  476. width: 150rpx;
  477. }
  478. }
  479. }
  480. </style>