index.vue 6.3 KB

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