view(Purchase): add client list from requesta as example.
This commit is contained in:
		@@ -21,19 +21,24 @@
 | 
				
			|||||||
          :rules="[rules.required]"
 | 
					          :rules="[rules.required]"
 | 
				
			||||||
          required
 | 
					          required
 | 
				
			||||||
        ></v-text-field>
 | 
					        ></v-text-field>
 | 
				
			||||||
        <v-text-field
 | 
					        <v-select
 | 
				
			||||||
          v-model="purchase.client"
 | 
					          v-model="purchase.client"
 | 
				
			||||||
 | 
					          :items="clients"
 | 
				
			||||||
          label="Cliente"
 | 
					          label="Cliente"
 | 
				
			||||||
          :rules="[rules.required]"
 | 
					          :rules="[rules.required]"
 | 
				
			||||||
          required
 | 
					          required
 | 
				
			||||||
        ></v-text-field>
 | 
					          item-text="name"
 | 
				
			||||||
 | 
					          item-value="id"
 | 
				
			||||||
 | 
					        ></v-select>
 | 
				
			||||||
        <v-textarea
 | 
					        <v-textarea
 | 
				
			||||||
          v-model="purchase.notes"
 | 
					          v-model="purchase.notes"
 | 
				
			||||||
          label="Notas"
 | 
					          label="Notas"
 | 
				
			||||||
        ></v-textarea>
 | 
					        ></v-textarea>
 | 
				
			||||||
        <v-divider></v-divider>
 | 
					        <v-divider></v-divider>
 | 
				
			||||||
 | 
					        <v-container>
 | 
				
			||||||
        <v-subheader>Productos</v-subheader>
 | 
					          <v-toolbar>
 | 
				
			||||||
 | 
					          <v-toolbar-title secondary>Productos</v-toolbar-title>
 | 
				
			||||||
 | 
					        </v-toolbar>
 | 
				
			||||||
        <div v-for="(line, index) in purchase.lines" :key="line.id">
 | 
					        <div v-for="(line, index) in purchase.lines" :key="line.id">
 | 
				
			||||||
          <v-row>
 | 
					          <v-row>
 | 
				
			||||||
            <v-col>
 | 
					            <v-col>
 | 
				
			||||||
@@ -53,7 +58,7 @@
 | 
				
			|||||||
                required
 | 
					                required
 | 
				
			||||||
              ></v-text-field>
 | 
					              ></v-text-field>
 | 
				
			||||||
            </v-col>
 | 
					            </v-col>
 | 
				
			||||||
            <v-col>
 | 
					n            <v-col>
 | 
				
			||||||
              <v-text-field
 | 
					              <v-text-field
 | 
				
			||||||
                v-model.number="line.quantity"
 | 
					                v-model.number="line.quantity"
 | 
				
			||||||
                label="Cantidad"
 | 
					                label="Cantidad"
 | 
				
			||||||
@@ -76,6 +81,8 @@
 | 
				
			|||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <v-btn @click="addLine" color="blue">Agregar</v-btn>
 | 
					        <v-btn @click="addLine" color="blue">Agregar</v-btn>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      </v-container>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <v-divider></v-divider>
 | 
					        <v-divider></v-divider>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <v-text-field
 | 
					        <v-text-field
 | 
				
			||||||
@@ -101,7 +108,7 @@
 | 
				
			|||||||
        valid: false,
 | 
					        valid: false,
 | 
				
			||||||
        purchase: {
 | 
					        purchase: {
 | 
				
			||||||
          date: '',
 | 
					          date: '',
 | 
				
			||||||
          client: '',
 | 
					          client: null,
 | 
				
			||||||
          notes: '',
 | 
					          notes: '',
 | 
				
			||||||
          lines: [{product:'', price: 0, quantity: 0}],
 | 
					          lines: [{product:'', price: 0, quantity: 0}],
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
@@ -112,8 +119,12 @@
 | 
				
			|||||||
          { title: 'Inicio', route: '/'},
 | 
					          { title: 'Inicio', route: '/'},
 | 
				
			||||||
          { title: 'Compras', route:'/compras'},
 | 
					          { title: 'Compras', route:'/compras'},
 | 
				
			||||||
        ],
 | 
					        ],
 | 
				
			||||||
 | 
					        clients: [],
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 | 
					    created() {
 | 
				
			||||||
 | 
					      this.fetchClients();
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
    computed: {
 | 
					    computed: {
 | 
				
			||||||
      calculateTotal() {
 | 
					      calculateTotal() {
 | 
				
			||||||
        return this.purchase.lines.reduce((total, line) => {
 | 
					        return this.purchase.lines.reduce((total, line) => {
 | 
				
			||||||
@@ -122,6 +133,16 @@
 | 
				
			|||||||
      },
 | 
					      },
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    methods: {
 | 
					    methods: {
 | 
				
			||||||
 | 
					      fetchClients() {
 | 
				
			||||||
 | 
					        fetch('/don_confiao/api/customers/')
 | 
				
			||||||
 | 
					          .then(response => response.json())
 | 
				
			||||||
 | 
					          .then(data => {
 | 
				
			||||||
 | 
					            this.clients = data.map(client => client.name);
 | 
				
			||||||
 | 
					          })
 | 
				
			||||||
 | 
					          .catch(error => {
 | 
				
			||||||
 | 
					            console.error(error);
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					      },
 | 
				
			||||||
      addLine() {
 | 
					      addLine() {
 | 
				
			||||||
        this.purchase.lines.push({ product: '', price: 0, quantity:0 });
 | 
					        this.purchase.lines.push({ product: '', price: 0, quantity:0 });
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user