| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- <template>
- <div class="plans-content">
- <div class="button-right">
- <el-button
- type="primary"
- icon="el-icon-plus"
- @click="showAddPlan">
- Individual Plan
- </el-button>
- </div>
- <el-table
- v-loading="table.loading"
- :data="table.data">
- <el-table-column
- align="center"
- label="Amount"
- prop="planCredit"
- min-width="100"/>
- <el-table-column
- align="center"
- label="Date Created"
- prop="createTime"
- min-width="120"/>
- <el-table-column
- align="center"
- label="Assigned Users"
- prop="assignedUsers"
- min-width="150">
- <template slot-scope="{row}">
- <span class="link-type" @click="assignPlan(row)">{{row.assignedUsers}}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- label="Current Consumption"
- prop="individualCurrentConsumption"
- min-width="170"/>
- <el-table-column
- align="center"
- label="Action"
- min-width="80">
- <template slot-scope="{row, $index}">
- <el-dropdown
- class="action-dropdown"
- @command="(v) => handleCommand(v, row)">
- <i class="el-icon-more icon-action"></i>
- <el-dropdown-menu slot="dropdown">
- <el-dropdown-item
- command="assignPlan">
- Assign Users
- </el-dropdown-item>
- <el-dropdown-item
- command="deletePlan"
- v-if="canDelete">
- Delete
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
- </template>
- </el-table-column>
- </el-table>
- <div class="right">
- <Pagination
- v-show="table.total"
- :total="table.total"
- :page.sync="filter.pageNum"
- :limit.sync="filter.pageSize"
- @pagination="getPlanList"/>
- </div>
- <el-dialog
- title="Individual Plan"
- :visible="addPlan.visible"
- :before-close="hideAddPlan"
- :close-on-click-modal="false"
- class="individual-plan-dialog">
- <div class="bold" style="padding-bottom: 15px;">Set Amount</div>
- <el-input
- class="add-text"
- v-model.number="addPlan.form.planCredit"
- maxlength="9"/>
- <div class="buttons">
- <el-button
- type="primary"
- class="cancel-button flex1"
- @click="hideAddPlan">
- Cancel
- </el-button>
- <el-button
- class="flex1"
- style="margin-left: 10px;"
- type="primary"
- :loading="addPlan.loading"
- @click="addPlanRow">
- Add
- </el-button>
- </div>
- </el-dialog>
- <assignment
- v-bind="dialogAssign"
- @hide="hideAssignDialog"/>
- </div>
- </template>
- <script>
- import limit from '@/api/limit.js'
- import Pagination from '@/components/Pagination'
- import assignment from './assignment.vue'
- export default {
- name: "plans",
- props: {
- id: {
- type: Number|String,
- default: ""
- },
- groupPk: {
- type: Number|String,
- default: ""
- },
- canDelete: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- table: {
- total: 0,
- data: [],
- loading: false
- },
- filter: {
- pageNum: 1,
- pageSize: 10,
- pageCriteria: {
- criteria: "",
- groupCreditPk: ""
- }
- },
- addPlan: {
- visible: false,
- loading: false,
- form: {
- planCredit: "",
- groupCreditPk: ""
- }
- },
- dialogAssign: {
- item: {},
- groupPk: "",
- visible: false
- }
- };
- },
- components: {Pagination, assignment},
- mounted() {
- if (this.id) {
- this.addPlan.form.groupCreditPk = this.id;
- this.filter.pageCriteria.groupCreditPk = this.id;
- this.getPlanList();
- }
- },
- methods: {
- getPlanList() {
- this.table.loading = true;
- limit.getCreditLimitPlanPages(this.filter).then(res => {
- if (res.data.totalRow && res.data.records) {
- this.table.data = res.data.records
- this.table.total = res.data.totalRow
- } else {
- this.table.data = []
- this.table.total = 0
- }
- this.table.loading = false;
- }).catch(err => {
- this.table.loading = false;
- this.table.data = [];
- this.table.total = 0;
- })
- },
- handleCommand(fuc, item) {
- this[fuc](item)
- },
- showAddPlan() {
- this.addPlan.visible = true;
- },
- hideAddPlan() {
- this.addPlan.visible = false;
- this.addPlan.form.planCredit = "";
- },
- addPlanRow() {
- this.addPlan.loading = true;
- limit.addCreditLimitPlan(this.addPlan.form).then(res => {
- this.$message.success("Added successfully.")
- this.hideAddPlan();
- this.getPlanList();
- }).catch(err => {
- this.$message({
- message: err,
- type: 'error'
- })
- }).finally(() => {
- this.addPlan.loading = false;
- });
- },
- assignPlan(item) {
- this.dialogAssign.item = item;
- this.dialogAssign.groupPk = this.groupPk;
- this.dialogAssign.visible = true;
- },
- deletePlan(item) {
- this.$confirm('Are you sure you want to delete this plan?', 'Delete', {
- confirmButtonText: 'OK',
- cancelButtonText: 'Cancel',
- type: 'warning'
- }).then(res => {
- this.handleDeletePlan(item.groupCreditPlanId)
- })
- },
- handleDeletePlan(id) {
- limit.deleteCreditLimitPlan(id).then(res => {
- this.$message({
- message: 'Delete successfully',
- type: 'success'
- });
- this.getPlanList();
- }).catch(err => {
- this.$message({
- message: err,
- type: 'error'
- })
- })
- },
- hideAssignDialog(e) {
- this.dialogAssign.item = {};
- this.dialogAssign.visible = false;
- if (e) {
- this.getPlanList();
- this.$emit("refresh");
- }
- }
- }
- }
- </script>
- <style scoped>
- .plans-content {
- position: relative;
- }
- .button-right {
- top: -55px;
- right: 0;
- position: absolute;
- }
- .individual-plan-dialog {
- padding-bottom: 120px;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .individual-plan-dialog >>> .el-dialog {
- width: 100%;
- max-width: 400px;
- }
- .buttons {
- display: flex;
- padding-top: 35px;
- align-items: center;
- }
- </style>
|