質問編集履歴

1

改修対象のソースについて修正

2020/08/08 03:47

投稿

kyoto-taichi
kyoto-taichi

スコア10

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,7 @@
158
158
 
159
159
 
160
160
 
161
- ```ここに言語を入力
161
+ ```Vue.js コンポーネント
162
162
 
163
163
  <template>
164
164
 
@@ -166,97 +166,91 @@
166
166
 
167
167
  <h2>ここで合計金額を表示したい!!</h2>
168
168
 
169
- <div class="row justify-content-center">
170
-
171
- <div class="col-sm-6">
172
-
173
- <form v-on:submit.prevent="submit">
174
-
175
- <div class="form-group row">
176
-
177
- <label for="year" class="col-sm-3 col-form-label">Year</label>
178
-
179
- <input type="text" class="col-sm-9 form-control" id="year" v-model="cost.year" />
180
-
181
- </div>
182
-
183
- <div class="form-group row">
184
-
185
- <label for="month" class="col-sm-3 col-form-label">Month</label>
186
-
187
- <input type="text" class="col-sm-9 form-control" id="month" v-model="cost.month" />
188
-
189
- </div>
190
-
191
- <div class="form-group row">
192
-
193
- <label for="day" class="col-sm-3 col-form-label">Day</label>
194
-
195
- <input type="text" class="col-sm-9 form-control" id="day" v-model="cost.day" />
196
-
197
- </div>
198
-
199
- <div class="form-group row">
200
-
201
- <label for="account-name" class="col-sm-3 col-form-label">Account</label>
202
-
203
- <select class="col-sm-9 form-control" id="account" v-model="cost.accountName">
204
-
205
- <option
206
-
207
- v-for="(account, index) in accounts"
208
-
209
- :key="index"
210
-
211
- v-bind:value="account.accountKanji"
212
-
213
- >{{ account.accountKanji }}</option>
214
-
215
- </select>
216
-
217
- </div>
218
-
219
- <div class="form-group row">
220
-
221
- <label for="price" class="col-sm-3 col-form-label">Price</label>
222
-
223
- <input type="text" class="col-sm-9 form-control" id="price" v-model="cost.price" />
224
-
225
- </div>
226
-
227
- <div class="form-group row">
228
-
229
- <label for="journal" class="col-sm-3 col-form-label">Journal</label>
230
-
231
- <input type="text" class="col-sm-9 form-control" id="journal" v-model="cost.journal" />
232
-
233
- </div>
234
-
235
- <button type="submit" class="btn btn-primary">Submit</button>
236
-
237
- </form>
238
-
239
- </div>
240
-
241
- </div>
169
+ <table class="table table-hover">
170
+
171
+ <thead class="thead-light">
172
+
173
+ <tr>
174
+
175
+ <th scope="col">id</th>
176
+
177
+ <th scope="col">account</th>
178
+
179
+ <th scope="col">price</th>
180
+
181
+ <th scope="col">journal</th>
182
+
183
+ <th scope="col">year</th>
184
+
185
+ <th scope="col">month</th>
186
+
187
+ <th scope="col">day</th>
188
+
189
+ <th scope="col">Watch</th>
190
+
191
+ </tr>
192
+
193
+ </thead>
194
+
195
+ <tbody>
196
+
197
+ <tr v-for="(cost, index) in costs" :key="index">
198
+
199
+ <th scope="row">{{ cost.id }}</th>
200
+
201
+ <td>{{ cost.accountName }}</td>
202
+
203
+ <td>{{ cost.price }}</td>
204
+
205
+ <td>{{ cost.journal }}</td>
206
+
207
+ <td>{{ cost.year }}</td>
208
+
209
+ <td>{{ cost.month }}</td>
210
+
211
+ <td>{{ cost.day }}</td>
212
+
213
+ <td>
214
+
215
+ <router-link v-bind:to="{name: 'cost.detail', params: { costId: cost.id } }">
216
+
217
+ <button class="btn btn-primary">Watch</button>
218
+
219
+ </router-link>
220
+
221
+ </td>
222
+
223
+ </tr>
224
+
225
+ </tbody>
226
+
227
+ </table>
242
228
 
243
229
  </div>
244
230
 
245
231
  </template>
246
232
 
247
-
248
-
249
233
  <script>
250
234
 
251
235
  export default {
252
236
 
237
+ props: {
238
+
239
+ year: Number,
240
+
241
+ month: Number,
242
+
243
+ day: Number,
244
+
245
+ },
246
+
253
247
  data: function () {
254
248
 
255
249
  return {
256
250
 
257
- cost: {},
251
+ costs: [],
258
-
252
+
259
- accounts: [],
253
+ totalAmount: 0,
260
254
 
261
255
  };
262
256
 
@@ -264,45 +258,51 @@
264
258
 
265
259
  methods: {
266
260
 
267
- submit() {
261
+ getCostData() {
262
+
268
-
263
+ if (this.day === undefined) {
264
+
265
+ axios
266
+
269
- axios.post("/api/cost/store", this.cost).then((res) => {
267
+ .get("/api/cost/list/" + this.year + "/" + this.month)
268
+
270
-
269
+ .then((res) => {
270
+
271
- this.$router.push({ name: "cost.rec-done" });
271
+ this.costs = res.data;
272
-
272
+
273
- });
273
+ });
274
+
275
+ } else {
276
+
277
+ axios
278
+
279
+ .get(
280
+
281
+ "/api/cost/list/" + this.year + "/" + this.month + "/" + this.day
282
+
283
+ )
284
+
285
+ .then((res) => {
286
+
287
+ this.costs = res.data;
288
+
289
+ });
290
+
291
+ }
292
+
293
+ for (var item in this.costs) {
294
+
295
+ totalAmount += this.costs[item]["price"];
296
+
297
+ }
274
298
 
275
299
  },
276
300
 
277
- fillDateInfo() {
278
-
279
- var now = new Date();
280
-
281
- this.cost.year = now.getFullYear();
282
-
283
- this.cost.month = now.getMonth() + 1;
284
-
285
- this.cost.day = now.getDate();
286
-
287
- },
288
-
289
- getAccountList() {
290
-
291
- axios.get("/api/account/list").then((res) => {
292
-
293
- this.accounts = res.data;
294
-
295
- });
296
-
297
- },
298
-
299
301
  },
300
302
 
301
303
  mounted() {
302
304
 
303
- this.getAccountList();
305
+ this.getCostData();
304
-
305
- this.fillDateInfo();
306
306
 
307
307
  },
308
308
 
@@ -312,4 +312,6 @@
312
312
 
313
313
 
314
314
 
315
+
316
+
315
317
  ```