index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. <div
  18. class="filter-flex-button"
  19. v-if="!$route.meta.onlyView">
  20. <el-button
  21. icon="el-icon-plus"
  22. type="primary"
  23. @click="onClickAdd">
  24. Create
  25. </el-button>
  26. </div>
  27. </div>
  28. </div>
  29. <el-table
  30. v-loading="loading"
  31. :data="table.list">
  32. <el-table-column
  33. align="center"
  34. label="Campaign ID"
  35. prop="userPk"
  36. min-width="120">
  37. <template slot-scope="{row}" >
  38. <span
  39. class="link-type"
  40. @click="onClickEdit(row)"
  41. v-if="!$route.meta.onlyView && row.dataStatus != 'Inactive'">
  42. {{ row.campaignId }}
  43. </span>
  44. <span v-else>{{ row.campaignId }}</span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column
  48. align="center"
  49. label="Campaign Title"
  50. prop="campaignTitle"
  51. min-width="150"/>
  52. <el-table-column
  53. align="center"
  54. label="Start Date and End Date"
  55. prop="campaignDuration"
  56. min-width="180"/>
  57. <el-table-column
  58. align="center"
  59. label="Status"
  60. prop="dataStatus"
  61. min-width="80"/>
  62. <el-table-column
  63. align="center"
  64. label="No. of Sites"
  65. prop="assignedSiteCount"
  66. min-width="120"/>
  67. <el-table-column
  68. align="center"
  69. label="Created By"
  70. prop="createBy"
  71. min-width="120"/>
  72. <el-table-column
  73. align="center"
  74. label="Created On"
  75. prop="createTime"
  76. min-width="120"/>
  77. <el-table-column
  78. align="center"
  79. label="Action"
  80. min-width="80"
  81. v-if="!$route.meta.onlyView">
  82. <template v-slot="{ row }">
  83. <el-dropdown
  84. class="action-dropdown"
  85. @command="(v) => handleCommand(v, row)"
  86. v-if="row.dataStatus != 'Inactive'">
  87. <i class="el-icon-more icon-action"></i>
  88. <el-dropdown-menu slot="dropdown">
  89. <el-dropdown-item
  90. command="assignSites">
  91. Assign Sites
  92. </el-dropdown-item>
  93. <el-dropdown-item
  94. command="onClickEdit">
  95. Edit
  96. </el-dropdown-item>
  97. <el-dropdown-item
  98. command="onClickDelete">
  99. Delete
  100. </el-dropdown-item>
  101. </el-dropdown-menu>
  102. </el-dropdown>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <div class="right">
  107. <pagination
  108. v-show="table.total > 0"
  109. :total="table.total"
  110. :page.sync="filters.pageNo"
  111. :limit.sync="filters.pageSize"
  112. @pagination="getTableData" />
  113. </div>
  114. <DialogAssignment
  115. v-bind="dialogAssign"
  116. @hide="hideAssignDialog"/>
  117. </div>
  118. </template>
  119. <script>
  120. import TableAction from '@/components/TableAction.vue'
  121. import Pagination from '@/components/Pagination'
  122. import DialogAssignment from './assignment.vue'
  123. import charge from '../../http/api/charge'
  124. import api from '../../api/campaign.js'
  125. export default {
  126. data() {
  127. return {
  128. loading: false,
  129. filters: {
  130. pageNo: 1,
  131. pageSize: 10,
  132. pageVo: {
  133. criteria: "",
  134. dataStatus: ""
  135. }
  136. },
  137. table: {
  138. list: [],
  139. total: 0
  140. },
  141. options: {
  142. status: [],
  143. types: []
  144. },
  145. dialogAssign: {
  146. item: {},
  147. visible: false
  148. }
  149. };
  150. },
  151. components: { Pagination, TableAction, DialogAssignment },
  152. created() {
  153. this.getStatusOptions();
  154. this.onClickSearch();
  155. },
  156. methods: {
  157. onClickSearch() {
  158. this.filters.pageNo = 1
  159. this.getTableData()
  160. },
  161. getStatusOptions() {
  162. charge.getStatusOptions().then(res => {
  163. this.options.status = res.data;
  164. }).catch(err => {
  165. this.$message.error(err);
  166. })
  167. },
  168. getTableData() {
  169. this.loading = true;
  170. api.getCampaignPages(this.filters).then(res => {
  171. if (res.data && res.total) {
  172. this.table.total = res.total;
  173. this.table.list = res.data;
  174. } else {
  175. this.table.total = 0;
  176. this.table.list = [];
  177. }
  178. }).catch(err => {
  179. this.$message({
  180. type: 'error',
  181. message: err
  182. })
  183. this.table.total = 0;
  184. this.table.list = [];
  185. }).finally(() => {
  186. this.loading = false;
  187. })
  188. },
  189. onClickAdd() {
  190. this.$router.push({
  191. path: "/marketing-management/campaign/create"
  192. })
  193. },
  194. handleCommand(cb, item) {
  195. this[cb](item)
  196. },
  197. assignSites(row) {
  198. if (row) {
  199. this.dialogAssign.item = row;
  200. this.dialogAssign.visible = true;
  201. }
  202. },
  203. hideAssignDialog(e) {
  204. this.dialogAssign.item = {};
  205. this.dialogAssign.visible = false;
  206. if (e) {
  207. this.getTableData();
  208. }
  209. },
  210. onClickEdit(row) {
  211. this.$router.push({
  212. path: "/marketing-management/campaign/update/" + row.campaignId
  213. })
  214. },
  215. onClickDelete(row) {
  216. this.$confirm('Are you sure you want to delete this campaign?', 'Delete', {
  217. confirmButtonText: 'OK',
  218. cancelButtonText: 'Cancel',
  219. type: 'warning'
  220. }).then(res => {
  221. this.onDeleteCampaign(row.campaignId)
  222. })
  223. },
  224. onDeleteCampaign(id) {
  225. this.loading = true;
  226. api.deleteCampaign(id).then(res => {
  227. this.$message({
  228. type: 'success',
  229. message: "Delete success."
  230. })
  231. this.getTableData()
  232. }).catch(err => {
  233. this.$message({
  234. type: 'error',
  235. message: err
  236. })
  237. this.loading = false;
  238. })
  239. }
  240. }
  241. }
  242. </script>
  243. <style scoped>
  244. .filter-input {
  245. min-width: 100px;
  246. max-width: 300px;
  247. }
  248. </style>