index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container">
  4. <div class="filter-view">
  5. <el-select
  6. class="filter-input"
  7. placeholder="All Status"
  8. clearable
  9. @change="onClickSearch"
  10. v-model="filters.pageVo.dataStatus">
  11. <el-option
  12. v-for="(item,index) in options.status"
  13. :key="index"
  14. :label="item.name"
  15. :value="item.value"/>
  16. </el-select>
  17. <el-select
  18. class="filter-input"
  19. @change="onClickSearch"
  20. placeholder="All Article Type"
  21. v-model="filters.pageVo.articleTypeId"
  22. clearable>
  23. <el-option
  24. v-for="(item,index) in options.types"
  25. :key="index"
  26. :label="item.name"
  27. :value="item.value"/>
  28. </el-select>
  29. <div
  30. class="filter-flex-button"
  31. v-if="!$route.meta.onlyView">
  32. <el-button
  33. icon="el-icon-plus"
  34. type="primary"
  35. @click="onClickAdd">
  36. Create
  37. </el-button>
  38. </div>
  39. </div>
  40. </div>
  41. <el-table
  42. v-loading="loading"
  43. :data="table.list">
  44. <el-table-column
  45. align="center"
  46. label="Article ID"
  47. prop="userPk"
  48. min-width="120">
  49. <template slot-scope="{row}" >
  50. <span
  51. class="link-type"
  52. @click="onClickEdit(row)"
  53. v-if="!$route.meta.onlyView">
  54. {{ row.articleId }}
  55. </span>
  56. <span v-else>{{ row.articleId }}</span>
  57. </template>
  58. </el-table-column>
  59. <el-table-column
  60. align="center"
  61. label="Title"
  62. prop="articleTitle"
  63. min-width="150"/>
  64. <el-table-column
  65. align="center"
  66. label="Article Type"
  67. prop="articleTypeName"
  68. min-width="100"/>
  69. <el-table-column
  70. align="center"
  71. label="Posted By"
  72. prop="createBy"
  73. min-width="120"/>
  74. <el-table-column
  75. align="center"
  76. label="Posted Date"
  77. prop="createTime"
  78. min-width="120"/>
  79. <el-table-column
  80. align="center"
  81. label="Views"
  82. prop="views"
  83. min-width="80"/>
  84. <el-table-column
  85. align="center"
  86. label="Status"
  87. prop="dataStatus"
  88. min-width="80"/>
  89. <el-table-column
  90. align="center"
  91. label="Action"
  92. min-width="120"
  93. v-if="!$route.meta.onlyView">
  94. <template v-slot="{ row }">
  95. <TableAction
  96. @edit="onClickEdit(row)"
  97. @delete="onClickDelete(row)"
  98. v-if="row.dataStatus != 'Inactive'"/>
  99. </template>
  100. </el-table-column>
  101. </el-table>
  102. <div class="right">
  103. <pagination
  104. v-show="table.total > 0"
  105. :total="table.total"
  106. :page.sync="filters.pageNo"
  107. :limit.sync="filters.pageSize"
  108. @pagination="getTableData" />
  109. </div>
  110. </div>
  111. </template>
  112. <script>
  113. import TableAction from '@/components/TableAction.vue'
  114. import Pagination from '@/components/Pagination'
  115. import charge from '../../http/api/charge'
  116. import api from '../../api/article.js'
  117. export default {
  118. data() {
  119. return {
  120. loading: false,
  121. filters: {
  122. pageNo: 1,
  123. pageSize: 10,
  124. pageVo: {
  125. criteria: "",
  126. dataStatus: "",
  127. articleTypeId: ""
  128. }
  129. },
  130. table: {
  131. list: [],
  132. total: 0
  133. },
  134. options: {
  135. status: [],
  136. types: []
  137. }
  138. };
  139. },
  140. components: { Pagination, TableAction },
  141. created() {
  142. this.getStatusOptions();
  143. this.onClickSearch();
  144. },
  145. methods: {
  146. onClickSearch() {
  147. this.filters.pageNo = 1
  148. this.getTableData()
  149. },
  150. getStatusOptions() {
  151. charge.getStatusOptions().then(res => {
  152. this.options.status = res.data;
  153. }).catch(err => {
  154. this.$message.error(err);
  155. }).finally(() => {
  156. this.getArticleTypeOptions()
  157. });
  158. },
  159. getArticleTypeOptions() {
  160. api.getArticleTypeOption().then(res => {
  161. this.options.types = res.data;
  162. }).catch(err => {
  163. this.$message.error(err);
  164. });
  165. },
  166. getTableData() {
  167. this.loading = true;
  168. api.getArticlePages(this.filters).then(res => {
  169. if (res.data && res.total) {
  170. this.table.total = res.total;
  171. this.table.list = res.data;
  172. } else {
  173. this.table.total = 0;
  174. this.table.list = [];
  175. }
  176. }).catch(err => {
  177. this.$message({
  178. type: 'error',
  179. message: err
  180. })
  181. this.table.total = 0;
  182. this.table.list = [];
  183. }).finally(() => {
  184. this.loading = false;
  185. })
  186. },
  187. onClickAdd() {
  188. this.$router.push({
  189. path: "/marketing-management/article/create"
  190. })
  191. },
  192. onClickEdit(row) {
  193. this.$router.push({
  194. path: "/marketing-management/article/update/" + row.articleId
  195. })
  196. },
  197. onClickDelete(row) {
  198. this.$confirm('Are you sure you want to delete this article?', 'Delete', {
  199. confirmButtonText: 'OK',
  200. cancelButtonText: 'Cancel',
  201. type: 'warning'
  202. }).then(res => {
  203. this.onDeleteArticle(row.articleId)
  204. })
  205. },
  206. onDeleteArticle(id) {
  207. this.loading = true;
  208. api.deleteArticle(id).then(res => {
  209. this.$message({
  210. type: 'success',
  211. message: "Delete success."
  212. })
  213. this.getTableData()
  214. }).catch(err => {
  215. this.$message({
  216. type: 'error',
  217. message: err
  218. })
  219. this.loading = false;
  220. })
  221. }
  222. }
  223. }
  224. </script>
  225. <style scoped>
  226. .filter-input {
  227. min-width: 100px;
  228. max-width: 300px;
  229. }
  230. </style>