plans.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <div class="plans-content">
  3. <div class="button-right">
  4. <el-button
  5. type="primary"
  6. icon="el-icon-plus"
  7. @click="showAddPlan">
  8. Individual Plan
  9. </el-button>
  10. </div>
  11. <el-table
  12. v-loading="table.loading"
  13. :data="table.data">
  14. <el-table-column
  15. align="center"
  16. label="Amount"
  17. prop="planCredit"
  18. min-width="100"/>
  19. <el-table-column
  20. align="center"
  21. label="Date Created"
  22. prop="createTime"
  23. min-width="120"/>
  24. <el-table-column
  25. align="center"
  26. label="Assigned Users"
  27. prop="assignedUsers"
  28. min-width="120"/>
  29. <el-table-column
  30. align="center"
  31. label="Current Consumption"
  32. prop="currentConsumptionCredit"
  33. min-width="140"/>
  34. <el-table-column
  35. align="center"
  36. label="Action"
  37. min-width="80">
  38. <template slot-scope="{row, $index}">
  39. <el-dropdown
  40. class="action-dropdown"
  41. @command="(v) => handleCommand(v, row)">
  42. <i class="el-icon-more icon-action"></i>
  43. <el-dropdown-menu slot="dropdown">
  44. <el-dropdown-item
  45. command="assignPlan">
  46. Assign Users
  47. </el-dropdown-item>
  48. <el-dropdown-item
  49. command="deletePlan">
  50. Delete
  51. </el-dropdown-item>
  52. </el-dropdown-menu>
  53. </el-dropdown>
  54. </template>
  55. </el-table-column>
  56. </el-table>
  57. <div class="right">
  58. <Pagination
  59. v-show="table.total"
  60. :total="table.total"
  61. :page.sync="filter.pageNum"
  62. :limit.sync="filter.pageSize"
  63. @pagination="getPlanList"/>
  64. </div>
  65. <el-dialog
  66. title="Individual Plan"
  67. :visible="addPlan.visible"
  68. :before-close="hideAddPlan"
  69. :close-on-click-modal="false"
  70. class="individual-plan-dialog">
  71. <div class="bold" style="padding-bottom: 15px;">Set Amount</div>
  72. <el-input
  73. class="add-text"
  74. v-model.number="addPlan.form.planCredit"
  75. maxlength="9"/>
  76. <div class="buttons">
  77. <el-button
  78. type="primary"
  79. class="cancel-button flex1"
  80. @click="hideAddPlan">
  81. Cancel
  82. </el-button>
  83. <el-button
  84. class="flex1"
  85. style="margin-left: 10px;"
  86. type="primary"
  87. :loading="addPlan.loading"
  88. @click="addPlanRow">
  89. Add
  90. </el-button>
  91. </div>
  92. </el-dialog>
  93. <assignment
  94. v-bind="dialogAssign"
  95. @hide="hideAssignDialog"/>
  96. </div>
  97. </template>
  98. <script>
  99. import limit from '@/api/limit.js'
  100. import Pagination from '@/components/Pagination'
  101. import assignment from './assignment.vue'
  102. export default {
  103. name: "plans",
  104. props: {
  105. id: {
  106. type: Number|String,
  107. default: ""
  108. },
  109. groupPk: {
  110. type: Number|String,
  111. default: ""
  112. }
  113. },
  114. data() {
  115. return {
  116. table: {
  117. total: 0,
  118. data: [],
  119. loading: false
  120. },
  121. filter: {
  122. pageNum: 1,
  123. pageSize: 10,
  124. pageCriteria: {
  125. criteria: "",
  126. groupCreditPk: ""
  127. }
  128. },
  129. addPlan: {
  130. visible: false,
  131. loading: false,
  132. form: {
  133. planCredit: "",
  134. groupCreditPk: ""
  135. }
  136. },
  137. dialogAssign: {
  138. item: {},
  139. groupPk: "",
  140. visible: false
  141. }
  142. };
  143. },
  144. components: {Pagination, assignment},
  145. mounted() {
  146. if (this.id) {
  147. this.addPlan.form.groupCreditPk = this.id;
  148. this.filter.pageCriteria.groupCreditPk = this.id;
  149. this.getPlanList();
  150. }
  151. },
  152. methods: {
  153. getPlanList() {
  154. this.table.loading = true;
  155. limit.getCreditLimitPlanPages(this.filter).then(res => {
  156. if (res.data.totalRow && res.data.records) {
  157. this.table.data = res.data.records
  158. this.table.total = res.data.totalRow
  159. } else {
  160. this.table.data = []
  161. this.table.total = 0
  162. }
  163. this.table.loading = false;
  164. }).catch(err => {
  165. this.table.loading = false;
  166. this.table.data = [];
  167. this.table.total = 0;
  168. })
  169. },
  170. handleCommand(fuc, item) {
  171. this[fuc](item)
  172. },
  173. showAddPlan() {
  174. this.addPlan.visible = true;
  175. },
  176. hideAddPlan() {
  177. this.addPlan.visible = false;
  178. this.addPlan.form.planCredit = "";
  179. },
  180. addPlanRow() {
  181. this.addPlan.loading = true;
  182. limit.addCreditLimitPlan(this.addPlan.form).then(res => {
  183. this.$message.success("Added successfully.")
  184. this.hideAddPlan();
  185. this.getPlanList();
  186. }).catch(err => {
  187. this.$message({
  188. message: err,
  189. type: 'error'
  190. })
  191. }).finally(() => {
  192. this.addPlan.loading = false;
  193. });
  194. },
  195. assignPlan(item) {
  196. this.dialogAssign.item = item;
  197. this.dialogAssign.groupPk = this.groupPk;
  198. this.dialogAssign.visible = true;
  199. },
  200. deletePlan(item) {
  201. this.$confirm('Are you sure you want to delete this plan?', 'Delete', {
  202. confirmButtonText: 'OK',
  203. cancelButtonText: 'Cancel',
  204. type: 'warning'
  205. }).then(res => {
  206. this.handleDeletePlan(item.groupCreditPlanId)
  207. })
  208. },
  209. handleDeletePlan(id) {
  210. limit.deleteCreditLimitPlan(id).then(res => {
  211. this.$message({
  212. message: 'Delete successfully',
  213. type: 'success'
  214. });
  215. this.getPlanList();
  216. }).catch(err => {
  217. this.$message({
  218. message: err,
  219. type: 'error'
  220. })
  221. })
  222. },
  223. hideAssignDialog(e) {
  224. this.dialogAssign.item = {};
  225. this.dialogAssign.visible = false;
  226. if (e) {
  227. this.getPlanList();
  228. this.$emit("refresh");
  229. }
  230. }
  231. }
  232. }
  233. </script>
  234. <style scoped>
  235. .plans-content {
  236. position: relative;
  237. }
  238. .button-right {
  239. top: -55px;
  240. right: 0;
  241. position: absolute;
  242. }
  243. .individual-plan-dialog {
  244. padding-bottom: 120px;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. .individual-plan-dialog >>> .el-dialog {
  250. width: 100%;
  251. max-width: 400px;
  252. }
  253. .buttons {
  254. display: flex;
  255. padding-top: 35px;
  256. align-items: center;
  257. }
  258. </style>