checkbox.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <view class="container">
  3. <view class="d-table">
  4. <!-- type="selection" @selection-change="selectionChange" -->
  5. <uni-table border stripe emptyText="暂无更多数据">
  6. <!-- 表头行 -->
  7. <uni-tr>
  8. <uni-th align="center">
  9. <checkbox-group @change="handlerChecked">
  10. <checkbox :checked="isAllChecked" value="1" />
  11. </checkbox-group>
  12. </uni-th>
  13. <uni-th align="center">序号</uni-th>
  14. <uni-th align="center">序列号</uni-th>
  15. <uni-th align="center">刻码</uni-th>
  16. <uni-th align="center" v-if="itemData.currentTaskDiagram.type == 4">发货码</uni-th>
  17. <uni-th align="center">投料数量</uni-th>
  18. <uni-th align="center">是否合格</uni-th>
  19. </uni-tr>
  20. <!-- 表格数据行 -->
  21. <uni-tr v-for="(item, index) in listArr" :key="index">
  22. <uni-td>
  23. <checkbox-group @change="handlerCheckedTow($event, index, item)">
  24. <checkbox :checked="item.selected" value="1" />
  25. </checkbox-group>
  26. </uni-td>
  27. <uni-td>{{ index + 1 }}</uni-td>
  28. <uni-td>
  29. {{ item.extInfo && item.extInfo.productSequence }}
  30. </uni-td>
  31. <uni-td>
  32. <input class="uni-input" v-model="item.extInfo.engrave"
  33. :disabled="!itemData.currentTaskDiagram.isFirstTask" @input="blurNum(item.extInfo.engrave)"
  34. type="digit"></input>
  35. </uni-td>
  36. <uni-td v-if="itemData.currentTaskDiagram.type == 4">
  37. <input class="uni-input" v-model="item.sendCode" type="digit"></input>
  38. </uni-td>
  39. <uni-td>
  40. {{ item.feedQuantity }}
  41. </uni-td>
  42. <uni-td>
  43. <zxz-uni-data-select :localdata="areaList" v-model="item.extInfo.isQualified" dataValue='value'
  44. format='{name}' dataKey="name" filterable :clear='false'
  45. v-if="!itemData.currentTaskDiagram.isFirstTask"
  46. @chaneg="handlerChange(item, index)"></zxz-uni-data-select>
  47. <text v-else>{{ item.extInfo.isQualified == 1 ? '合格' : '不合格' }}</text>
  48. </uni-td>
  49. </uni-tr>
  50. </uni-table>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. export default {
  56. props: {
  57. tableData: {
  58. type: Array,
  59. default: () => []
  60. },
  61. itemData: {
  62. type: Object,
  63. default: () => { }
  64. },
  65. },
  66. data() {
  67. return {
  68. pickerIndex: 0,
  69. isAllChecked: true,
  70. areaList: [
  71. {
  72. name: '合格',
  73. value: 1,
  74. },
  75. {
  76. name: '不合格',
  77. value: 2,
  78. },
  79. ],
  80. listArr: [],
  81. selectedIndexs: []
  82. };
  83. },
  84. watch:{
  85. tableData:{
  86. handler(v){
  87. this.listArr =v;
  88. },
  89. immediate:true,
  90. deep:true
  91. }
  92. },
  93. methods: {
  94. handlerCheckedTow(e, index, item) {
  95. console.log(item);
  96. if (e.detail.value.length) {
  97. // this.$set(this.tableData[index], 'selected', true);
  98. item.selected = true;
  99. } else {
  100. // this.$set(this.tableData[index], 'selected', false);
  101. item.selected = false;
  102. }
  103. this.listArr[index] =item;
  104. // this.$emit('tableDataFn', this.tableData);
  105. console.log(this.tableData);
  106. this.$nextTick(() => {
  107. let a = this.listArr.filter(v => v.selected);
  108. if (a.length && a.length == this.listArr.length) {
  109. this.isAllChecked = true;
  110. } else {
  111. this.isAllChecked = false;
  112. }
  113. })
  114. },
  115. //全选
  116. handlerChecked(e) {
  117. console.log(this.listArr);
  118. if (e.detail.value.length) {
  119. // 全选
  120. this.listArr.map(item => {
  121. item.selected = true;
  122. })
  123. } else {
  124. // 未选中
  125. this.listArr.map(item => {
  126. item.selected = false;
  127. })
  128. }
  129. this.listArr = [];
  130. this.$set(this, 'listArr', this.listArr);
  131. this.listArr = this.tableData;
  132. this.$emit('tableDataFn', this.tableData);
  133. },
  134. blurNum(workReportInfo) {
  135. this.$emit('tableDataFn', this.tableData);
  136. },
  137. handlerChange(item, index) {
  138. // this.$emit('tableDataFn', this.tableData);
  139. console.log(item, index);
  140. },
  141. selectionChange(e) {
  142. this.selectedIndexs = e.detail.index;
  143. },
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. ::v-deep .uni-select--mask{
  149. position: relative !important;
  150. }
  151. .container {
  152. padding: 10rpx;
  153. overflow: auto;
  154. checkbox {
  155. transform: scale(0.8);
  156. }
  157. }
  158. .uni-input {
  159. width: 150rpx;
  160. border: 1px solid #F0F8F2;
  161. background: #F0F8F2;
  162. color: #157A2C;
  163. }
  164. /deep/.uni-table {
  165. min-width: 100vw !important;
  166. .uni-table-td,
  167. .uni-table-th {
  168. padding: 20rpx 10rpx !important;
  169. text-align: center !important;
  170. font-weight: normal !important;
  171. font-size: 26rpx !important;
  172. }
  173. .uni-table-text {
  174. font-size: 26rpx !important;
  175. }
  176. }
  177. </style>