index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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.assetName }}</view>
  30. <view class="code">{{ item.assetCode}}</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
  38. class="items">
  39. 可用库存:{{ item.number }} {{item.unit}}
  40. </view>
  41. </view>
  42. </view>
  43. </label>
  44. </checkbox-group>
  45. <u-empty v-if='list.length == 0' style='margin-top: 20vh;' iconSize='150' textSize='32' text='暂无数据'>
  46. </u-empty>
  47. </u-list>
  48. </view>
  49. <view class="bottom-wrapper rx-bc">
  50. <view>
  51. <checkbox v-if="!seletedAll" color="#fff" :checked="seletedAll" @tap="_seletedAll">全选</checkbox>
  52. <checkbox class="select-all" color="#fff" v-else :checked="seletedAll" @tap="_seletedAll">取消全选
  53. </checkbox>
  54. </view>
  55. <view>
  56. <u-button type="success" size="small" class="u-reset-button" :disabled="!checkListLen" @click="jumpAdd">
  57. <view > 选择( {{ checkListLen }} ) </view>
  58. </u-button>
  59. </view>
  60. </view>
  61. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择分类"
  62. :localdata="classificationList" valueKey="id" textKey="name" childrenKey="children" />
  63. </view>
  64. </template>
  65. <script>
  66. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  67. import {
  68. tableHeader
  69. } from '../../common.js'
  70. import {
  71. treeByPid,
  72. pageeLedgerMain
  73. } from '@/api/pda/workOrder.js'
  74. export default {
  75. components: {
  76. baTreePicker
  77. },
  78. data() {
  79. return {
  80. keyWord: null,
  81. categoryLevelId: null,
  82. classificationList: [],
  83. treePickerShow: false,
  84. list: [],
  85. seletedAll: false, //全选状态
  86. memoList: [],
  87. pid: null, // 上个页面id
  88. storageKey: null
  89. }
  90. },
  91. //选择的列表长度
  92. computed: {
  93. checkListLen() {
  94. return this.memoList.length
  95. }
  96. },
  97. onLoad(option) {
  98. this.pid = option.id
  99. if(option.storageKey) {
  100. this.storageKey = option.storageKey
  101. this.memoList = (this.storageKey && uni.getStorageSync(this.storageKey )) || []
  102. }
  103. this.getTreeList()
  104. },
  105. onUnload() {
  106. if(this.storageKey) {
  107. uni.removeStorage(this.storageKey)
  108. }
  109. },
  110. methods: {
  111. _seletedAll() {
  112. if (!this.seletedAll) {
  113. this.seletedAll = true
  114. this.list.map(item => {
  115. this.$set(item, 'checked', true)
  116. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  117. if (idx === -1) {
  118. this.memoList.push(item)
  119. }
  120. })
  121. } else {
  122. this.seletedAll = false
  123. this.list.map(item => {
  124. this.$set(item, 'checked', false)
  125. const idx = this.memoList.findIndex(itm => itm.id === item.id)
  126. if (idx > -1) {
  127. this.memoList.splice(idx, 1)
  128. }
  129. })
  130. }
  131. },
  132. openTreePicker() {
  133. this.$refs.treePicker._show()
  134. },
  135. tableH(type) {
  136. return tableHeader(type)
  137. },
  138. getTreeList() {
  139. let params = {
  140. ids: [1, 5, 7, 8, 10, 14, ]
  141. }
  142. treeByPid(params).then(res => {
  143. this.classificationList = res
  144. this.confirm([res[0].id], res[0].name)
  145. })
  146. },
  147. confirm(id, name) {
  148. this.categoryLevelId = id
  149. this.getList()
  150. },
  151. getList() {
  152. let param = {
  153. categoryLevelId: this.categoryLevelId,
  154. keyWord: this.keyWord,
  155. pageNum: 1,
  156. size: -1
  157. }
  158. this.list = []
  159. pageeLedgerMain(param).then(res => {
  160. this.list.push(
  161. ...res.list.map(i => {
  162. const checked =
  163. this.memoList.findIndex(itm => itm.id === i.id) > -1
  164. return {
  165. checked,
  166. ...i
  167. }
  168. })
  169. )
  170. })
  171. },
  172. //勾选
  173. selectVal(e, val, index) {
  174. this.list[index].checked = !this.list[index].checked
  175. this.seletedAll = !this.list.some(item => !item.checked)
  176. const idx = this.memoList.findIndex(
  177. item => item.id === this.list[index].id
  178. )
  179. if (this.list[index].checked) {
  180. if (idx === -1) {
  181. this.memoList.push(this.list[index])
  182. }
  183. } else {
  184. if (idx > -1) {
  185. this.memoList.splice(idx, 1)
  186. }
  187. }
  188. },
  189. //跳转回添加页面
  190. jumpAdd () {
  191. uni.$emit('setSelectList', this.memoList, this.pid)
  192. uni.navigateBack()
  193. },
  194. }
  195. }
  196. </script>
  197. <style lang="scss" scoped>
  198. .content-box {
  199. height: 100vh;
  200. overflow: hidden;
  201. display: flex;
  202. flex-direction: column;
  203. background-color: $page-bg;
  204. }
  205. .searchBox {
  206. background-color: #dedede;
  207. height: 90rpx;
  208. padding: 0 20rpx;
  209. input {
  210. height: 70rpx;
  211. width: 540rpx;
  212. background: #f9f9f9 !important;
  213. padding-left: 10rpx;
  214. border-radius: 5rpx;
  215. }
  216. }
  217. .list_box {
  218. flex: 1;
  219. overflow: hidden;
  220. padding: 6rpx 0;
  221. .u-list {
  222. height: 100% !important;
  223. }
  224. }
  225. .bottom-wrapper {
  226. height: 80rpx;
  227. background: #fff;
  228. padding: 0 32rpx;
  229. /deep/ .uni-checkbox-input-checked {
  230. background-color: $theme-color !important;
  231. border-color: $theme-color !important;
  232. }
  233. }
  234. .listBox {
  235. margin-top: 8rpx;
  236. padding: 8rpx 24rpx;
  237. background: #fff;
  238. /deep/ .uni-checkbox-input-checked {
  239. background-color: $theme-color !important;
  240. border-color: $theme-color !important;
  241. }
  242. .listBox-con {
  243. width: 650rpx;
  244. font-weight: 400;
  245. }
  246. .listBox-top {
  247. margin-top: 6rpx;
  248. color: #090A0A;
  249. font-size: 28rpx;
  250. font-style: normal;
  251. }
  252. .listBox-bottom {
  253. color: #090A0A;
  254. font-size: 24rpx;
  255. font-style: normal;
  256. flex-wrap: wrap;
  257. .items {
  258. width: 50%;
  259. margin-top: 8rpx;
  260. }
  261. }
  262. }
  263. </style>