timePopup.vue 5.0 KB

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