SparePart.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view class="">
  3. <template>
  4. <view class="input-search">
  5. <input
  6. type="text"
  7. v-model="searchValue"
  8. placeholder="请搜索"
  9. @confirm="handleConfirm"
  10. />
  11. </view>
  12. <view class="input-search__placeholder"></view>
  13. </template>
  14. <checkbox-group style="padding-bottom: 100rpx" @change="checkboxChange">
  15. <label class="radio-list" v-for="(item, index) in list" :key="index">
  16. <checkbox class="radio" :value="item.code" :checked="item.checked" />
  17. <view class="content">
  18. <view class="">
  19. <text>{{ item.code }}/</text>
  20. <text class="font-grey">{{ item.name }}</text>
  21. </view>
  22. <view class="">
  23. <text>{{ item.inventoryLibrary }}/</text>
  24. <text class="font-grey">{{ item.model }}</text>
  25. </view>
  26. </view>
  27. <view @click.stop>
  28. <uni-number-box
  29. @change="e => checkItem(e, index)"
  30. :min="0"
  31. :max="item.ableUse"
  32. v-model="item.num"
  33. >
  34. </uni-number-box>
  35. </view>
  36. </label>
  37. </checkbox-group>
  38. <view class="footer">
  39. <view class="bottom">
  40. <checkbox v-if="!seletedAll" :checked="seletedAll" @tap="_seletedAll"
  41. >全选</checkbox
  42. >
  43. <checkbox
  44. class="select-all"
  45. v-else
  46. :checked="seletedAll"
  47. @tap="_seletedAll"
  48. >取消全选
  49. </checkbox>
  50. </view>
  51. <text class="footer-span-btn" @click="submit"
  52. >申领({{ checkListLen }})</text
  53. >
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import { get, postJ } from '@/utils/api.js'
  59. export default {
  60. name: 'SparePart',
  61. data () {
  62. return {
  63. seletedAll: false,
  64. searchValue: ''
  65. //list:[]
  66. }
  67. },
  68. props: {
  69. list: {
  70. type: Array,
  71. default: () => []
  72. }
  73. },
  74. computed: {
  75. checkListLen () {
  76. const list = this.list.filter(el => {
  77. if (el.checked && !el.disabled) {
  78. return el
  79. }
  80. })
  81. return list.length
  82. }
  83. },
  84. methods: {
  85. handleConfirm () {
  86. this.$emit('search', this.searchValue)
  87. },
  88. checkItem (e, index) {
  89. this.$set(this.list[index], 'checked', true)
  90. },
  91. _seletedAll () {
  92. if (!this.seletedAll) {
  93. this.seletedAll = true
  94. this.list.map(item => {
  95. this.$set(item, 'checked', true)
  96. })
  97. } else {
  98. this.seletedAll = false
  99. //this.checkListLen = 0;
  100. this.list.map(item => {
  101. this.$set(item, 'checked', false)
  102. })
  103. }
  104. },
  105. checkboxChange (e) {
  106. let checkList = e.detail.value
  107. //判断是否全选
  108. if (checkList.length === this.list.length) {
  109. this.list.forEach(el => {
  110. this.$set(el, 'checked', true)
  111. })
  112. this.seletedAll = true
  113. } else {
  114. let items = this.list
  115. let chekedItem = []
  116. //选中的长度+ 不可选中的长度
  117. let cheAndDisLen = 0
  118. //有选中的值
  119. if (checkList.length) {
  120. //遍历列表所有的数据
  121. for (let i = 0; i < items.length; i++) {
  122. //判断该数据是否选中
  123. if (items[i].disabled) {
  124. cheAndDisLen++
  125. } else {
  126. const isPick = checkList.some(pick => {
  127. return pick == items[i].batchNo
  128. })
  129. this.$set(this.list[i], 'checked', isPick)
  130. if (isPick) {
  131. cheAndDisLen++
  132. }
  133. }
  134. }
  135. } else {
  136. //全不选
  137. this.list.forEach(el => {
  138. this.$set(el, 'checked', false)
  139. })
  140. }
  141. //改变全选状态
  142. //选中+不可选中长度等于数据长度为全选
  143. if (cheAndDisLen == this.list.length) {
  144. this.seletedAll = true
  145. } else {
  146. this.seletedAll = false
  147. }
  148. }
  149. },
  150. submit () {
  151. this.$emit('submitList', this.list)
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .input-search {
  158. position: fixed;
  159. width: 100%;
  160. padding: 10rpx 20rpx;
  161. height: 80rpx;
  162. z-index: 99;
  163. background-color: #ffffff;
  164. box-sizing: border-box;
  165. input {
  166. height: 80rpx;
  167. line-height: 80rpx;
  168. text-align: center;
  169. font-size: $uni-font-size-base;
  170. background-color: $page-bg;
  171. border-radius: 30rpx;
  172. }
  173. &__placeholder {
  174. padding-bottom: 90rpx;
  175. }
  176. }
  177. .radio-list {
  178. display: flex;
  179. padding: 20rpx;
  180. align-items: center;
  181. justify-content: space-between;
  182. color: $uni-text-color;
  183. border-bottom: 2rpx solid #d8d8d8;
  184. font-size: $uni-font-size-base;
  185. line-height: 1.8;
  186. .radio {
  187. margin-right: 10rpx;
  188. }
  189. .content {
  190. flex-grow: 1;
  191. font-size: 28rpx;
  192. }
  193. }
  194. .footer {
  195. position: fixed;
  196. display: flex;
  197. justify-content: space-between;
  198. align-items: center;
  199. bottom: 0;
  200. width: 100%;
  201. height: 90rpx;
  202. text-align: center;
  203. border-top: 1rpx solid #eeecec;
  204. background-color: #ffffff;
  205. .bottom {
  206. font-size: $uni-font-size-lg;
  207. margin-left: 20rpx;
  208. .select-all {
  209. color: $j-primary-green;
  210. }
  211. }
  212. .footer-span-btn {
  213. height: 30rpx;
  214. line-height: 30rpx;
  215. font-size: $uni-font-size-lg;
  216. color: #ffffff;
  217. margin-right: 20rpx;
  218. padding: 10rpx 20rpx;
  219. text-align: center;
  220. background-color: $j-primary-green;
  221. border-radius: 40rpx;
  222. }
  223. }
  224. </style>