authprivAdd.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!-- 经销商授权信息 编辑新增-->
  2. <template>
  3. <el-dialog :title="isAdd ? '新增' : '编辑'" :visible.sync="visible" :close-on-click-modal="false"
  4. :close-on-press-escape="false" :before-close="beforeClose" @close="$emit('close')">
  5. <el-form :model="formData" ref="authprivAdd" label-position="left" label-width="120px" v-loading="loading">
  6. <el-form-item v-for="column in formColumns" :label="column.title" :prop="column.key"
  7. :rules="{ required: true, message: `请输入${column.title}`, trigger: column.type == 'Input' ? 'blur' : 'change' }">
  8. <el-input v-if="column.type == 'Input'" :clearable="column.clearable" v-model="formData[column.key]"
  9. autocomplete="off"></el-input>
  10. <el-date-picker v-if="column.type == 'DateRange'" :clearable="column.clearable" v-model="formData[column.key]"
  11. format="yyyy-MM-dd " value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期"
  12. end-placeholder="结束日期"></el-date-picker>
  13. <el-date-picker v-if="column.type == 'Date'" :clearable="column.clearable" v-model="formData[column.key]"
  14. format="yyyy-MM-dd " value-format="yyyy-MM-dd" type="date" placeholder="选择日期"></el-date-picker>
  15. </el-form-item>
  16. </el-form>
  17. <div slot="footer" class="dialog-footer">
  18. <el-button @click="handleCancel">取 消</el-button>
  19. <el-button type="primary" @click="handleConfirm('authprivAdd')">确 定</el-button>
  20. </div>
  21. </el-dialog>
  22. </template>
  23. <script>
  24. import dealerApi from '@/api/marketing/dealer-authorization';
  25. import { FormColumns } from './column';
  26. import { initParams } from '../utils/init'
  27. const initFormColumns = () =>
  28. FormColumns.map((column) => {
  29. const clearable = column.clearable || true;
  30. return {
  31. ...column,
  32. clearable,
  33. };
  34. });
  35. export default {
  36. name: 'authprivAdd',
  37. data() {
  38. return {
  39. visible: false,
  40. isAdd: true,
  41. loading: false,
  42. formData: { ...initParams(initFormColumns()) },
  43. formColumns: initFormColumns(),
  44. }
  45. },
  46. methods: {
  47. // 控制弹窗展示
  48. setVisible(val) {
  49. this.visible = val;
  50. },
  51. setFormData(data) {
  52. if (data.id) {
  53. this.loading = true;
  54. this.isAdd = false;
  55. this.formData = {
  56. ...data,
  57. time: [data.startTime, data.endTime]
  58. };
  59. setTimeout(() => {
  60. this.loading = false;
  61. }, 250);
  62. return
  63. }
  64. this.isAdd = true;
  65. },
  66. // 重置表单数据
  67. handleResetData() {
  68. this.formData = {
  69. ...initParams(initFormColumns())
  70. }
  71. this.$refs['authprivAdd'].clearValidate();
  72. },
  73. // 取消
  74. handleCancel() {
  75. this.handleResetData();
  76. this.setVisible(false);
  77. },
  78. // 确定
  79. handleConfirm(formName) {
  80. this.$refs[formName].validate(async (valid) => {
  81. if (valid) {
  82. // 校验通过
  83. let isTime = this.formData.time && this.formData.time != '' && this.formData.time.length;
  84. const { name, id, } = this.$store.state.user;
  85. let params = {
  86. ...this.formData,
  87. startTime: isTime ? this.formData.time[0] : '',
  88. endTime: isTime ? this.formData.time[1] : '',
  89. updatePerson: name,
  90. updateTime: new Date().Format('yyyy-MM-dd HH:mm:ss'),
  91. ...(
  92. this.isAdd ? {
  93. status: '0',
  94. createPerson: name,
  95. createTime: new Date().Format('yyyy-MM-dd HH:mm:ss'),
  96. } : {}
  97. )
  98. }
  99. delete params['time']
  100. console.log(params, 'params--------');
  101. try {
  102. this.loading = true;
  103. let { code, msg } = await (this.isAdd ?
  104. dealerApi.insert(params) :
  105. dealerApi.update(params))
  106. if (code === 200) {
  107. this.handleCancel();
  108. }
  109. } catch (error) {
  110. console.log(error, 'error');
  111. } finally {
  112. this.loading = false;
  113. }
  114. } else {
  115. console.log('error submit!!');
  116. return false;
  117. }
  118. });
  119. },
  120. beforeClose(done) {
  121. this.handleResetData();
  122. done();
  123. },
  124. },
  125. created() {
  126. }
  127. }
  128. </script>
  129. <style lang="scss" scoped>
  130. .authpriv {
  131. width: calc(100% - 24px);
  132. height: 100%;
  133. margin: 10px
  134. }
  135. </style>