<style lang="less">

</style>

<template>
    <div>
        <Row>
            <Col span="18">
                <Card>
                    <Form :label-width="80">
                        <FormItem label="项目">
                            <Input v-model="form.appliances" icon="android-list"/>
                        </FormItem>
                        <FormItem label="服务地址">
                            <Input v-model="form.address" icon="android-list"/>
                        </FormItem>
                        <FormItem label="联系人">
                            <Input v-model="form.contact" icon="android-list"/>
                        </FormItem>
                        <FormItem label="联系电话">
                            <Input v-model="form.phone" icon="android-list"/>
                        </FormItem>
                        <FormItem label="订单价格">
                            <Input v-model="form.price" icon="android-list"/>
                        </FormItem>
                        <FormItem label="订单状态">
                            <Select v-model="form.status" style="width: 150px">
                                <Option :value="0">待处理</Option>
                                <Option :value="1">商家受理</Option>
                                <Option :value="2">待支付</Option>
                                <Option :value="3">已支付</Option>
                            </Select>
                        </FormItem>
                    </Form>
                    <div class="submit">
                        <Button @click="handlePublish" :loading="publishLoading" icon="ios-checkmark" size="large" type="primary">发布</Button>
                    </div>
                </Card>
            </Col>
        </Row>
    </div>
</template>

<script>
import tinymce from 'tinymce';
import editor from '../main-components/editor'
export default {
    name: 'edit',
    components: {
        editor
    },
    props: {
        formContent: Object
    },
    watch: {
        formContent() {
            if (!this.formContent.status) {
                this.formContent.status = 0;
            }
            this.form = this.formContent;
        }
    },
    data () {
        return {
            form: this.formContent,
            publishLoading: false
        };
    },
    methods: {
        handlePublish() {
            if (true) {
                this.publishLoading = true;
                let data = {
                    appliances: this.form.appliances,
                    address: this.form.address,
                    contact: this.form.contact,
                    phone: this.form.phone,
                    price: parseFloat(this.form.price),
                    status: this.form.status
                };
                if (this.form.id) {
                    data.id = this.form.id;
                }
                this.axios.post("/house_appliance_clean_order/store", data).then((res) => {
                    if (res.data.status == 0) {
                        this.$Message.success('操作成功！');
                        this.publishLoading = false;
                        setTimeout(() => {
                            this.$emit("pub-success");
                        }, 1000);
                    }
                });
            } else {
                this.$Message.error('请完善所有信息！');
                this.publishLoading = false;
            }
        }
    }
};
</script>
