index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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. this.memoList = []
  108. if (this.isType == 'feed') {
  109. let _arr = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  110. this.memoList = [..._arr[0].modelList, ..._arr[0].equipmentList, ..._arr[0].instanceList]
  111. } else if (this.isType == 'pick') {
  112. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  113. } else if (this.isType == 'job') {
  114. let _obj = (this.storageKey && uni.getStorageSync(this.storageKey)) || {}
  115. this.memoList = [..._obj.turnover]
  116. }
  117. }
  118. this.getTreeList()
  119. },
  120. onUnload() {
  121. if (this.storageKey) {
  122. uni.removeStorage(this.storageKey)
  123. }
  124. },
  125. methods: {
  126. _seletedAll() {
  127. if (!this.seletedAll) {
  128. this.seletedAll = true
  129. this.list.map(item => {
  130. this.$set(item, 'checked', true)
  131. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  132. if (idx === -1) {
  133. this.memoList.push(item)
  134. }
  135. })
  136. } else {
  137. this.seletedAll = false
  138. this.list.map(item => {
  139. this.$set(item, 'checked', false)
  140. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  141. if (idx > -1) {
  142. this.memoList.splice(idx, 1)
  143. }
  144. })
  145. }
  146. },
  147. openTreePicker() {
  148. this.$refs.treePicker._show()
  149. },
  150. tableH(type) {
  151. return tableHeader(type)
  152. },
  153. getTreeList() {
  154. let params = {}
  155. if (this.isType == 'feed') {
  156. params.ids = [1, 5, 7, 8, 10, 14]
  157. } else if (this.isType == 'pick') {
  158. params.ids = [1, 5, 7, 8, 10, 14]
  159. } else if (this.isType == 'job') {
  160. params['ids'] = [7, 11]
  161. }
  162. treeByPid(params).then(res => {
  163. this.classificationList = res
  164. this.confirm([res[0].id], res[0].name)
  165. })
  166. },
  167. confirm(id, name) {
  168. this.categoryLevelId = id
  169. this.list = []
  170. this.getList()
  171. },
  172. doSearch() {
  173. this.list = []
  174. this.getList()
  175. },
  176. scrolltolower() {
  177. if (isEnd) return
  178. this.page++
  179. this.getList()
  180. },
  181. getList() {
  182. let param = {
  183. categoryLevelId: this.categoryLevelId,
  184. keyWord: this.keyWord,
  185. pageNum: this.page,
  186. size: 100,
  187. }
  188. isEnd = false
  189. let URL = null
  190. if (this.isType == 'pick') { // 领料
  191. param.dimension = 1
  192. URL = pageeLedgerMain
  193. } else if (this.isType == 'feed') { // 投料
  194. URL = assetPage
  195. } else if (this.isType == 'job') { // 报工
  196. URL = assetPage
  197. }
  198. URL(param).then(res => {
  199. this.list.push(
  200. ...res.list.map(i => {
  201. const checked =
  202. this.memoList.findIndex(itm => itm.id === i.id) > -1
  203. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  204. return {
  205. checked,
  206. warehouseId,
  207. ...i,
  208. instanceId: i.id,
  209. }
  210. })
  211. )
  212. isEnd = this.list.length >= res.count
  213. })
  214. },
  215. //勾选
  216. selectVal(e, val, index) {
  217. this.list[index].checked = !this.list[index].checked
  218. this.seletedAll = !this.list.some(item => !item.checked)
  219. const idx = this.memoList.findIndex(
  220. item => item.id === this.list[index].id
  221. )
  222. if (this.list[index].checked) {
  223. if (idx === -1) {
  224. this.memoList.push(this.list[index])
  225. }
  226. } else {
  227. if (idx > -1) {
  228. this.memoList.splice(idx, 1)
  229. }
  230. }
  231. },
  232. //跳转回添加页面
  233. jumpAdd() {
  234. if (this.isType == 'pick' || this.isType == 'feed' || this.isType == 'job') {
  235. uni.$emit('setSelectList', this.memoList, this.pid)
  236. uni.navigateBack()
  237. }
  238. },
  239. }
  240. }
  241. </script>
  242. <style lang="scss" scoped>
  243. .content-box {
  244. height: 100vh;
  245. overflow: hidden;
  246. display: flex;
  247. flex-direction: column;
  248. background-color: $page-bg;
  249. }
  250. .searchBox {
  251. background-color: #dedede;
  252. height: 90rpx;
  253. padding: 0 20rpx;
  254. input {
  255. height: 70rpx;
  256. width: 540rpx;
  257. background: #f9f9f9 !important;
  258. padding-left: 10rpx;
  259. border-radius: 5rpx;
  260. }
  261. }
  262. .list_box {
  263. flex: 1;
  264. overflow: hidden;
  265. padding: 6rpx 0;
  266. .u-list {
  267. height: 100% !important;
  268. }
  269. }
  270. .bottom-wrapper {
  271. height: 80rpx;
  272. background: #fff;
  273. padding: 0 32rpx;
  274. /deep/ .uni-checkbox-input-checked {
  275. background-color: $theme-color !important;
  276. border-color: $theme-color !important;
  277. }
  278. }
  279. .listBox {
  280. margin-top: 8rpx;
  281. padding: 8rpx 24rpx;
  282. background: #fff;
  283. /deep/ .uni-checkbox-input-checked {
  284. background-color: $theme-color !important;
  285. border-color: $theme-color !important;
  286. }
  287. .listBox-con {
  288. width: 650rpx;
  289. font-weight: 400;
  290. }
  291. .listBox-top {
  292. margin-top: 6rpx;
  293. color: #090A0A;
  294. font-size: 28rpx;
  295. font-style: normal;
  296. }
  297. .listBox-bottom {
  298. color: #090A0A;
  299. font-size: 24rpx;
  300. font-style: normal;
  301. flex-wrap: wrap;
  302. .items {
  303. width: 50%;
  304. margin-top: 8rpx;
  305. }
  306. }
  307. }
  308. </style>