index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. instanceId: i.id,
  167. categoryId: i.assetId
  168. }
  169. })
  170. )
  171. })
  172. },
  173. //勾选
  174. selectVal(e, val, index) {
  175. this.list[index].checked = !this.list[index].checked
  176. this.seletedAll = !this.list.some(item => !item.checked)
  177. const idx = this.memoList.findIndex(
  178. item => item.id === this.list[index].id
  179. )
  180. if (this.list[index].checked) {
  181. if (idx === -1) {
  182. this.memoList.push(this.list[index])
  183. }
  184. } else {
  185. if (idx > -1) {
  186. this.memoList.splice(idx, 1)
  187. }
  188. }
  189. },
  190. //跳转回添加页面
  191. jumpAdd() {
  192. uni.$emit('setSelectList', this.memoList, this.pid)
  193. uni.navigateBack()
  194. },
  195. }
  196. }
  197. </script>
  198. <style lang="scss" scoped>
  199. .content-box {
  200. height: 100vh;
  201. overflow: hidden;
  202. display: flex;
  203. flex-direction: column;
  204. background-color: $page-bg;
  205. }
  206. .searchBox {
  207. background-color: #dedede;
  208. height: 90rpx;
  209. padding: 0 20rpx;
  210. input {
  211. height: 70rpx;
  212. width: 540rpx;
  213. background: #f9f9f9 !important;
  214. padding-left: 10rpx;
  215. border-radius: 5rpx;
  216. }
  217. }
  218. .list_box {
  219. flex: 1;
  220. overflow: hidden;
  221. padding: 6rpx 0;
  222. .u-list {
  223. height: 100% !important;
  224. }
  225. }
  226. .bottom-wrapper {
  227. height: 80rpx;
  228. background: #fff;
  229. padding: 0 32rpx;
  230. /deep/ .uni-checkbox-input-checked {
  231. background-color: $theme-color !important;
  232. border-color: $theme-color !important;
  233. }
  234. }
  235. .listBox {
  236. margin-top: 8rpx;
  237. padding: 8rpx 24rpx;
  238. background: #fff;
  239. /deep/ .uni-checkbox-input-checked {
  240. background-color: $theme-color !important;
  241. border-color: $theme-color !important;
  242. }
  243. .listBox-con {
  244. width: 650rpx;
  245. font-weight: 400;
  246. }
  247. .listBox-top {
  248. margin-top: 6rpx;
  249. color: #090A0A;
  250. font-size: 28rpx;
  251. font-style: normal;
  252. }
  253. .listBox-bottom {
  254. color: #090A0A;
  255. font-size: 24rpx;
  256. font-style: normal;
  257. flex-wrap: wrap;
  258. .items {
  259. width: 50%;
  260. margin-top: 8rpx;
  261. }
  262. }
  263. }
  264. </style>