index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <view class="">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. title="选择备品备件"
  8. @clickLeft="onBack"
  9. >
  10. <template slot="float">
  11. <view class="nav-icon-caozuo">
  12. <u-button
  13. click="nav-icon-caozuo"
  14. type="primary"
  15. size="small"
  16. @click="jump"
  17. >选择</u-button
  18. >
  19. </view>
  20. </template>
  21. </uni-nav-bar>
  22. <view class="fixed">
  23. <view class="search_box">
  24. <u--input v-model="params.code" placeholder="请输入编码"></u--input>
  25. <u-button type="primary" @click="onSearch">
  26. <u-icon name="search" size="40rpx" color="#fff"></u-icon>搜索
  27. </u-button>
  28. </view>
  29. <view class="tabList">
  30. <view class="left">
  31. <view
  32. v-for="(item, idx) in tabList"
  33. :key="idx"
  34. :class="[idx === pickTabIndex ? 'active' : '', 'tab-item']"
  35. @click="onTabClick(idx)"
  36. >
  37. {{ item.name }}
  38. </view>
  39. </view>
  40. <view class="right">
  41. <text @click="onScreen">筛选</text>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="mt100" v-if="tabList[pickTabIndex]">
  46. <view
  47. class=""
  48. v-for="(item, index) in tabList[pickTabIndex].list"
  49. :key="index"
  50. @click="handleCheckboxChange(index)"
  51. >
  52. <u-checkbox-group v-model="checkboxValue">
  53. <view class="checkbox_flex">
  54. <u-checkbox :name="index"> </u-checkbox>
  55. <view class="content">
  56. <OrderList
  57. lable1=""
  58. :value1="item.name"
  59. lable2=""
  60. :value2="
  61. item.sparepartTypeCode ? item.sparepartTypeCode.name : ''
  62. "
  63. lable3="入库类型:"
  64. :value3="item.code"
  65. lable4=""
  66. :value4="item.spec"
  67. ></OrderList>
  68. </view>
  69. </view>
  70. </u-checkbox-group>
  71. </view>
  72. <view v-show="tabList[pickTabIndex].list.length === 0" class="no_data">
  73. <u-empty mode="data"></u-empty>
  74. </view>
  75. </view>
  76. <u-picker
  77. :show="linkageShow"
  78. ref="uPicker"
  79. :columns="columns"
  80. key-name="name"
  81. @confirm="onConfirm"
  82. @cancel="linkageShow = false"
  83. @change="changeHandler"
  84. ></u-picker>
  85. </view>
  86. </template>
  87. <script>
  88. import { get, post } from '@/utils/api.js'
  89. import OrderList from '../components/OrderList.vue'
  90. export default {
  91. components: {
  92. OrderList
  93. },
  94. data () {
  95. return {
  96. checkboxValue: [],
  97. linkageShow: false,
  98. params: {
  99. code: '',
  100. page: 1,
  101. size: 10,
  102. sparepartTypeCode: ''
  103. },
  104. code: '',
  105. columns: [],
  106. tabList: [],
  107. columnData: [],
  108. pickTabIndex: 0,
  109. isEnd: true
  110. }
  111. },
  112. onShow () {
  113. this.getInit()
  114. },
  115. onReachBottom () {
  116. if (this.isEnd) return
  117. uni.showLoading({
  118. title: '加载中'
  119. })
  120. this.params.page++
  121. this.getSparepartList()
  122. },
  123. methods: {
  124. jump () {
  125. let arr = this.tabList[this.pickTabIndex].list.filter((item, idx) =>
  126. this.checkboxValue.some(el => idx === el)
  127. )
  128. this.$store.dispatch('tour_tally/setSelectSparepart', arr)
  129. uni.redirectTo({
  130. url: '/pages/put_storage/add/index'
  131. })
  132. },
  133. onBack () {
  134. uni.redirectTo({
  135. url: '/pages/put_storage/add/index'
  136. })
  137. },
  138. handleCheckboxChange (idx) {
  139. if (this.checkboxValue.includes(idx)) {
  140. let index = this.checkboxValue.findIndex(item => item === idx)
  141. this.checkboxValue.splice(index, 1)
  142. } else {
  143. this.checkboxValue.push(idx)
  144. }
  145. },
  146. changeHandler (e) {
  147. const {
  148. columnIndex,
  149. value,
  150. values, // values为当前变化列的数组内容
  151. index,
  152. // 微信小程序无法将picker实例传出来,只能通过ref操作
  153. picker = this.$refs.uPicker
  154. } = e
  155. // 当第一列值发生变化时,变化第二列(后一列)对应的选项
  156. if (columnIndex === 0) {
  157. // picker为选择器this实例,变化第二列对应的选项
  158. this.columnData = this.tabList[this.pickTabIndex].children[index]
  159. .children
  160. ? this.tabList[this.pickTabIndex].children[index].children
  161. : []
  162. picker.setColumnValues(1, this.columnData)
  163. }
  164. },
  165. onConfirm (e) {
  166. if (e.value && e.value.length > 1) {
  167. this.code = e.value[1].code
  168. } else {
  169. this.code = e.value[0].code
  170. }
  171. uni.showLoading({
  172. title: '加载中'
  173. })
  174. this.getSparepartList()
  175. this.linkageShow = false
  176. },
  177. onScreen () {
  178. if (this.pickTabIndex) {
  179. this.linkageShow = true
  180. this.columns = [this.tabList[this.pickTabIndex].children]
  181. const picker = this.$refs.uPicker
  182. this.columnData = this.tabList[this.pickTabIndex].children[0].children
  183. ? this.tabList[this.pickTabIndex].children[0].children
  184. : []
  185. this.$nextTick(() => {
  186. picker.setColumnValues(1, this.columnData)
  187. })
  188. }
  189. },
  190. onSearch () {
  191. this.params.page = 1
  192. uni.showLoading({
  193. title: '加载中'
  194. })
  195. this.getSparepartList()
  196. },
  197. async getSparepartList () {
  198. let res = await this.getList(this.code)
  199. uni.hideLoading()
  200. if (this.params.page === 1) {
  201. this.tabList[this.pickTabIndex].list = res.items
  202. } else {
  203. res.items.forEach(item => {
  204. this.tabList[this.pickTabIndex].list.push(item)
  205. })
  206. }
  207. this.$forceUpdate()
  208. this.params.page < res.pageTotal
  209. ? (this.isEnd = false)
  210. : (this.isEnd = true)
  211. },
  212. onTabClick (idx) {
  213. this.pickTabIndex = idx
  214. this.params.page = 1
  215. uni.showLoading({
  216. title: '加载中'
  217. })
  218. this.code = this.tabList[idx].code
  219. this.getSparepartList()
  220. },
  221. getTree () {
  222. return new Promise((resolve, reject) => {
  223. get(this.apiUrl + '/feature/type/spareparts/tree?type=3').then(res => {
  224. if (res.success) {
  225. this.code = res.data[0].code
  226. resolve(res.data)
  227. }
  228. })
  229. })
  230. },
  231. getList (code) {
  232. this.params.sparepartTypeCode = code
  233. return new Promise((resolve, reject) => {
  234. post(
  235. this.apiUrl + '/feature/book/spareparts/sparepartList',
  236. this.params
  237. ).then(res => {
  238. if (res.success) {
  239. resolve(res.data)
  240. }
  241. })
  242. })
  243. },
  244. async getInit () {
  245. uni.showLoading({
  246. title: '加载中'
  247. })
  248. let res = await this.getTree()
  249. uni.hideLoading()
  250. this.getTabList(res)
  251. this.getSparepartList()
  252. },
  253. getTabList (list) {
  254. if (list && list.length !== 0) {
  255. list.forEach(item => {
  256. item.name = '全部'
  257. item.list = []
  258. this.tabList.push(item)
  259. if (item.children && item.children.length !== 0) {
  260. item.children.forEach(el => {
  261. el.list = []
  262. this.tabList.push(el)
  263. })
  264. }
  265. })
  266. }
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="scss" scoped>
  272. .search_box {
  273. padding: 10rpx 20rpx;
  274. display: flex;
  275. background-color: #f2f2f2;
  276. /deep/ .u-input {
  277. background: #fff;
  278. }
  279. /deep/ .u-botton {
  280. margin-left: 20rpx;
  281. }
  282. }
  283. .checkbox_flex {
  284. display: flex;
  285. width: 100%;
  286. padding: 10rpx;
  287. align-items: center;
  288. margin-bottom: 16rpx;
  289. .u-checkbox {
  290. width: 32rpx;
  291. height: 32rpx;
  292. }
  293. /deep/ .u-checkbox__icon-wrap--square {
  294. width: 100% !important;
  295. height: 100% !important;
  296. }
  297. .content {
  298. width: 100%;
  299. }
  300. }
  301. .tabList {
  302. width: 100%;
  303. padding: 0 20rpx;
  304. display: flex;
  305. justify-content: space-between;
  306. height: 82rpx;
  307. line-height: 82rpx;
  308. background-color: #ffffff;
  309. border-bottom: 1px solid #f2f2f2;
  310. z-index: 99;
  311. box-sizing: border-box;
  312. .left {
  313. display: flex;
  314. justify-content: space-between;
  315. width: 80%;
  316. .tab-item {
  317. width: 30%;
  318. text-align: center;
  319. font-size: 32rpx;
  320. color: $uni-text-color-grey;
  321. }
  322. .tab-item.active {
  323. color: $j-primary-border-green;
  324. border-bottom: 1px solid $j-primary-border-green;
  325. }
  326. }
  327. .right {
  328. flex: 1;
  329. text-align: right;
  330. }
  331. }
  332. .fixed {
  333. position: fixed;
  334. left: 0;
  335. width: 100%;
  336. }
  337. .no_data {
  338. position: fixed;
  339. top: 50%;
  340. left: 50%;
  341. transform: translate(-50%, -50%);
  342. color: #999;
  343. font-size: 28rpx;
  344. }
  345. .mt100 {
  346. margin-top: 200rpx;
  347. }
  348. /deep/ .u-picker__view__column__item {
  349. height: 88rpx !important;
  350. line-height: 88rpx !important;
  351. }
  352. /deep/ .uni-picker-view-indicator {
  353. height: 88rpx !important;
  354. line-height: 88rpx !important;
  355. }
  356. </style>