index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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" 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. } from '@/api/pda/workOrder.js'
  75. export default {
  76. components: {
  77. baTreePicker
  78. },
  79. data() {
  80. return {
  81. keyWord: null,
  82. categoryLevelId: null,
  83. classificationList: [],
  84. treePickerShow: false,
  85. list: [],
  86. seletedAll: false, //全选状态
  87. memoList: [],
  88. pid: null, // 上个页面id
  89. storageKey: null
  90. }
  91. },
  92. //选择的列表长度
  93. computed: {
  94. checkListLen() {
  95. return this.memoList.length
  96. }
  97. },
  98. onLoad(option) {
  99. this.pid = option.id
  100. if (option.storageKey) {
  101. this.storageKey = option.storageKey
  102. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey)) || []
  103. }
  104. this.getTreeList()
  105. },
  106. onUnload() {
  107. if (this.storageKey) {
  108. uni.removeStorage(this.storageKey)
  109. }
  110. },
  111. methods: {
  112. _seletedAll() {
  113. if (!this.seletedAll) {
  114. this.seletedAll = true
  115. this.list.map(item => {
  116. this.$set(item, 'checked', true)
  117. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  118. if (idx === -1) {
  119. this.memoList.push(item)
  120. }
  121. })
  122. } else {
  123. this.seletedAll = false
  124. this.list.map(item => {
  125. this.$set(item, 'checked', false)
  126. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  127. if (idx > -1) {
  128. this.memoList.splice(idx, 1)
  129. }
  130. })
  131. }
  132. },
  133. openTreePicker() {
  134. this.$refs.treePicker._show()
  135. },
  136. tableH(type) {
  137. return tableHeader(type)
  138. },
  139. getTreeList() {
  140. let params = {
  141. ids: [1, 5, 7, 8, 10, 14, 4]
  142. }
  143. treeByPid(params).then(res => {
  144. this.classificationList = res
  145. this.confirm([res[0].id], res[0].name)
  146. })
  147. },
  148. confirm(id, name) {
  149. this.categoryLevelId = id
  150. this.getList()
  151. },
  152. getList() {
  153. let param = {
  154. categoryLevelId: this.categoryLevelId,
  155. keyWord: this.keyWord,
  156. pageNum: 1,
  157. size: -1,
  158. dimension: 1
  159. }
  160. this.list = []
  161. pageeLedgerMain(param).then(res => {
  162. this.list.push(
  163. ...res.list.map(i => {
  164. const checked =
  165. this.memoList.findIndex(itm => itm.id === i.id) > -1
  166. const warehouseId = i.pathIds && i.pathIds.split(',')[0]
  167. return {
  168. checked,
  169. warehouseId,
  170. ...i,
  171. instanceId: i.id,
  172. categoryId: i.assetId,
  173. }
  174. })
  175. )
  176. })
  177. },
  178. //勾选
  179. selectVal(e, val, index) {
  180. this.list[index].checked = !this.list[index].checked
  181. this.seletedAll = !this.list.some(item => !item.checked)
  182. const idx = this.memoList.findIndex(
  183. item => item.id === this.list[index].id
  184. )
  185. if (this.list[index].checked) {
  186. if (idx === -1) {
  187. this.memoList.push(this.list[index])
  188. }
  189. } else {
  190. if (idx > -1) {
  191. this.memoList.splice(idx, 1)
  192. }
  193. }
  194. },
  195. //跳转回添加页面
  196. jumpAdd() {
  197. uni.$emit('setSelectList', this.memoList, this.pid)
  198. uni.navigateBack()
  199. },
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .content-box {
  205. height: 100vh;
  206. overflow: hidden;
  207. display: flex;
  208. flex-direction: column;
  209. background-color: $page-bg;
  210. }
  211. .searchBox {
  212. background-color: #dedede;
  213. height: 90rpx;
  214. padding: 0 20rpx;
  215. input {
  216. height: 70rpx;
  217. width: 540rpx;
  218. background: #f9f9f9 !important;
  219. padding-left: 10rpx;
  220. border-radius: 5rpx;
  221. }
  222. }
  223. .list_box {
  224. flex: 1;
  225. overflow: hidden;
  226. padding: 6rpx 0;
  227. .u-list {
  228. height: 100% !important;
  229. }
  230. }
  231. .bottom-wrapper {
  232. height: 80rpx;
  233. background: #fff;
  234. padding: 0 32rpx;
  235. /deep/ .uni-checkbox-input-checked {
  236. background-color: $theme-color !important;
  237. border-color: $theme-color !important;
  238. }
  239. }
  240. .listBox {
  241. margin-top: 8rpx;
  242. padding: 8rpx 24rpx;
  243. background: #fff;
  244. /deep/ .uni-checkbox-input-checked {
  245. background-color: $theme-color !important;
  246. border-color: $theme-color !important;
  247. }
  248. .listBox-con {
  249. width: 650rpx;
  250. font-weight: 400;
  251. }
  252. .listBox-top {
  253. margin-top: 6rpx;
  254. color: #090A0A;
  255. font-size: 28rpx;
  256. font-style: normal;
  257. }
  258. .listBox-bottom {
  259. color: #090A0A;
  260. font-size: 24rpx;
  261. font-style: normal;
  262. flex-wrap: wrap;
  263. .items {
  264. width: 50%;
  265. margin-top: 8rpx;
  266. }
  267. }
  268. }
  269. </style>