index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view class="content-box">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="搜索" @clickLeft="back">
  4. <!--右菜单-->
  5. <template slot="right">
  6. <u-button type="success" size="small" class="u-reset-button" @click="openTreePicker"
  7. text="选择分类"></u-button>
  8. </template>
  9. </uni-nav-bar>
  10. <view class="top-wrapper">
  11. <view class="searchBox rx-bc">
  12. <input v-model="keyWord" placeholder="请输入关键字搜索" class="searchInput" />
  13. <view>
  14. <u-button @click="doSearch" type="success" size="small" class="u-reset-button" text="搜索">
  15. </u-button>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="list_box">
  20. <u-list @scrolltolower="scrolltolower">
  21. <checkbox-group v-for="(item, index) in list" :key="index" @change="e => selectVal(e, item, index)">
  22. <label class="listBox rx-bs">
  23. <view class="listBox-sel">
  24. <checkbox :value="item.code"
  25. :class="item.rootCategoryLevelId == 1 && !item.checked ? 'checkedClass': ''"
  26. color="#fff" :disabled="item.disabled" :checked="item.checked" />
  27. </view>
  28. <view class="listBox-con">
  29. <view class="listBox-top rx-bc">
  30. <view> {{ item.name }}</view>
  31. <view class="code">{{ item.code}}</view>
  32. </view>
  33. <view class="listBox-bottom rx">
  34. <view v-for="(itm, index) in tableH(item.rootCategoryLevelId)" :key="index"
  35. class="items">
  36. {{ itm.label }}:{{ item[itm.prop] }}
  37. </view>
  38. <view class="items">
  39. 可用库存:{{ item.availableCountBase }} {{item.unit}}
  40. </view>
  41. </view>
  42. </view>
  43. </label>
  44. </checkbox-group>
  45. <view v-if='list.length == 0' style='margin-top: 20vh;'>
  46. <u-empty iconSize='150' textSize='32' text='暂无数据'>
  47. </u-empty>
  48. </view>
  49. </u-list>
  50. </view>
  51. <view class="bottom-wrapper rx-bc">
  52. <view>
  53. <checkbox v-if="!seletedAll" color="#fff" :checked="seletedAll" @tap="_seletedAll">全选</checkbox>
  54. <checkbox class="select-all" color="#fff" v-else :checked="seletedAll" @tap="_seletedAll">取消全选
  55. </checkbox>
  56. </view>
  57. <view>
  58. <u-button type="success" size="small" class="u-reset-button" :disabled="!checkListLen" @click="jumpAdd">
  59. <view> 选择( {{ checkListLen }} ) </view>
  60. </u-button>
  61. </view>
  62. </view>
  63. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择分类"
  64. :localdata="classificationList" valueKey="id" textKey="name" childrenKey="children" />
  65. <matterPop v-if='matterShow' :matterId='matterId' :categoryId='categoryId' :mattList='mattList' @close='close'
  66. @mattSave='mattSave'>
  67. </matterPop>
  68. </view>
  69. </template>
  70. <script>
  71. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  72. import {
  73. tableHeader
  74. } from '../../common.js'
  75. import {
  76. treeByPid,
  77. pageeLedgerMain,
  78. assetPage
  79. } from '@/api/pda/workOrder.js'
  80. import matterPop from './matterPop.vue'
  81. let [isEnd] = [false]
  82. export default {
  83. components: {
  84. baTreePicker,
  85. matterPop
  86. },
  87. data() {
  88. return {
  89. keyWord: null,
  90. categoryLevelId: null,
  91. classificationList: [],
  92. treePickerShow: false,
  93. list: [],
  94. page: 1,
  95. seletedAll: false, //全选状态
  96. memoList: [],
  97. isType: null,
  98. pid: null, // 上个页面id
  99. storageKey: null,
  100. matterShow: false, //物料 左弹框
  101. matterId: null,
  102. categoryId: null,
  103. mattList: []
  104. }
  105. },
  106. //选择的列表长度
  107. computed: {
  108. checkListLen() {
  109. return this.memoList.length
  110. }
  111. },
  112. onLoad(option) {
  113. this.pid = option.id
  114. this.isType = option.isType
  115. if (option.storageKey) {
  116. this.storageKey = option.storageKey
  117. if (this.isType == 'feed') {
  118. let _arr = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  119. this.memoList = [..._arr[0].modelList, ..._arr[0].equipmentList]
  120. this.mattList = [..._arr[0].instanceList]
  121. } else {
  122. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  123. }
  124. }
  125. this.getTreeList()
  126. },
  127. onUnload() {
  128. if (this.storageKey) {
  129. uni.removeStorage(this.storageKey)
  130. }
  131. },
  132. methods: {
  133. _seletedAll() {
  134. if (!this.seletedAll) {
  135. this.seletedAll = true
  136. this.list.map(item => {
  137. this.$set(item, 'checked', true)
  138. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  139. if (idx === -1) {
  140. this.memoList.push(item)
  141. }
  142. })
  143. } else {
  144. this.seletedAll = false
  145. this.list.map(item => {
  146. this.$set(item, 'checked', false)
  147. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  148. if (idx > -1) {
  149. this.memoList.splice(idx, 1)
  150. }
  151. })
  152. }
  153. },
  154. openTreePicker() {
  155. this.$refs.treePicker._show()
  156. },
  157. tableH(type) {
  158. return tableHeader(type)
  159. },
  160. getTreeList() {
  161. let params = {
  162. ids: [1, 5, 7, 8, 10, 14]
  163. }
  164. treeByPid(params).then(res => {
  165. this.classificationList = res
  166. this.confirm([res[0].id], res[0].name)
  167. })
  168. },
  169. confirm(id, name) {
  170. this.categoryLevelId = id
  171. this.getList()
  172. },
  173. doSearch() {
  174. this.page = 1
  175. this.getList()
  176. },
  177. scrolltolower() {
  178. if (isEnd) return
  179. this.page++
  180. this.getList()
  181. },
  182. getList() {
  183. let param = {
  184. categoryLevelId: this.categoryLevelId,
  185. keyWord: this.keyWord,
  186. pageNum: this.page,
  187. size: 100,
  188. }
  189. isEnd = false
  190. if (this.isType == 'pick') {
  191. param.dimension = 1
  192. pageeLedgerMain(param).then(res => {
  193. this.list.push(
  194. ...res.list.map(i => {
  195. const checked =
  196. this.memoList.findIndex(itm => itm.id === i.id) > -1
  197. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  198. return {
  199. checked,
  200. warehouseId,
  201. ...i,
  202. instanceId: i.id,
  203. categoryId: i.assetId,
  204. }
  205. })
  206. )
  207. isEnd = this.list.length >= res.count
  208. })
  209. } else if (this.isType == 'feed') {
  210. assetPage(param).then(res => {
  211. this.list.push(
  212. ...res.list.map(i => {
  213. const checked =
  214. this.memoList.findIndex(itm => itm.id === i.id) > -1
  215. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  216. if (i.rootCategoryLevelId == 1) {
  217. i.mattList = []
  218. }
  219. return {
  220. checked,
  221. warehouseId,
  222. ...i,
  223. instanceId: i.id,
  224. }
  225. })
  226. )
  227. isEnd = this.list.length >= res.count
  228. })
  229. }
  230. },
  231. //勾选
  232. selectVal(e, val, index) {
  233. if (this.isType == 'feed' && val.rootCategoryLevelId == 1) {
  234. this.$set(this.list[index], 'checked', false)
  235. if (val.mattList.length > 0) {
  236. this.mattList = val.mattList
  237. } else {
  238. this.memoList.forEach(m => {
  239. if (m.rootCategoryLevelId == 1) {
  240. this.mattList = this.mattList.concat(m.mattList)
  241. }
  242. })
  243. }
  244. this.categoryId = val.categoryId
  245. this.matterId = val.id
  246. this.matterShow = true
  247. } else {
  248. this.list[index].checked = !this.list[index].checked
  249. this.seletedAll = !this.list.some(item => !item.checked)
  250. const idx = this.memoList.findIndex(
  251. item => item.id === this.list[index].id
  252. )
  253. if (this.list[index].checked) {
  254. if (idx === -1) {
  255. this.memoList.push(this.list[index])
  256. }
  257. } else {
  258. if (idx > -1) {
  259. this.memoList.splice(idx, 1)
  260. }
  261. }
  262. }
  263. },
  264. close() {
  265. this.matterShow = false
  266. },
  267. mattSave(maList, id) {
  268. this.list.forEach(e => {
  269. if (e.id == id) {
  270. this.$set(e, 'checked', maList.length == 0 ? false : true)
  271. e.mattList = maList
  272. this.matterShow = false
  273. const idx = this.memoList.findIndex(
  274. item => item.id === id
  275. )
  276. this.list.forEach(e => {
  277. if (e.id == id) {
  278. if (e.checked && idx === -1) {
  279. this.memoList.push(e)
  280. } else if (!e.checked && idx > -1) {
  281. this.memoList.splice(idx, 1)
  282. }
  283. }
  284. })
  285. }
  286. })
  287. },
  288. //跳转回添加页面
  289. jumpAdd() {
  290. if (this.isType == 'pick') {
  291. uni.$emit('setSelectList', this.memoList, this.pid)
  292. uni.navigateBack()
  293. } else if (this.isType == 'feed') {
  294. uni.$emit('setSelectList', this.memoList, this.pid)
  295. uni.navigateBack()
  296. }
  297. },
  298. }
  299. }
  300. </script>
  301. <style lang="scss" scoped>
  302. .content-box {
  303. height: 100vh;
  304. overflow: hidden;
  305. display: flex;
  306. flex-direction: column;
  307. background-color: $page-bg;
  308. }
  309. .searchBox {
  310. background-color: #dedede;
  311. height: 90rpx;
  312. padding: 0 20rpx;
  313. input {
  314. height: 70rpx;
  315. width: 540rpx;
  316. background: #f9f9f9 !important;
  317. padding-left: 10rpx;
  318. border-radius: 5rpx;
  319. }
  320. }
  321. .list_box {
  322. flex: 1;
  323. overflow: hidden;
  324. padding: 6rpx 0;
  325. .u-list {
  326. height: 100% !important;
  327. }
  328. }
  329. .bottom-wrapper {
  330. height: 80rpx;
  331. background: #fff;
  332. padding: 0 32rpx;
  333. /deep/ .uni-checkbox-input-checked {
  334. background-color: $theme-color !important;
  335. border-color: $theme-color !important;
  336. }
  337. }
  338. .listBox {
  339. margin-top: 8rpx;
  340. padding: 8rpx 24rpx;
  341. background: #fff;
  342. /deep/ .uni-checkbox-input-checked {
  343. background-color: $theme-color !important;
  344. border-color: $theme-color !important;
  345. }
  346. .listBox-con {
  347. width: 650rpx;
  348. font-weight: 400;
  349. }
  350. .listBox-top {
  351. margin-top: 6rpx;
  352. color: #090A0A;
  353. font-size: 28rpx;
  354. font-style: normal;
  355. }
  356. .listBox-bottom {
  357. color: #090A0A;
  358. font-size: 24rpx;
  359. font-style: normal;
  360. flex-wrap: wrap;
  361. .items {
  362. width: 50%;
  363. margin-top: 8rpx;
  364. }
  365. }
  366. }
  367. .checkedClass {
  368. /deep/ .uni-checkbox-input-checked {
  369. background-color: #fff !important;
  370. border: 1px solid #d1d1d1 !important;
  371. }
  372. }
  373. </style>