com-edit-template.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <style>
  2. </style>
  3. <template id="com-edit-template">
  4. <div class="com-edit-template">
  5. <!-- 添加评价回复模板 -->
  6. <el-dialog title="添加模板" :visible.sync="dialogVisible" width="30%" @close="closeDialog" :close-on-click-modal="false">
  7. <el-form :model="ruleForm" ref="ruleForm" :rules="rules" size="small" label-width="80px">
  8. <el-form-item prop="title" label="模板名称">
  9. <el-input type="text" v-model="ruleForm.title"></el-input>
  10. </el-form-item>
  11. <el-form-item prop="content" label="模板内容">
  12. <el-input type="textarea" v-model="ruleForm.content" autocomplete="off"></el-input>
  13. </el-form-item>
  14. <el-form-item prop="type" label="模板类型">
  15. <el-radio v-model="ruleForm.type" :label="1">好评回复</el-radio>
  16. <el-radio v-model="ruleForm.type" :label="2">中评回复</el-radio>
  17. <el-radio v-model="ruleForm.type" :label="3">差评回复</el-radio>
  18. </el-form-item>
  19. <el-form-item style="text-align: right">
  20. <el-button size="small" @click="dialogVisible = false">取消</el-button>
  21. <el-button size="small" type="primary" :loading="submitLoading" @click="toSumbit('ruleForm')">确定
  22. </el-button>
  23. </el-form-item>
  24. </el-form>
  25. </el-dialog>
  26. </div>
  27. </template>
  28. <script>
  29. Vue.component('com-edit-template', {
  30. template: '#com-edit-template',
  31. props: {
  32. isShow: {
  33. type: Boolean,
  34. default: false,
  35. },
  36. template: {
  37. type: Object,
  38. default: null
  39. },
  40. url: {
  41. type: String,
  42. default: 'mall/order-comment-templates/edit'
  43. }
  44. },
  45. watch: {
  46. isShow: function (newVal) {
  47. if (newVal) {
  48. this.openDialog()
  49. }
  50. }
  51. },
  52. data() {
  53. return {
  54. dialogVisible: false,
  55. ruleForm: {
  56. id: null,
  57. title: '',
  58. content: '',
  59. type: 1,
  60. },
  61. submitLoading: false,
  62. rules: {
  63. title: [
  64. {required: true, message: '请输入模板名称', trigger: 'change'},
  65. ],
  66. content: [
  67. {required: true, message: '请输入模板内容', trigger: 'change'},
  68. ],
  69. type: [
  70. {required: true, message: '请选择模板类型', trigger: 'change'},
  71. ],
  72. },
  73. }
  74. },
  75. methods: {
  76. // 打开备注
  77. openDialog(e) {
  78. if (this.template) {
  79. this.ruleForm.id = this.template.id;
  80. this.ruleForm.title = this.template.title;
  81. this.ruleForm.content = this.template.content;
  82. this.ruleForm.type = this.template.type;
  83. } else {
  84. this.ruleForm.id = null;
  85. this.ruleForm.title = '';
  86. this.ruleForm.content = '';
  87. this.ruleForm.type = 1;
  88. }
  89. this.dialogVisible = true;
  90. },
  91. closeDialog() {
  92. this.$emit('close')
  93. },
  94. toSumbit(formName) {
  95. this.$refs[formName].validate((valid) => {
  96. if (valid) {
  97. this.submitLoading = true;
  98. request({
  99. params: {
  100. r: this.url
  101. },
  102. data: {
  103. id: this.ruleForm.id,
  104. title: this.ruleForm.title,
  105. content:this.ruleForm.content,
  106. type:this.ruleForm.type,
  107. },
  108. method: 'post'
  109. }).then(e => {
  110. this.submitLoading = false;
  111. if (e.data.code === 0) {
  112. this.dialogVisible = false;
  113. this.$message.success(e.data.msg);
  114. this.$emit('submit')
  115. } else {
  116. this.$message.error(e.data.msg);
  117. }
  118. }).catch(e => {
  119. });
  120. } else {
  121. console.log('error submit!!');
  122. return false;
  123. }
  124. });
  125. }
  126. }
  127. })
  128. </script>