index.vue 6.5 KB

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