editActiveEndTime.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <a-modal
  3. centered
  4. class="editActiveEndTime-basicInfo-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="时间变更"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="500">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <div style="text-align: center;margin-bottom: 20px;font-weight: bold;">确定要变更{{ form.name }}的促销时间吗?</div>
  13. <a-form-model
  14. id="editActiveEndTime-basicInfo-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol" >
  20. <a-form-model-item label="原结束日期" prop="time">
  21. <span>{{ form.timeEnd }}</span>
  22. </a-form-model-item>
  23. <a-form-model-item label="变更后结束日期" prop="newTimeEnd">
  24. <a-date-picker style="width:90%" v-model="form.newTimeEnd" @change="onChange" :format="dateFormat" :disabled-date="disabledDate"/>
  25. </a-form-model-item>
  26. </a-form-model>
  27. <div class="btn-cont">
  28. <a-button id="editActiveEndTime-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  29. <a-button style="margin-left: 15px;" type="primary" id="editActiveEndTime-modal-save" @click="handleSave">确定</a-button>
  30. </div>
  31. </a-spin>
  32. </a-modal>
  33. </template>
  34. <script>
  35. import { commonMixin } from '@/utils/mixin'
  36. import moment from 'moment'
  37. import { promotionDateModify } from '@/api/promotion'
  38. export default {
  39. name: 'EditActiveEndTimeModal',
  40. mixins: [commonMixin],
  41. props: {
  42. openModal: { // 弹框显示状态
  43. type: Boolean,
  44. default: false
  45. } },
  46. data () {
  47. return {
  48. isShow: this.openModal, // 是否打开弹框
  49. spinning: false,
  50. formItemLayout: {
  51. labelCol: { span: 6 },
  52. wrapperCol: { span: 16 }
  53. },
  54. form: {
  55. name: '',
  56. timeStart: '',
  57. timeEnd: '',
  58. newTimeEnd: undefined
  59. },
  60. dateFormat: 'YYYY-MM-DD',
  61. rules: {
  62. newTimeEnd: [
  63. { required: true, message: '请选择变更的结束时间', trigger: 'change' }
  64. ]
  65. }
  66. }
  67. },
  68. methods: {
  69. onChange (date, dateString) {
  70. if (date) {
  71. this.form.newTimeEnd = dateString + ' 23:59:59'
  72. } else {
  73. this.form.newTimeEnd = undefined
  74. }
  75. },
  76. // 保存
  77. handleSave () {
  78. const _this = this
  79. this.$refs.ruleForm.validate(valid => {
  80. if (valid) {
  81. promotionDateModify({ promotionSn: _this.form.sn, promotionDateStart: _this.form.timeStart, promotionDateEnd: _this.form.newTimeEnd }).then(res => {
  82. if (res.status == 200) {
  83. _this.$message.success(res.message)
  84. setTimeout(() => {
  85. _this.isShow = false
  86. _this.$emit('ok', res.data)
  87. _this.spinning = false
  88. }, 1000)
  89. } else {
  90. _this.spinning = false
  91. }
  92. })
  93. } else {
  94. return false
  95. }
  96. })
  97. },
  98. // 获取显示内容
  99. setData (obj) {
  100. this.form = { ...this.form, ...obj }
  101. },
  102. // 不可选日期
  103. disabledDate (date, dateStrings) {
  104. return date && date.valueOf('day') < moment().subtract(1, 'day') // 今天以后,包含今天
  105. }
  106. },
  107. watch: {
  108. // 父页面传过来的弹框状态
  109. openModal (newValue, oldValue) {
  110. this.isShow = newValue
  111. },
  112. // 重定义的弹框状态
  113. isShow (newValue, oldValue) {
  114. if (!newValue) {
  115. this.$emit('close')
  116. this.form = {
  117. name: '',
  118. timeStart: '',
  119. timeEnd: '',
  120. newTimeEnd: undefined
  121. }
  122. this.$refs.ruleForm.resetFields()
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="less" scoped>
  129. .editActiveEndTime-basicInfo-modal{
  130. .ant-modal-body {
  131. padding: 40px 40px 24px;
  132. }
  133. .btn-cont {
  134. text-align: center;
  135. margin: 35px 0 10px;
  136. }
  137. }
  138. </style>