index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :visible.sync="visible"
  5. :before-close="handleClose"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. width="35%"
  10. >
  11. <el-form
  12. :model="form"
  13. ref="tableForm"
  14. class="tableForm"
  15. :rules="tableFormRules"
  16. >
  17. <el-button
  18. type="primary"
  19. size="small"
  20. style="margin-bottom: 10px"
  21. @click="handleAdd()"
  22. v-if="!view"
  23. >新增</el-button
  24. >
  25. <el-table
  26. ref="multipleTable"
  27. :data="form.arrivalBatch"
  28. tooltip-effect="dark"
  29. style="width: 100%"
  30. stripe
  31. :header-cell-style="{ background: '#EEEEEE', border: 'none' }"
  32. >
  33. <el-table-column label="数量" prop="arriveCount">
  34. <template slot-scope="{ row, $index }">
  35. <el-form-item
  36. :prop="'arrivalBatch.' + $index + '.arriveCount'"
  37. :rules="tableFormRules.arriveCount"
  38. >
  39. <el-input
  40. placeholder="请输入"
  41. clearable
  42. v-model="row.arriveCount"
  43. :disabled="view"
  44. ></el-input>
  45. </el-form-item>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="到货时间">
  49. <template slot-scope="{ row, $index }">
  50. <el-form-item
  51. :prop="'arrivalBatch.' + $index + '.arriveDate'"
  52. :rules="tableFormRules.arriveDate"
  53. >
  54. <el-date-picker
  55. clearable
  56. v-model="row.arriveDate"
  57. type="date"
  58. value-format="yyyy-MM-dd"
  59. placeholder="请选择日期"
  60. :disabled="view"
  61. >
  62. </el-date-picker>
  63. </el-form-item> </template
  64. ></el-table-column>
  65. <el-table-column label="操作" prop="action" width="80" v-if="!view">
  66. <template slot-scope="{ $index }">
  67. <el-link
  68. type="primary"
  69. :underline="false"
  70. @click="handleDel($index)"
  71. >删除</el-link
  72. >
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </el-form>
  77. <div class="btns">
  78. <el-button type="primary" size="small" @click="handleOk">确认</el-button>
  79. <el-button size="small" @click="handleClose">取消</el-button>
  80. </div>
  81. </el-dialog>
  82. </template>
  83. <script>
  84. import { copyObj } from '@/utils/util';
  85. export default {
  86. components: {},
  87. props:{
  88. view:{
  89. default:false
  90. }
  91. },
  92. data() {
  93. return {
  94. visible: false,
  95. title: '设置分批时间',
  96. current: null,
  97. form: {
  98. arrivalBatch: [
  99. {
  100. arriveDate: null,
  101. arriveCount: null
  102. }
  103. ]
  104. },
  105. tableFormRules: {
  106. arriveCount: {
  107. required: true,
  108. message: '请输入数量',
  109. trigger: 'blur'
  110. },
  111. arriveDate: {
  112. required: true,
  113. message: '请选择日期',
  114. trigger: 'change'
  115. }
  116. }
  117. };
  118. },
  119. watch: {},
  120. methods: {
  121. open(row) {
  122. console.log(row, 'row');
  123. this.form.arrivalBatch = row.arrivalBatch&&copyObj(row.arrivalBatch)||[];
  124. this.current = row;
  125. this.visible = true;
  126. },
  127. handleAdd() {
  128. this.form.arrivalBatch.push({
  129. arriveDate: null,
  130. arriveCount: null
  131. });
  132. },
  133. handleDel(index) {
  134. this.form.arrivalBatch.splice(index, 1);
  135. },
  136. handleOk() {
  137. this.$refs.tableForm.validate((valid) => {
  138. if (valid) {
  139. this.$emit('chooseTime', this.current,copyObj(this.form.arrivalBatch) );
  140. this.handleClose();
  141. }
  142. });
  143. },
  144. handleClose() {
  145. this.$refs.tableForm && this.$refs.tableForm.resetFields();
  146. this.visible = false;
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. .btns {
  153. margin-top: 20px;
  154. text-align: center;
  155. }
  156. .el-form-item {
  157. margin-bottom: 20px !important;
  158. }
  159. </style>