Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!--
  2. <template>
  3.   <v-container>
  4.     <v-layout justify-center>
  5.       <v-flex xs12 sm12>
  6.         <v-card class="elevation-1"></v-card>
  7.       </v-flex>
  8.     </v-layout>
  9.   </v-container>
  10. </template>
  11.  
  12. <script>
  13. export default {
  14.   data() {
  15.     return {
  16.       loading: false,
  17.       anthropometricData:[],
  18.     };
  19.   },
  20.   filters: {},
  21.   methods: {
  22.     init() {
  23.       this.$store.dispatch("loading/setLoading", true);
  24.       this.$http
  25.         .get(`/api/cabinet/user/anthropometric`)
  26.         .then(
  27.           r => {
  28.             this.anthropometricData = r.data.anthropometricData || [];
  29.           },
  30.           e => {
  31.             this.$message.error(e.data.message);
  32.           }
  33.         )
  34.         .finally(() => {
  35.           this.$store.dispatch("loading/setLoading", false);
  36.         });
  37.     }
  38.   },
  39.   created() {},
  40.   mounted() {
  41.     this.init();
  42.   }
  43. };
  44. </script>
  45.  -->
  46.  
  47.  
  48. <template>
  49.   <v-container>
  50.     <v-layout justify-center>
  51.       <v-flex xs12 sm12>
  52.         <v-card class="elevation-1">
  53.           <v-dialog
  54.             v-model="dialog"
  55.             max-width="500px">
  56.             <template v-slot:activator="{ on }">
  57.               <v-btn
  58.                 color="general"
  59.                 dark
  60.                 class="mb-2"
  61.                 v-on="on">Добавить новые данные пользователя</v-btn>
  62.             </template>
  63.  
  64.             <v-card>
  65.               <v-card-text>
  66.                 <v-container grid-list-md >
  67.                   <v-layout wrap>
  68.                     <v-flex
  69.                       xs12
  70.                       sm6
  71.                       md4>
  72.                       <v-text-field
  73.                         v-model="editedItem.name"
  74.                         label="Dessert name" />
  75.                     </v-flex>
  76.                     <v-flex
  77.                       xs12
  78.                       sm6
  79.                       md4>
  80.                       <v-text-field
  81.                         v-model="editedItem.calories"
  82.                         label="Calories" />
  83.                     </v-flex>
  84.                     <v-flex
  85.                       xs12
  86.                       sm6
  87.                       md4>
  88.                       <v-text-field
  89.                         v-model="editedItem.fat"
  90.                         label="Fat (g)"/>
  91.                     </v-flex>
  92.                     <v-flex
  93.                       xs12
  94.                       sm6
  95.                       md4>
  96.                       <v-text-field
  97.                         v-model="editedItem.carbs"
  98.                         label="Carbs (g)"/>
  99.                     </v-flex>
  100.                     <v-flex
  101.                       xs12
  102.                       sm6
  103.                       md4>
  104.                       <v-text-field
  105.                         v-model="editedItem.protein"
  106.                         label="Protein (g)"/>
  107.                     </v-flex>
  108.                   </v-layout>
  109.                 </v-container>
  110.               </v-card-text>
  111.  
  112.               <v-card-actions>
  113.                 <v-spacer/>
  114.                 <v-btn
  115.                   color="blue darken-1"
  116.                   flat
  117.                   @click="close">Отменить</v-btn>
  118.                 <v-btn
  119.                   color="blue darken-1"
  120.                   flat
  121.                   @click="save">Сохранить</v-btn>
  122.               </v-card-actions>
  123.             </v-card>
  124.           </v-dialog>
  125.           <v-data-table
  126.             :headers="headers"
  127.             :items="desserts"
  128.             class="elevation-1"
  129.           >
  130.             <!-- change table header color(or other properties) -->
  131.             <template
  132.               slot="headerCell"
  133.               slot-scope="{ header }"
  134.             >
  135.               <span
  136.                 class="subheading font-weight-light text-general text--darken-3"
  137.                 v-text="header.text"
  138.               ></span>
  139.             </template>
  140.             <template v-slot:items="props">
  141.               <td>{{ props.item.name }}</td>
  142.               <td>{{ props.item.calories }}</td>
  143.               <td>{{ props.item.fat }}</td>
  144.               <td>{{ props.item.carbs }}</td>
  145.               <td>{{ props.item.protein }}</td>
  146.               <td class="justify-center ">
  147.                 <v-icon
  148.                   medium
  149.                   class="mr-2"
  150.                   @click="editItem(props.item)"
  151.                 >
  152.                   edit
  153.                 </v-icon>
  154.                 <v-icon
  155.                   medium
  156.                   @click="deleteItem(props.item)"
  157.                 >
  158.                   delete
  159.                 </v-icon>
  160.               </td>
  161.             </template>
  162.             <template v-slot:no-data>
  163.               <v-btn
  164.                 color="primary"
  165.                 @click="initialize">Сброс настроек</v-btn>
  166.             </template>
  167.           </v-data-table>
  168.         </v-card>
  169.       </v-flex>
  170.     </v-layout>
  171.   </v-container>
  172. </template>
  173.  
  174. <script>
  175. export default {
  176.   data: () => ({
  177.     dialog: false,
  178.     headers: [
  179.       {
  180.         text: 'Dessert (100g serving)',
  181.         align: 'left',
  182.         sortable: false,
  183.         value: 'name'
  184.       },
  185.       { text: 'Calories', value: 'calories' },
  186.       { text: 'Fat (g)', value: 'fat' },
  187.       { text: 'Carbs (g)', value: 'carbs' },
  188.       { text: 'Protein (g)', value: 'protein' },
  189.       { text: 'Actions', value: 'name', sortable: false }
  190.     ],
  191.     desserts: [],
  192.     editedIndex: -1,
  193.     editedItem: {
  194.       name: '',
  195.       calories: '',
  196.       fat: '',
  197.       carbs: '',
  198.       protein: ''
  199.     },
  200.     defaultItem: {
  201.       name: '',
  202.       calories: '',
  203.       fat: '',
  204.       carbs: '',
  205.       protein: ''
  206.     }
  207.   }),
  208.   computed: {
  209.     formTitle () {
  210.       return this.editedIndex === -1 ? 'Новые данные пользователя' : 'Редактировать данные пользователя'
  211.     }
  212.   },
  213.   watch: {
  214.     dialog (val) {
  215.       val || this.close()
  216.     }
  217.   },
  218.   created () {
  219.     this.initialize()
  220.   },
  221.   methods: {
  222.     initialize () {
  223.       this.desserts = []
  224.     },
  225.     editItem (item) {
  226.       this.editedIndex = this.desserts.indexOf(item)
  227.       this.editedItem = Object.assign({}, item)
  228.       this.dialog = true
  229.     },
  230.     deleteItem (item) {
  231.       const index = this.desserts.indexOf(item)
  232.       confirm('Вы точно уверены, что хотите удалить данные пользователя?') && this.desserts.splice(index, 1)
  233.     },
  234.     close () {
  235.       this.dialog = false
  236.       setTimeout(() => {
  237.         this.editedItem = Object.assign({}, this.defaultItem)
  238.         this.editedIndex = -1
  239.       }, 300)
  240.     },
  241.     save () {
  242.       if (this.editedIndex > -1) {
  243.         Object.assign(this.desserts[this.editedIndex], this.editedItem)
  244.       } else {
  245.         this.desserts.push(this.editedItem)
  246.       }
  247.       this.close()
  248.     }
  249.   }
  250. };
  251. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement