detail.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="style">
  5. <el-col :span="24" class="top">
  6. <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
  7. </el-col>
  8. <el-col :span="24" class="main">
  9. <release :form="form" @onSubmitDraft="onSubmitDraft" @onSubmit="onSubmit"></release>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. </div>
  14. </template>
  15. <script>
  16. import NavBar from '@/layout/common/topInfo.vue';
  17. import release from '@/layout/myProduct/release.vue';
  18. import { mapState, createNamespacedHelpers } from 'vuex';
  19. const { mapActions: mapMarketproduct } = createNamespacedHelpers('marketproduct');
  20. export default {
  21. name: 'detail',
  22. props: {},
  23. components: {
  24. NavBar,
  25. release, //产品发布
  26. },
  27. data: () => ({
  28. // 头部标题
  29. title: '',
  30. // meta为true
  31. isleftarrow: '',
  32. // 返回
  33. navShow: true,
  34. // 发布产品
  35. form: {},
  36. }),
  37. created() {
  38. this.searchInfo();
  39. },
  40. computed: {
  41. ...mapState(['user']),
  42. id() {
  43. return this.$route.query.id;
  44. },
  45. },
  46. methods: {
  47. ...mapMarketproduct({ productFetch: 'fetch', productCreate: 'create', productUpdate: 'update' }),
  48. // 详情
  49. async searchInfo() {
  50. if (this.id) {
  51. let res = await this.productFetch(this.id);
  52. if (this.$checkRes(res)) {
  53. this.$set(this, `form`, res.data);
  54. }
  55. }
  56. },
  57. // 保存草稿
  58. async onSubmitDraft({ data }) {
  59. if (this.id) {
  60. let res = await this.productUpdate(data);
  61. if (this.$checkRes(res)) {
  62. this.$message({
  63. message: '草稿修改成功',
  64. type: 'success',
  65. });
  66. this.$router.push({ path: '/userCenter/myProduct/index' });
  67. } else {
  68. this.$message.error('草稿修改失败');
  69. }
  70. } else {
  71. data.status = '3';
  72. data.userid = this.user.uid;
  73. let res = await this.productCreate(data);
  74. if (this.$checkRes(res)) {
  75. this.$message({
  76. message: '草稿创建成功',
  77. type: 'success',
  78. });
  79. this.$router.push({ path: '/userCenter/myProduct/index' });
  80. } else {
  81. this.$message.error('草稿创建失败');
  82. }
  83. }
  84. },
  85. // 信息发布
  86. async onSubmit({ data }) {
  87. if (this.id) {
  88. data.status = '0';
  89. let res = await this.productUpdate(data);
  90. if (this.$checkRes(res)) {
  91. this.$message({
  92. message: '信息发布成功',
  93. type: 'success',
  94. });
  95. this.$router.push({ path: '/userCenter/myProduct/index' });
  96. } else {
  97. this.$message.error('信息发布失败');
  98. }
  99. } else {
  100. data.status = '0';
  101. data.userid = this.user.uid;
  102. let res = await this.productCreate(data);
  103. if (this.$checkRes(res)) {
  104. this.$message({
  105. message: '信息发布成功',
  106. type: 'success',
  107. });
  108. this.$router.push({ path: '/userCenter/myProduct/index' });
  109. } else {
  110. this.$message.error('信息发布失败');
  111. }
  112. }
  113. },
  114. },
  115. mounted() {
  116. this.title = this.$route.meta.title;
  117. this.isleftarrow = this.$route.meta.isleftarrow;
  118. },
  119. };
  120. </script>
  121. <style lang="less" scoped>
  122. .style {
  123. width: 100%;
  124. min-height: 667px;
  125. position: relative;
  126. background-color: #f9fafc;
  127. }
  128. .top {
  129. height: 46px;
  130. overflow: hidden;
  131. position: relative;
  132. z-index: 999;
  133. }
  134. .main {
  135. min-height: 570px;
  136. }
  137. .foot {
  138. position: absolute;
  139. bottom: 0;
  140. }
  141. </style>