timePopup.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <uni-popup ref="popup" :showClose="true" background-color="#fff" @change="change">
  3. <scroll-view class="scroll-content" scroll-y style="height: 80vh;">
  4. <view class="popup-title">
  5. <text>待分配数量:{{ count }}</text>
  6. <u-button class="popup-title-btn" type="primary" @click="handleAddDate" text="新增" ></u-button>
  7. </view>
  8. <uni-table ref="table" border stripe emptyText="暂无更多数据">
  9. <uni-tr>
  10. <uni-th width="100" align="center">数量</uni-th>
  11. <uni-th width="150" align="center">到货时间</uni-th>
  12. <uni-th width="80" align="center">操作</uni-th>
  13. </uni-tr>
  14. <uni-tr v-for="(item, index) in tableData" :key="index">
  15. <uni-td><uni-number-box v-model="item.arriveCount" :min="0" :max="getCountMax(item)" @change="changeCountValue(index)" /></uni-td>
  16. <uni-td>
  17. <uni-datetime-picker type="date" v-model="item.arriveDate"></uni-datetime-picker>
  18. </uni-td>
  19. <uni-td>
  20. <button class="uni-button" size="mini" type="warn" @click="handleDelDate(index)">删除</button>
  21. </uni-td>
  22. </uni-tr>
  23. </uni-table>
  24. <view class="footerButton">
  25. <u-button type="default" @click="handleClose" text="关闭"></u-button>
  26. <u-button type="primary" @click="handleConfirm" text="确认"></u-button>
  27. </view>
  28. </scroll-view>
  29. </uni-popup>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. count: 0, //待分配数量
  36. tableData: [], //表格数据
  37. }
  38. },
  39. computed: {
  40. getCountMax() {
  41. return (row) => {
  42. let maxCount = this.current.totalCount * 1 || 0;
  43. let usedCount = this.tableData.reduce((n, item) => {
  44. n += item.arriveCount * 1;
  45. return n;
  46. }, 0);
  47. return maxCount - usedCount + row.arriveCount * 1;
  48. };
  49. }
  50. },
  51. methods: {
  52. open(current, index) {
  53. this.current = current;
  54. this.currentIndex = index;
  55. // this.count = this.current.totalCount * 1 || 0;
  56. this.changeCountValue();
  57. this.$refs.popup.open('bottom');
  58. if(current.arrivalBatch) {
  59. this.tableData = current.arrivalBatch
  60. } else {
  61. this.tableData = []
  62. }
  63. },
  64. change(e) {
  65. console.log('当前模式:' + e.type + ',状态:' + e.show);
  66. },
  67. // 新增
  68. handleAddDate() {
  69. this.tableData.push({
  70. arriveCount: null,
  71. arriveDate: null,
  72. })
  73. },
  74. handleDelDate(index) {
  75. this.count += this.tableData[index].arriveCount;
  76. this.tableData.splice(index, 1);
  77. },
  78. changeCountValue() {
  79. if (this.tableData.length) {
  80. let num = this.tableData.reduce((n, item) => {
  81. n += item.arriveCount * 1;
  82. return n;
  83. }, 0);
  84. this.count = this.current.totalCount * 1 - num || 0;
  85. } else {
  86. this.count = this.current.totalCount * 1 || 0;
  87. }
  88. },
  89. handleConfirm() {
  90. if (this.count != 0) {
  91. uni.showToast({ title: '分配数量有误,请检查!'})
  92. return
  93. }
  94. // 检查tableData数组中是否有空值
  95. for (let i = 0; i < this.tableData.length; i++) {
  96. const item = this.tableData[i];
  97. if (item.arriveCount === null || item.arriveCount === undefined || !item.arriveDate) {
  98. return uni.showToast({ title: `第${i + 1}行数据不完整,请检查数量和到货时间!`});
  99. }
  100. }
  101. this.$emit('confirm', this.tableData);
  102. },
  103. handleClose() {
  104. this.$refs.popup.close()
  105. },
  106. }
  107. }
  108. </script>
  109. <style scoped lang="scss">
  110. .footerButton {
  111. width: 100%;
  112. height: 84rpx;
  113. display: flex;
  114. position: fixed;
  115. bottom: 0;
  116. z-index: 10;
  117. background-color: #fff;
  118. /deep/.u-button {
  119. height: 100%;
  120. }
  121. >view {
  122. flex: 1;
  123. }
  124. }
  125. .scroll-content {
  126. padding: 20rpx;
  127. }
  128. .popup-title {
  129. display: flex;
  130. align-items: center;
  131. padding: 20rpx;
  132. }
  133. .popup-title-btn {
  134. width: 100rpx;
  135. margin-right: 20rpx;
  136. }
  137. </style>