timeDialog.vue 4.1 KB

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