create-modal.vue
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<template>
<Modal v-model="model"
width="400"
class-name="vertical-center-modal create-invoice-modal">
<p slot="header">
新建发货单
</p>
<div class="create-invoice-modal-content">
<Form label-position="left" :label-width="100">
<Form-item label="到货仓库">
<select-room v-model="storageId"></select-room>
</Form-item>
<Form-item label="预计到货时间">
<date-pick v-model="createDate"></date-pick>
</Form-item>
<Form-item label="品牌">
<select-brand v-model="brandId" :selectWhenOnlyOne="true"></select-brand>
</Form-item>
</Form>
</div>
<div slot="footer" style="text-align: center">
<Button type="primary" size="large" :loading="modal_loading" @click="submit">保存</Button>
<Button type="primary" size="large" :loading="modal_loading" @click="submitAnd">保存并添加商品</Button>
<Button type="ghost" size="large" @click="cancel">取消</Button>
</div>
</Modal>
</template>
<script>
import InvoiceService from 'services/repository/invoice-service';
import DatePick from './date-pick';
import moment from 'moment';
export default {
name: 'create-modal',
created() {
this.invoiceService = new InvoiceService();
},
data() {
return {
model: false,
modal_loading: false,
storageId: null,
createDate: null,
brandId: null
};
},
computed: {
handleDate() {
return moment(this.createDate, 'YYYY-MM-DD').unix();
}
},
methods: {
show() {
this.reset();
this.model = true;
},
close() {
this.model = false;
},
submit() {
this.save().then((result) => {
if (result.code === 200) {
this.close();
this.emitEvent();
}
}).catch((err) => {
this.$Message.error(err);
});
},
submitAnd() {
this.save().then((result) => {
if (result.code === 200) {
this.close();
this.emitEvent();
this.$router.push({
name: 'repository.invoice.edit',
params: {
id: result.data
},
query: {
brandId: this.brandId
}
});
}
}).catch((err) => {
this.$Message.error(err);
});
},
cancel() {
this.close();
},
reset() {
this.modal_loading = false;
},
save() {
if (!this.storageId) {
return Promise.reject('请选择到货仓库');
}
if (!this.createDate) {
return Promise.reject('设置预计到货时间');
}
if (!this.brandId) {
this.$Message.error();
return Promise.reject('请选择品牌');
}
this.modal_loading = true;
return this.invoiceService.createOrder(this.storageId, this.handleDate, this.brandId).then((result) => {
if (result.code === 200) {
this.$Message.info('创建成功');
} else {
this.$Message.error('创建失败');
}
return result;
});
},
emitEvent() {
this.$emit('on-success');
}
},
components: {
DatePick
}
};
</script>
<style lang="scss">
.create-invoice-modal {
.ivu-date-picker {
width: 100%;
}
.create-invoice-modal-content {
padding: 20px;
}
}
.vertical-center-modal {
display: flex;
align-items: center;
justify-content: center;
.ivu-modal {
top: 0;
}
}
.spin-container {
width: 1033px;
height: 200px;
position: relative;
}
.table-container {
width: 1033px;
min-height: 200px;
}
</style>