edit.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <div class="hui-flex hui-dialog">
  3. <div class="hui-flex-box hui-dialog-content">
  4. <el-form :model="form" label-position="top">
  5. <el-form-item label="主标题">
  6. <el-input type="text" v-model="form.name" placeholder="请输入主标题"></el-input>
  7. </el-form-item>
  8. <el-form-item label="副标题">
  9. <el-input type="text" v-model="form.subtitle" placeholder="请输入副标题"></el-input>
  10. </el-form-item>
  11. <el-form-item label="价格(元)">
  12. <el-input type="text" v-model="form.price" @input="handleInput($event)" placeholder="请输入价格">
  13. </el-input>
  14. </el-form-item>
  15. <el-form-item label="服务介绍" class="hui-textarea">
  16. <custom-data ref="customData" :list="customList" :option="option"></custom-data>
  17. </el-form-item>
  18. <el-form-item label="服务配图" class="hui-textarea">
  19. <upload ref="rotatingImages" :list="rotatingImages" type="insert" :maxLen="15"></upload>
  20. </el-form-item>
  21. <el-form-item label="详情配图" class="hui-textarea">
  22. <upload ref="detailedImage" :list="detailedImage" type="insert" :maxLen="15"></upload>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. <div class="hui-dialog-submit">
  27. <el-button size="small" @click="$emit('callback')">取 消</el-button>
  28. <el-button size="small" type="primary" @click="submit" :loading="loading">保 存</el-button>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. import {
  34. insertServe,
  35. updateServe,
  36. getServeById
  37. } from '@/api/serve'
  38. const upload = () => import('@/components/common/upload');
  39. import customData from '@/components/common/customData'
  40. export default {
  41. props: ['isUpdate', 'detailId', 'productLevelId'],
  42. data() {
  43. return {
  44. form: {
  45. name: '',
  46. subtitle: '',
  47. type: 1,
  48. price: ''
  49. },
  50. loading: false,
  51. rotatingImages: [],
  52. detailedImage: [],
  53. customList: [],
  54. option: [{
  55. id: 1,
  56. label: '介绍标题',
  57. width: '200px',
  58. value: 'title',
  59. type: 'text'
  60. }, {
  61. id: 2,
  62. label: '介绍内容',
  63. value: 'content',
  64. type: 'text'
  65. }]
  66. }
  67. },
  68. mounted() {
  69. if (this.isUpdate) {
  70. getServeById(this.detailId).then(res => {
  71. if (res.state) {
  72. this.form = res.data;
  73. if (this.form.rotatingImages) this.rotatingImages = JSON.parse(this.form.rotatingImages);
  74. if (this.form.detailedImage) this.detailedImage = JSON.parse(this.form.detailedImage);
  75. if (this.form.intro) this.customList = JSON.parse(this.form.intro);
  76. }
  77. })
  78. } else {
  79. this.form['productLevelId'] = this.productLevelId;
  80. this.form['organizationId'] = this.$store.getters.organization.id;
  81. }
  82. },
  83. components: {
  84. upload,
  85. customData
  86. },
  87. methods: {
  88. handleInput(val) {
  89. let dat = ("" + val)
  90. .replace(/[^\d^\.]+/g, "")
  91. .replace(/^0+(\d)/, "$1")
  92. .replace(/^\./, "0.")
  93. .match(/^\d*(\.?\d{0,2})/g)[0] || "";
  94. this.form.price = dat;
  95. },
  96. submit() {
  97. this.loading = true;
  98. let postData = JSON.parse(JSON.stringify(this.form));
  99. postData['rotatingImages'] = JSON.stringify(this.$refs.rotatingImages.fileList);
  100. postData['detailedImage'] = JSON.stringify(this.$refs.detailedImage.fileList);
  101. postData['intro'] = JSON.stringify(this.$refs.customData.listData);
  102. if (this.isUpdate) {
  103. updateServe(postData).then(this.successFunc)
  104. } else {
  105. insertServe(postData).then(this.successFunc)
  106. }
  107. },
  108. successFunc(res) {
  109. this.loading = false;
  110. if (res.state) {
  111. this.$message.success('操作成功');
  112. this.$emit('callback', 'init');
  113. }
  114. }
  115. }
  116. }
  117. </script>
  118. <style lang="scss"></style>