index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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="getList" 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>
  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. export default {
  82. components: {
  83. baTreePicker,
  84. matterPop
  85. },
  86. data() {
  87. return {
  88. keyWord: null,
  89. categoryLevelId: null,
  90. classificationList: [],
  91. treePickerShow: false,
  92. list: [],
  93. seletedAll: false, //全选状态
  94. memoList: [],
  95. isType: null,
  96. pid: null, // 上个页面id
  97. storageKey: null,
  98. matterShow: false, //物料 左弹框
  99. matterId: null,
  100. categoryId: null,
  101. mattList: []
  102. }
  103. },
  104. //选择的列表长度
  105. computed: {
  106. checkListLen() {
  107. return this.memoList.length
  108. }
  109. },
  110. onLoad(option) {
  111. this.pid = option.id
  112. this.isType = option.isType
  113. if (option.storageKey) {
  114. this.storageKey = option.storageKey
  115. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  116. }
  117. this.getTreeList()
  118. },
  119. onUnload() {
  120. if (this.storageKey) {
  121. uni.removeStorage(this.storageKey)
  122. }
  123. },
  124. methods: {
  125. _seletedAll() {
  126. if (!this.seletedAll) {
  127. this.seletedAll = true
  128. this.list.map(item => {
  129. this.$set(item, 'checked', true)
  130. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  131. if (idx === -1) {
  132. this.memoList.push(item)
  133. }
  134. })
  135. } else {
  136. this.seletedAll = false
  137. this.list.map(item => {
  138. this.$set(item, 'checked', false)
  139. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  140. if (idx > -1) {
  141. this.memoList.splice(idx, 1)
  142. }
  143. })
  144. }
  145. },
  146. openTreePicker() {
  147. this.$refs.treePicker._show()
  148. },
  149. tableH(type) {
  150. return tableHeader(type)
  151. },
  152. getTreeList() {
  153. let params = {
  154. ids: [1, 5, 7, 8, 10, 14]
  155. }
  156. treeByPid(params).then(res => {
  157. this.classificationList = res
  158. this.confirm([res[0].id], res[0].name)
  159. })
  160. },
  161. confirm(id, name) {
  162. this.categoryLevelId = id
  163. this.getList()
  164. },
  165. getList() {
  166. let param = {
  167. categoryLevelId: this.categoryLevelId,
  168. keyWord: this.keyWord,
  169. pageNum: 1,
  170. size: -1,
  171. }
  172. this.list = []
  173. if (this.isType == 'pick') {
  174. param.dimension = 1
  175. pageeLedgerMain(param).then(res => {
  176. this.list.push(
  177. ...res.list.map(i => {
  178. const checked =
  179. this.memoList.findIndex(itm => itm.id === i.id) > -1
  180. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  181. return {
  182. checked,
  183. warehouseId,
  184. ...i,
  185. instanceId: i.id,
  186. categoryId: i.assetId,
  187. }
  188. })
  189. )
  190. })
  191. } else if (this.isType == 'feed') {
  192. assetPage(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. if (i.rootCategoryLevelId == 1) {
  199. i.mattList = []
  200. }
  201. return {
  202. checked,
  203. warehouseId,
  204. ...i,
  205. instanceId: i.id,
  206. }
  207. })
  208. )
  209. })
  210. }
  211. },
  212. //勾选
  213. selectVal(e, val, index) {
  214. if (this.isType == 'feed' && val.rootCategoryLevelId == 1) {
  215. this.$set(this.list[index], 'checked', false)
  216. if (val.mattList.length > 0) {
  217. this.mattList = val.mattList
  218. } else {
  219. this.memoList.forEach(m => {
  220. if (m.rootCategoryLevelId == 1) {
  221. this.mattList = this.mattList.concat(m.mattList)
  222. }
  223. })
  224. }
  225. this.categoryId = val.categoryId
  226. this.matterId = val.id
  227. this.matterShow = true
  228. } else {
  229. this.list[index].checked = !this.list[index].checked
  230. this.seletedAll = !this.list.some(item => !item.checked)
  231. const idx = this.memoList.findIndex(
  232. item => item.id === this.list[index].id
  233. )
  234. if (this.list[index].checked) {
  235. if (idx === -1) {
  236. this.memoList.push(this.list[index])
  237. }
  238. } else {
  239. if (idx > -1) {
  240. this.memoList.splice(idx, 1)
  241. }
  242. }
  243. }
  244. },
  245. close() {
  246. this.matterShow = false
  247. },
  248. mattSave(maList, id) {
  249. this.list.forEach(e => {
  250. if (e.id == id) {
  251. this.$set(e, 'checked', maList.length == 0 ? false : true)
  252. e.mattList = maList
  253. this.matterShow = false
  254. const idx = this.memoList.findIndex(
  255. item => item.id === id
  256. )
  257. this.list.forEach(e => {
  258. if (e.id == id) {
  259. if (e.checked && idx === -1) {
  260. this.memoList.push(e)
  261. } else if (!e.checked && idx > -1) {
  262. this.memoList.splice(idx, 1)
  263. }
  264. }
  265. })
  266. }
  267. })
  268. },
  269. //跳转回添加页面
  270. jumpAdd() {
  271. if (this.isType == 'pick') {
  272. uni.$emit('setSelectList', this.memoList, this.pid)
  273. uni.navigateBack()
  274. } else if (this.isType == 'feed') {
  275. uni.$emit('setSelectList', this.memoList, this.pid)
  276. uni.navigateBack()
  277. }
  278. },
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .content-box {
  284. height: 100vh;
  285. overflow: hidden;
  286. display: flex;
  287. flex-direction: column;
  288. background-color: $page-bg;
  289. }
  290. .searchBox {
  291. background-color: #dedede;
  292. height: 90rpx;
  293. padding: 0 20rpx;
  294. input {
  295. height: 70rpx;
  296. width: 540rpx;
  297. background: #f9f9f9 !important;
  298. padding-left: 10rpx;
  299. border-radius: 5rpx;
  300. }
  301. }
  302. .list_box {
  303. flex: 1;
  304. overflow: hidden;
  305. padding: 6rpx 0;
  306. .u-list {
  307. height: 100% !important;
  308. }
  309. }
  310. .bottom-wrapper {
  311. height: 80rpx;
  312. background: #fff;
  313. padding: 0 32rpx;
  314. /deep/ .uni-checkbox-input-checked {
  315. background-color: $theme-color !important;
  316. border-color: $theme-color !important;
  317. }
  318. }
  319. .listBox {
  320. margin-top: 8rpx;
  321. padding: 8rpx 24rpx;
  322. background: #fff;
  323. /deep/ .uni-checkbox-input-checked {
  324. background-color: $theme-color !important;
  325. border-color: $theme-color !important;
  326. }
  327. .listBox-con {
  328. width: 650rpx;
  329. font-weight: 400;
  330. }
  331. .listBox-top {
  332. margin-top: 6rpx;
  333. color: #090A0A;
  334. font-size: 28rpx;
  335. font-style: normal;
  336. }
  337. .listBox-bottom {
  338. color: #090A0A;
  339. font-size: 24rpx;
  340. font-style: normal;
  341. flex-wrap: wrap;
  342. .items {
  343. width: 50%;
  344. margin-top: 8rpx;
  345. }
  346. }
  347. }
  348. .checkedClass {
  349. /deep/ .uni-checkbox-input-checked {
  350. background-color: #fff !important;
  351. border: 1px solid #d1d1d1 !important;
  352. }
  353. }
  354. </style>