index.vue 6.0 KB

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