index.vue 9.3 KB

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