plans.vue 6.4 KB

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