index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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" color="#fff" :disabled="item.disabled"
  25. :checked="item.checked" />
  26. </view>
  27. <view class="listBox-con">
  28. <view class="listBox-top rx-bc">
  29. <view> {{ item.name }}</view>
  30. <view class="code">{{ item.code}}</view>
  31. </view>
  32. <view class="listBox-bottom rx">
  33. <view v-for="(itm, index) in tableH(item.rootCategoryLevelId)" :key="index"
  34. class="items">
  35. {{ itm.label }}:{{ item[itm.prop] }}
  36. </view>
  37. <view class="items">
  38. 可用库存:{{ item.availableCountBase }} {{item.unit}}
  39. </view>
  40. </view>
  41. </view>
  42. </label>
  43. </checkbox-group>
  44. <view v-if='list.length == 0' style='margin-top: 20vh;'>
  45. <u-empty iconSize='150' textSize='32' text='暂无数据'>
  46. </u-empty>
  47. </view>
  48. </u-list>
  49. </view>
  50. <view class="bottom-wrapper rx-bc">
  51. <view>
  52. <checkbox v-if="!seletedAll" color="#fff" :checked="seletedAll" @tap="_seletedAll">全选</checkbox>
  53. <checkbox class="select-all" color="#fff" v-else :checked="seletedAll" @tap="_seletedAll">取消全选
  54. </checkbox>
  55. </view>
  56. <view>
  57. <u-button type="success" size="small" class="u-reset-button" :disabled="!checkListLen" @click="jumpAdd">
  58. <view> 选择( {{ checkListLen }} ) </view>
  59. </u-button>
  60. </view>
  61. </view>
  62. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择分类"
  63. :localdata="classificationList" valueKey="id" textKey="name" childrenKey="children" />
  64. </view>
  65. </template>
  66. <script>
  67. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  68. import {
  69. tableHeader
  70. } from '../../common.js'
  71. import {
  72. treeByPid,
  73. pageeLedgerMain,
  74. assetPage
  75. } from '@/api/pda/workOrder.js'
  76. let [isEnd] = [false]
  77. export default {
  78. components: {
  79. baTreePicker,
  80. },
  81. data() {
  82. return {
  83. keyWord: null,
  84. categoryLevelId: null,
  85. classificationList: [],
  86. treePickerShow: false,
  87. list: [],
  88. page: 1,
  89. seletedAll: false, //全选状态
  90. memoList: [],
  91. isType: null,
  92. pid: null, // 上个页面id
  93. storageKey: null,
  94. }
  95. },
  96. //选择的列表长度
  97. computed: {
  98. checkListLen() {
  99. return this.memoList.length
  100. }
  101. },
  102. onLoad(option) {
  103. this.pid = option.id
  104. this.isType = option.isType
  105. if (option.storageKey) {
  106. this.storageKey = option.storageKey
  107. if (this.isType == 'feed') {
  108. let _arr = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  109. this.memoList = [..._arr[0].modelList, ..._arr[0].equipmentList, ..._arr[0].instanceList]
  110. } else if (this.isType == 'pick') {
  111. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  112. } else if (this.isType == 'job') {
  113. let _obj = (this.storageKey && uni.getStorageSync(this.storageKey)) || {}
  114. this.memoList = [ ..._obj.turnover ]
  115. }
  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. if (this.isType == 'feed') {
  155. params.ids = [1, 5, 7, 8, 10, 14]
  156. } else if (this.isType == 'pick') {
  157. params.ids = [1, 5, 7, 8, 10, 14]
  158. } else if (this.isType == 'job') {
  159. params['ids'] = [7, 11]
  160. }
  161. treeByPid(params).then(res => {
  162. this.classificationList = res
  163. this.confirm([res[0].id], res[0].name)
  164. })
  165. },
  166. confirm(id, name) {
  167. this.categoryLevelId = id
  168. this.list = []
  169. this.getList()
  170. },
  171. doSearch() {
  172. this.list = []
  173. this.getList()
  174. },
  175. scrolltolower() {
  176. if (isEnd) return
  177. this.page++
  178. this.getList()
  179. },
  180. getList() {
  181. let param = {
  182. categoryLevelId: this.categoryLevelId,
  183. keyWord: this.keyWord,
  184. pageNum: this.page,
  185. size: 100,
  186. }
  187. isEnd = false
  188. let URL = null
  189. if (this.isType == 'pick') { // 领料
  190. param.dimension = 1
  191. URL = pageeLedgerMain
  192. } else if (this.isType == 'feed') { // 投料
  193. URL = assetPage
  194. } else if (this.isType == 'job') { // 报工
  195. URL = assetPage
  196. }
  197. URL(param).then(res => {
  198. this.list.push(
  199. ...res.list.map(i => {
  200. const checked =
  201. this.memoList.findIndex(itm => itm.id === i.id) > -1
  202. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  203. return {
  204. checked,
  205. warehouseId,
  206. ...i,
  207. instanceId: i.id,
  208. }
  209. })
  210. )
  211. isEnd = this.list.length >= res.count
  212. })
  213. },
  214. //勾选
  215. selectVal(e, val, index) {
  216. this.list[index].checked = !this.list[index].checked
  217. this.seletedAll = !this.list.some(item => !item.checked)
  218. const idx = this.memoList.findIndex(
  219. item => item.id === this.list[index].id
  220. )
  221. if (this.list[index].checked) {
  222. if (idx === -1) {
  223. this.memoList.push(this.list[index])
  224. }
  225. } else {
  226. if (idx > -1) {
  227. this.memoList.splice(idx, 1)
  228. }
  229. }
  230. },
  231. //跳转回添加页面
  232. jumpAdd() {
  233. if (this.isType == 'pick' || this.isType == 'feed' || this.isType == 'job') {
  234. uni.$emit('setSelectList', this.memoList, this.pid)
  235. uni.navigateBack()
  236. }
  237. },
  238. }
  239. }
  240. </script>
  241. <style lang="scss" scoped>
  242. .content-box {
  243. height: 100vh;
  244. overflow: hidden;
  245. display: flex;
  246. flex-direction: column;
  247. background-color: $page-bg;
  248. }
  249. .searchBox {
  250. background-color: #dedede;
  251. height: 90rpx;
  252. padding: 0 20rpx;
  253. input {
  254. height: 70rpx;
  255. width: 540rpx;
  256. background: #f9f9f9 !important;
  257. padding-left: 10rpx;
  258. border-radius: 5rpx;
  259. }
  260. }
  261. .list_box {
  262. flex: 1;
  263. overflow: hidden;
  264. padding: 6rpx 0;
  265. .u-list {
  266. height: 100% !important;
  267. }
  268. }
  269. .bottom-wrapper {
  270. height: 80rpx;
  271. background: #fff;
  272. padding: 0 32rpx;
  273. /deep/ .uni-checkbox-input-checked {
  274. background-color: $theme-color !important;
  275. border-color: $theme-color !important;
  276. }
  277. }
  278. .listBox {
  279. margin-top: 8rpx;
  280. padding: 8rpx 24rpx;
  281. background: #fff;
  282. /deep/ .uni-checkbox-input-checked {
  283. background-color: $theme-color !important;
  284. border-color: $theme-color !important;
  285. }
  286. .listBox-con {
  287. width: 650rpx;
  288. font-weight: 400;
  289. }
  290. .listBox-top {
  291. margin-top: 6rpx;
  292. color: #090A0A;
  293. font-size: 28rpx;
  294. font-style: normal;
  295. }
  296. .listBox-bottom {
  297. color: #090A0A;
  298. font-size: 24rpx;
  299. font-style: normal;
  300. flex-wrap: wrap;
  301. .items {
  302. width: 50%;
  303. margin-top: 8rpx;
  304. }
  305. }
  306. }
  307. </style>