edit.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="客服">
  16. <el-cascader v-model="customerId" :options="options" :props="{
  17. value:'id',
  18. label:'name',
  19. children:'children'
  20. }"></el-cascader>
  21. </el-form-item>
  22. <el-form-item label="商品介绍" class="hui-textarea">
  23. <custom-data ref="customData" :list="customList" :option="option"></custom-data>
  24. </el-form-item>
  25. <el-form-item label="商品配图" class="hui-textarea">
  26. <upload ref="rotatingImages" :list="rotatingImages" type="insert" :maxLen="15"></upload>
  27. </el-form-item>
  28. <el-form-item label="商品详情配图" class="hui-textarea">
  29. <upload ref="detailedImage" :list="detailedImage" type="insert" :maxLen="15"></upload>
  30. </el-form-item>
  31. <el-form-item label="合同样本" class="hui-textarea">
  32. <upload ref="contract" :list="contract" type="insert" accept=".pdf" text="上传合同" :maxLen="1">
  33. </upload>
  34. </el-form-item>
  35. </el-form>
  36. </div>
  37. <div class="hui-dialog-submit">
  38. <el-button size="small" @click="$emit('callback')">取 消</el-button>
  39. <el-button size="small" type="primary" @click="submit" :loading="loading">保 存</el-button>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import {
  45. insertServe,
  46. updateServe,
  47. getServeById
  48. } from '@/api/serve'
  49. import {
  50. getPartList
  51. } from '@/api/organization'
  52. import {
  53. findParentIds
  54. } from '@/uitls'
  55. const upload = () => import('@/components/common/upload');
  56. const customData = () => import('@/components/common/customData');
  57. export default {
  58. props: ['isUpdate', 'detailId', 'productLevelId'],
  59. data() {
  60. return {
  61. form: {
  62. name: '',
  63. subtitle: '',
  64. type: 1,
  65. price: ''
  66. },
  67. loading: false,
  68. rotatingImages: [],
  69. detailedImage: [],
  70. customList: [],
  71. contract: [],
  72. option: [{
  73. id: 1,
  74. label: '介绍标题',
  75. width: '200px',
  76. value: 'title',
  77. type: 'text'
  78. }, {
  79. id: 2,
  80. label: '介绍内容',
  81. value: 'content',
  82. type: 'text'
  83. }],
  84. customerId: [],
  85. options: []
  86. }
  87. },
  88. mounted() {
  89. getPartList(this.$store.getters.organization.id, this.$store.getters.project.id).then(res => {
  90. if (res.state) {
  91. this.options = res.data;
  92. this.returnChildren(this.options);
  93. if (this.form.customerId && this.options.length > 0) this.customerId = findParentIds(this
  94. .options, -this.form.customerId);
  95. }
  96. })
  97. if (this.isUpdate) {
  98. getServeById(this.detailId).then(res => {
  99. if (res.state) {
  100. this.form = res.data;
  101. if (this.form.rotatingImages) this.rotatingImages = JSON.parse(this.form.rotatingImages);
  102. if (this.form.detailedImage) this.detailedImage = JSON.parse(this.form.detailedImage);
  103. if (this.form.contract) this.contract = JSON.parse(this.form.contract);
  104. if (this.form.intro) this.customList = JSON.parse(this.form.intro);
  105. if (this.form.customerId && this.options.length > 0) this.customerId = findParentIds(this
  106. .options, -this.form.customerId);
  107. }
  108. })
  109. } else {
  110. this.form['productLevelId'] = this.productLevelId;
  111. this.form['organizationId'] = this.$store.getters.organization.id;
  112. }
  113. },
  114. components: {
  115. upload,
  116. customData
  117. },
  118. methods: {
  119. handleInput(val) {
  120. let dat = ("" + val)
  121. .replace(/[^\d^\.]+/g, "")
  122. .replace(/^0+(\d)/, "$1")
  123. .replace(/^\./, "0.")
  124. .match(/^\d*(\.?\d{0,2})/g)[0] || "";
  125. this.form.price = dat;
  126. },
  127. submit() {
  128. this.loading = true;
  129. let postData = JSON.parse(JSON.stringify(this.form));
  130. postData['rotatingImages'] = JSON.stringify(this.$refs.rotatingImages.fileList);
  131. postData['detailedImage'] = JSON.stringify(this.$refs.detailedImage.fileList);
  132. postData['contract'] = JSON.stringify(this.$refs.contract.fileList);
  133. postData['intro'] = JSON.stringify(this.$refs.customData.listData);
  134. if (this.customerId.length > 0) postData['customerId'] = -this.customerId[this.customerId.length - 1];
  135. if (this.isUpdate) {
  136. updateServe(postData).then(this.successFunc)
  137. } else {
  138. insertServe(postData).then(this.successFunc)
  139. }
  140. },
  141. successFunc(res) {
  142. this.loading = false;
  143. if (res.state) {
  144. this.$message.success('操作成功');
  145. this.$emit('callback', 'init');
  146. }
  147. },
  148. returnChildren(data) {
  149. data.forEach(item => {
  150. if (item.users) {
  151. let obj = item.users.map(res => {
  152. return {
  153. id: -res.id,
  154. name: res.name
  155. };
  156. })
  157. item.children = item.children.concat(obj);
  158. }
  159. if (item.children && item.children.length === 0) item.children = null;
  160. if (item.children && item.children.length > 0) this.returnChildren(item.children);
  161. });
  162. },
  163. }
  164. }
  165. </script>
  166. <style lang="scss"></style>