Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // // //child
  2.  
  3. <template>
  4.     <div>
  5.         <el-dialog
  6.                 :title="titleDialog"
  7.                 :visible.sync="dialogVisible"
  8.                 width="30%">
  9.             <el-alert
  10.                     :title="titleAlert"
  11.                     :type="typeAlert"
  12.                     :closable="false">
  13.             </el-alert>
  14.             <span slot="footer" class="dialog-footer">
  15.                 <el-button @click="dialogVisible = false">Отмена</el-button>
  16.                 <el-button type="primary" @click="handleConfirmation">Подтверждаю</el-button>
  17.             </span>
  18.         </el-dialog>
  19.     </div>
  20. </template>
  21.  
  22. <script>
  23.     export default {
  24.         name: 'page-elements-dialog',
  25.         props: ['titleDialog', 'dialogVisible', 'typeAlert', 'titleAlert'],
  26.         methods: {
  27.             handleConfirmation: function () {
  28.                 this.$emit('handleConfirmation');
  29.             }
  30.         }
  31.     }
  32. </script>
  33.  
  34. // // //parent
  35. <template>
  36.     <div>
  37.         <PageElementsBreadcrumb :breadcrumbElements="breadcrumbElements"/>
  38.  
  39.         <el-table
  40.                 v-loading="loading"
  41.                 :data="users"
  42.                 style="width: 100%">
  43.             <el-table-column
  44.                     fixed
  45.                     prop="id"
  46.                     label="ID"
  47.                     min-width="50">
  48.             </el-table-column>
  49.             <el-table-column
  50.                     prop="name"
  51.                     label="Имя"
  52.                     min-width="150">
  53.             </el-table-column>
  54.             <el-table-column type="expand">
  55.                 <template slot-scope="props">
  56.                     <p>Имя: {{ props.row.name }}</p>
  57.                     <p>E-mail: {{ props.row.email }}</p>
  58.                     <template v-if="props.row.reliability === 1">
  59.                         <p>Статус надежности: Надежный пользователь</p>
  60.                     </template>
  61.                     <template v-else>
  62.                         <p>Статус надежности: Не надежный пользователь</p>
  63.                     </template>
  64.                     <p v-if="props.row.description !== null && props.row.description.length > 0">Примечание: {{ props.row.description }}</p>
  65.                     <p v-if="props.row.discount !== 0">Персональный процент скидки: {{ props.row.discount}}</p>
  66.                 </template>
  67.             </el-table-column>
  68.             <el-table-column
  69.                     prop="email"
  70.                     label="E-mail"
  71.                     min-width="150">
  72.             </el-table-column>
  73.             <el-table-column
  74.                     label="Статус"
  75.                     min-width="150">
  76.                 <template slot-scope="props">
  77.                     <template v-if="props.row.status === 'administration'">
  78.                         <p>Администратор</p>
  79.                     </template>
  80.                     <template v-else>
  81.                         <p>Пользователь</p>
  82.                     </template>
  83.                 </template>
  84.             </el-table-column>
  85.             <el-table-column
  86.                     fixed="right"
  87.                     label="Управление"
  88.                     min-width="150">
  89.                 <template slot-scope="props">
  90.                     <el-button
  91.                             @click.native.prevent="goToUpdate(props.row.id)"
  92.                             size="mini">
  93.                         <i class="el-icon-edit"></i>
  94.                     </el-button>
  95.                     <el-button
  96.                             size="mini"
  97.                             type="danger"
  98.                             @click.native.prevent="deleteRow(props.$index, users)">
  99.                         <i class="el-icon-delete"></i>
  100.                     </el-button>
  101.                 </template>
  102.             </el-table-column>
  103.         </el-table>
  104.  
  105.         <PageElementsPagination :total="total"
  106.                                 :currentPage="currentPage"
  107.                                 :pageSize="pageSize"
  108.                                 v-on:change="handleCurrentPageChange"/>
  109.  
  110.         <PageElementsDialog :dialogVisible="dialogVisible"
  111.                             :titleDialog="titleDialog"
  112.                             :typeAlert="typeAlert"
  113.                             :titleAlert="titleAlert"
  114.                             v-on:handleConfirmation="deleteUser"/>
  115.     </div>
  116. </template>
  117.  
  118. <script>
  119.     import { PageElementsPagination, PageElementsBreadcrumb, PageElementsDialog} from '../page/elements';
  120.  
  121.     export default {
  122.         name: 'users-list',
  123.         mounted () {
  124.             this.breadcrumbElements = [
  125.                 {href: this.$router.resolve({name: 'main'}).href, title: 'Главная'},
  126.                 {href: this.$router.resolve({name: 'users-list'}).href, title: 'Список пользователей'},
  127.             ];
  128.             if (this.$store.getters.users.data !== undefined
  129.                 && this.$store.getters.users.data.length) {
  130.                 this.users = this.$store.getters.users.data;
  131.                 this.total = this.$store.getters.users.total;
  132.                 this.currentPage = this.$store.getters.users.current_page;
  133.                 this.pageSize = this.$store.getters.users.per_page;
  134.                 this.loading = false;
  135.                 return false;
  136.             }
  137.             this.getUsers();
  138.         },
  139.         data() {
  140.             return {
  141.                 users: [],
  142.                 currentPage: 0,
  143.                 total: 0,
  144.                 pageSize: 0,
  145.                 breadcrumbElements: [],
  146.                 loading: true,
  147.                 dialogVisible: false,
  148.                 titleDialog: '',
  149.                 operationsOnUser: null,
  150.                 typeAlert: 'warning',
  151.                 titleAlert: ''
  152.             }
  153.         },
  154.         methods: {
  155.             deleteUser: function () {
  156.                 console.log('delete user');
  157.             },
  158.             deleteRow: function (index, users) {
  159.                 this.operationsOnUser = users[index];
  160.                 this.titleDialog = 'Удаление пользователя';
  161.                 this.titleAlert = `Вы дейстительно хотите удалить пользователя ${this.operationsOnUser.name}`;
  162.                 this.dialogVisible = true;
  163.             },
  164.             getUsers: function (page = 1) {
  165.                 this.loading = true;
  166.                 return axios.get('/api/admin/users?page=' + page).then((response) => {
  167.                     this.users = response.data.users.data;
  168.                     this.total = response.data.users.total;
  169.                     this.currentPage = response.data.users.current_page;
  170.                     this.pageSize = response.data.users.per_page;
  171.                     this.$store.commit('updateUsers', response.data.users);
  172.                     this.loading = false;
  173.                 });
  174.             },
  175.             handleCurrentPageChange: function (val) {
  176.                 if (val !== this.currentPage) {
  177.                     this.getUsers(val);
  178.                 }
  179.             },
  180.             goToUpdate: function (id) {
  181.                 this.$router.push({name: 'users-update', params: {id: id}})
  182.             }
  183.         },
  184.         components: {
  185.             PageElementsPagination,
  186.             PageElementsBreadcrumb,
  187.             PageElementsDialog
  188.         }
  189.     }
  190. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement