edit.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?php
  2. ?>
  3. <div id="application" v-cloak>
  4. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;" style="overflow-y: auto;">
  5. <div slot="header">
  6. <el-breadcrumb separator="/">
  7. <el-breadcrumb-item>
  8. <span @click="$navigate({r: 'mall/goods/description-template'})" style="color: #000;cursor: pointer">商品说明</span>
  9. </el-breadcrumb-item>
  10. <el-breadcrumb-item>模板编辑</el-breadcrumb-item>
  11. </el-breadcrumb>
  12. </div>
  13. <div class="table-body">
  14. <el-form size="small" ref="form" label-width="120px" :model="form" :rules="rules">
  15. <el-form-item label="前端字段显示" prop="frontend_name">
  16. <el-input style="width: 200px;" maxlength="4" show-word-limit v-model="form.frontend_name"></el-input>
  17. </el-form-item>
  18. <el-form-item label="模板名称" prop="name">
  19. <el-input style="width: 200px;" maxlength="8" show-word-limit v-model="form.name"></el-input>
  20. </el-form-item>
  21. <el-form-item label="字段内容展示" prop="fields">
  22. <div style="display: flex;">
  23. <div style="width: 200px;">
  24. <div style="position: relative; margin-bottom: 10px;" v-for="(item, index) in form.fields" :key="index">
  25. <el-input
  26. maxlength="6"
  27. show-word-limit
  28. v-model="form.fields[index]"
  29. ></el-input>
  30. <i class="el-icon-close"
  31. style="position: absolute; top: 0; right: 0; cursor: pointer; padding: 1px; z-index: 1;"
  32. @click="removeField(index)"></i>
  33. </div>
  34. </div>
  35. <div style="margin-left: 10px;">
  36. <el-button type="text" @click="form.fields.push('')">添加</el-button>
  37. </div>
  38. </div>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button size="small" type="primary" style="padding: 9px 15px !important;" @click="submit" :loading="btnLoad">
  42. 保存
  43. </el-button>
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. </el-card>
  48. </div>
  49. <script>
  50. const application = new Vue({
  51. el: '#application',
  52. data: function () {
  53. const validateFields = (rule, value, callback) => {
  54. for (const field of value) {
  55. if (field.toString().trim() === '') {
  56. callback(new Error('请填写字段'))
  57. return
  58. }
  59. }
  60. callback()
  61. }
  62. return {
  63. api: 'mall/goods/edit-description-template',
  64. crumbs: [
  65. {
  66. title: '基础设置',
  67. }
  68. ],
  69. btnLoad: false,
  70. form: {
  71. id: getQuery('id'),
  72. name: '',
  73. frontend_name: '',
  74. fields: [''],
  75. },
  76. rules: {
  77. frontend_name: [
  78. {required: true, message: '请填写前端字段显示', trigger: 'blur'},
  79. {min: 1, max: 4, message: '长度在 1 到 4 个字符', trigger: 'blur'}
  80. ],
  81. name: [
  82. {required: true, message: '请填写模板名称', trigger: 'blur'},
  83. {min: 1, max: 8, message: '长度在 1 到 8 个字符', trigger: 'blur'}
  84. ],
  85. fields: [
  86. {required: true, message: '请填写字段', trigger: 'blur'},
  87. { validator: validateFields, trigger: 'blur' }
  88. ]
  89. }
  90. }
  91. },
  92. mounted() {
  93. if (this.form.id > 0) {
  94. this.detail()
  95. }
  96. },
  97. computed: {},
  98. methods: {
  99. submit() {
  100. this.$refs['form'].validate((valid) => {
  101. if (!valid) {
  102. return
  103. }
  104. this.btnLoad = true
  105. request({
  106. params: {
  107. r: 'mall/goods/edit-description-template',
  108. },
  109. method: 'POST',
  110. data: this.form
  111. }).then(e => {
  112. if (e.data.code === 0) {
  113. this.$message.success('添加成功')
  114. this.$navigate({r: 'mall/goods/description-template'})
  115. } else {
  116. this.$message.error(e.data.msg);
  117. }
  118. }).finally(() => {
  119. this.btnLoad = false
  120. })
  121. })
  122. },
  123. detail() {
  124. request({
  125. params: {
  126. r: 'mall/goods/edit-description-template',
  127. id: this.form.id,
  128. },
  129. }).then(e => {
  130. this.form = Object.assign(this.form, e.data.data)
  131. this.form.name += ''
  132. this.form.frontend_name += ''
  133. })
  134. },
  135. removeField(index) {
  136. if (this.form.fields.length > 1) {
  137. this.form.fields.splice(index, 1);
  138. } else {
  139. this.$message.warning('至少保留一个字段');
  140. }
  141. }
  142. }
  143. })
  144. </script>