index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main">
  5. <span v-if="display == 'list'">
  6. <el-col :span="24" class="btn">
  7. <el-button type="primary" size="mini" @click="add">添加信息</el-button>
  8. </el-col>
  9. <el-col :span="24" class="list">
  10. <data-table
  11. :fields="fields"
  12. :data="list"
  13. :total="total"
  14. @query="search"
  15. :opera="opera"
  16. @view="toView"
  17. @edit="toEdit"
  18. @delete="toDelete"
  19. ></data-table>
  20. </el-col>
  21. </span>
  22. <span v-else-if="display == 'detail'">
  23. <el-col :span="24" class="btn">
  24. <el-button type="primary" size="mini" @click="back">返回列表</el-button>
  25. </el-col>
  26. <el-col :span="24" class="detail">
  27. <data-form :data="form" :fields="formFields" @save="toSave">
  28. <template #custom="{item, form}">
  29. <template v-if="item.model === 'img_path'">
  30. <upload :limit="1" :data="form.img_path" type="img_path" :url="'/files/img_path/upload'" @upload="uploadSuccess"></upload>
  31. </template>
  32. <template v-if="item.model === 'file_path'">
  33. <uploadfile
  34. :limit="1"
  35. :data="form.file_path"
  36. type="file_path"
  37. listType=""
  38. :url="'/files/file_path/upload'"
  39. @upload="sucfile"
  40. @delete="delfile"
  41. ></uploadfile>
  42. </template>
  43. </template>
  44. </data-form>
  45. </el-col>
  46. </span>
  47. <span v-else-if="display == 'projectList'">
  48. <el-col :span="24" class="btn">
  49. <el-button type="primary" size="mini" @click="back">返回列表</el-button>
  50. </el-col>
  51. <el-col :span="24" class="projectList">
  52. <data-table :fields="profields" :opera="proopera" :data="prolist" :total="prototal" @query="prosearch"></data-table>
  53. </el-col>
  54. </span>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. </template>
  59. <script>
  60. import dataTable from '@/components/data-table.vue';
  61. import dataForm from '@/components/form.vue';
  62. import upload from '@/components/uploadone.vue';
  63. import uploadfile from '@/components/uploaddock.vue';
  64. import { mapState, createNamespacedHelpers } from 'vuex';
  65. const { mapActions: question } = createNamespacedHelpers('question');
  66. const { mapActions: projectsolic } = createNamespacedHelpers('projectsolic');
  67. export default {
  68. metaInfo() {
  69. return { title: this.$route.meta.title };
  70. },
  71. name: 'index',
  72. props: {},
  73. components: {
  74. dataTable,
  75. dataForm,
  76. upload,
  77. uploadfile,
  78. },
  79. data: function() {
  80. return {
  81. // 显示
  82. display: 'list',
  83. opera: [
  84. {
  85. label: '查看项目征集',
  86. method: 'view',
  87. },
  88. {
  89. label: '编辑',
  90. method: 'edit',
  91. },
  92. {
  93. label: '删除',
  94. method: 'delete',
  95. },
  96. ],
  97. fields: [
  98. { label: '信息标题', prop: 'title' },
  99. { label: '信息来源', prop: 'origin' },
  100. { label: '发布时间', prop: 'create_date' },
  101. ],
  102. list: [],
  103. total: 0,
  104. // 添加数据
  105. form: {},
  106. formFields: [
  107. { label: '信息标题', model: 'title' },
  108. { label: '发布时间', model: 'create_date', type: 'date' },
  109. { label: '信息来源', model: 'origin' },
  110. { label: '图片', model: 'img_path', custom: true },
  111. { label: '附件', model: 'file_path', custom: true },
  112. { label: '信息内容', model: 'content', type: 'editor' },
  113. ],
  114. // 项目征集列表
  115. proid: '',
  116. proopera: [],
  117. profields: [
  118. { label: '项目名称', prop: 'name' },
  119. { label: '建议单位', prop: 'company' },
  120. { label: '联系人', prop: 'contacts' },
  121. { label: '联系方式', prop: 'phone' },
  122. ],
  123. prolist: [],
  124. prototal: 0,
  125. };
  126. },
  127. async created() {
  128. await this.search();
  129. },
  130. methods: {
  131. ...question(['query', 'create', 'update', 'delete']),
  132. ...projectsolic({ solicQuery: 'query', solicFetch: 'fetch' }),
  133. async search({ skip = 0, limit = 10, ...info } = {}) {
  134. const res = await this.query({ skip, limit, ...info });
  135. if (this.$checkRes(res)) {
  136. this.$set(this, `list`, res.data);
  137. this.$set(this, `total`, res.total);
  138. }
  139. },
  140. // 修改
  141. toEdit({ data }) {
  142. this.$set(this, 'form', _.cloneDeep(data));
  143. this.display = 'detail';
  144. },
  145. // 删除
  146. async toDelete({ data }) {
  147. const res = await this.delete(data.id);
  148. if (this.$checkRes(res, '删除成功', '删除失败' || res.errmsg)) {
  149. this.search();
  150. }
  151. },
  152. // 添加数据
  153. add() {
  154. this.display = 'detail';
  155. },
  156. // 添加,修改
  157. async toSave({ data }) {
  158. const dup = _.cloneDeep(data);
  159. let res;
  160. if (dup.id) {
  161. res = await this.update(dup);
  162. } else {
  163. res = await this.create(dup);
  164. }
  165. if (this.$checkRes(res, '保存成功', res.errmsg || '保存失败')) {
  166. this.search();
  167. this.back();
  168. }
  169. },
  170. // 查看项目征集
  171. toView({ data }) {
  172. this.display = 'projectList';
  173. this.$set(this, `proid`, data._id);
  174. this.prosearch();
  175. },
  176. // 查看调研调查中的项目征集数据
  177. async prosearch({ skip = 0, limit = 10, ...info } = {}) {
  178. const res = await this.solicQuery({ skip, limit, question_id: this.proid });
  179. if (this.$checkRes(res)) {
  180. this.$set(this, `prolist`, res.data);
  181. this.$set(this, `prototal`, res.total);
  182. }
  183. },
  184. // 返回列表
  185. back() {
  186. this.form = {};
  187. this.display = 'list';
  188. this.search();
  189. },
  190. // 图片上传
  191. uploadSuccess({ type, data }) {
  192. this.$set(this.form, `${type}`, data.uri);
  193. },
  194. // 视频文件
  195. sucfile({ type, data }) {
  196. this.$set(this.form, `${type}`, data.uri);
  197. },
  198. delfile(index) {
  199. this.$set(this.form, `file_path`, '');
  200. },
  201. },
  202. computed: {
  203. ...mapState(['user']),
  204. },
  205. watch: {},
  206. };
  207. </script>
  208. <style lang="less" scoped>
  209. .main {
  210. padding: 0 15px 0 0;
  211. .btn {
  212. text-align: right;
  213. margin: 0 0 10px 0;
  214. }
  215. }
  216. </style>