detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div id="detail">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <el-col :span="24" class="top">
  6. <el-button type="primary" size="mini" @click="back">返回</el-button>
  7. </el-col>
  8. <el-col :span="24" class="down" v-loading="loading">
  9. <data-form :data="form" :fields="fields" :rules="{}" @save="toSave" v-if="!loading" :useEnter="false">
  10. <template #custom="{item,form}">
  11. <template v-if="item.model == 'picture'">
  12. <upload :limit="1" :data="form.picture" type="picture" :url="'/files/picture/upload'" @upload="uploadSuccess" @delete="uploadDelete"></upload>
  13. </template>
  14. <template v-else-if="item.model == 'video'">
  15. <upload
  16. :limit="1"
  17. :data="form.video"
  18. listType=""
  19. type="video"
  20. :url="'/files/video/upload'"
  21. @upload="uploadSuccess"
  22. @delete="uploadDelete"
  23. ></upload>
  24. </template>
  25. <template v-else-if="item.model == 'filepath'">
  26. <upload
  27. :limit="1"
  28. :data="form.filepath"
  29. listType=""
  30. type="filepath"
  31. :url="'/files/filepath/upload'"
  32. @upload="uploadSuccess"
  33. @delete="uploadDelete"
  34. ></upload>
  35. </template>
  36. <template v-else-if="item.model == 'is_money'">
  37. <el-switch v-model="form.is_money" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
  38. </template>
  39. <template v-else-if="item.model == 'money_url'">
  40. <upload
  41. :limit="1"
  42. :data="form.money_url"
  43. type="money_url"
  44. :url="'/files/moneyurl/upload'"
  45. @upload="uploadMoney"
  46. @delete="uploadDelMoney"
  47. v-if="form.is_money"
  48. ></upload>
  49. </template>
  50. </template>
  51. </data-form>
  52. </el-col>
  53. </el-col>
  54. </el-row>
  55. </div>
  56. </template>
  57. <script>
  58. import dataForm from '@common/src/components/frame/form.vue';
  59. import upload from '@common/src/components/frame/upload.vue';
  60. import { mapState, createNamespacedHelpers } from 'vuex';
  61. const { mapActions: mapViewPoint } = createNamespacedHelpers('viewPoint');
  62. export default {
  63. metaInfo() {
  64. return { title: this.$route.meta.title };
  65. },
  66. name: 'detail',
  67. props: {},
  68. components: { dataForm, upload },
  69. data: function() {
  70. return {
  71. fields: [
  72. { label: '信息标题', model: 'title' },
  73. { label: '发布时间', model: 'publish_time', type: 'date' },
  74. { label: '信息来源', model: 'origin' },
  75. { label: '信息简介', model: 'brief', type: 'textarea' },
  76. { label: '是否收费', model: 'is_money', custom: true },
  77. { label: '上传收款图片', model: 'money_url', custom: true },
  78. { label: '图片文件', model: 'picture', custom: true },
  79. { label: '视频文件', model: 'video', custom: true },
  80. { label: '附件文件', model: 'filepath', custom: true },
  81. { label: '内容', model: 'content', type: 'editor' },
  82. ],
  83. form: {},
  84. loading: false,
  85. };
  86. },
  87. async created() {
  88. if (this.id) {
  89. await this.search();
  90. }
  91. },
  92. methods: {
  93. ...mapViewPoint(['fetch', 'update', 'create']),
  94. async search() {
  95. this.loading = true;
  96. let res = await this.fetch(this.id);
  97. if (this.$checkRes(res)) {
  98. this.$set(this, `form`, res.data);
  99. this.loading = false;
  100. }
  101. },
  102. async toSave({ data }) {
  103. if (data.id) {
  104. let res = await this.update(data);
  105. if (this.$checkRes(res)) {
  106. this.$message({
  107. message: '信息修改成功',
  108. type: 'success',
  109. });
  110. this.back();
  111. }
  112. } else {
  113. data.user_id = this.user.id;
  114. let res = await this.create(data);
  115. if (this.$checkRes(res)) {
  116. this.$message({
  117. message: '信息创建成功',
  118. type: 'success',
  119. });
  120. this.back();
  121. }
  122. }
  123. },
  124. // 返回列表
  125. back() {
  126. this.$router.push({ path: '/viewPoint' });
  127. },
  128. // 钱图片上传
  129. uploadMoney({ type, data }) {
  130. this.$set(this.form, `${type}`, data.uri);
  131. },
  132. // 钱图片删除
  133. uploadDelMoney(data) {
  134. this.$set(this.form, `${data.type}`, null);
  135. },
  136. // 图片上传
  137. uploadSuccess({ type, data }) {
  138. this.$set(this.form, `${type}`, { url: data.uri, name: data.name });
  139. },
  140. // 删除图片
  141. uploadDelete(data) {
  142. this.$set(this.form, `${data.type}`, {});
  143. },
  144. number() {
  145. this.form.money = this.form.money.replace(/[^\.\d]/g, '');
  146. this.form.money = this.form.money.replace('.', '');
  147. },
  148. },
  149. computed: {
  150. ...mapState(['user']),
  151. id() {
  152. return this.$route.query.id;
  153. },
  154. },
  155. watch: {},
  156. };
  157. </script>
  158. <style lang="less" scoped>
  159. .main {
  160. .top {
  161. text-align: right;
  162. margin: 0 0 10px 0;
  163. }
  164. }
  165. </style>