<template>
    <div class="edit-view__content-wrapper">
        <div class="edit-view__content-section">
            <divider />
            <el-form
                :model="formData"
                :rules="rules"
                ref="form"
                label-width="10vw"
                label-position="right"
                size="small"
                style="max-width: calc(400px + 20vw); margin: 0 auto; padding-right: 10vw;"
                inline
            >
                <el-form-item prop="name" label="商标logo">
                    <el-input v-model="formData.name" style="width: calc(400px + 10vw);" @change="submit"></el-input>
                </el-form-item>

                <el-form-item prop="applyStatus" label="案件状态">
                    <el-select disabled v-model="formData.applyStatus" clearable filterable placeholder="请选择">
                        <el-option
                            v-for="item in applyStatusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>

                <el-form-item prop="supplierPartnerId" label="供应商">
                    <el-select v-model="formData.supplierPartnerId" filterable placeholder="请选择" @change="submit">
                        <el-option
                            v-for="item in supplierPartnerIdOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop="uwNo" label="寰球案号">
                    <el-input disabled v-model="formData.uwNo"></el-input>
                </el-form-item>
                <el-form-item prop="clientPartnerId" label="客户">
                    <el-select v-model="formData.clientPartnerId" filterable placeholder="请选择" @change="submit">
                        <el-option
                            v-for="item in clientPartnerIdOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item prop="applyNo" label="商标申请号">
                    <el-input v-model="formData.applyNo" @change="submit"></el-input>
                </el-form-item>
                <el-form-item prop="applyDate" label="商标申请日" @change="submit">
                    <el-date-picker
                        v-model="formData.applyDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期"
                    >
                    </el-date-picker>
                </el-form-item>
                <el-form-item prop="payRatio" label="支付比例">
                    <el-select v-model="formData.payRatio" placeholder="请选择" @change="submit">
                        <el-option
                            v-for="item in payRatioOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        >
                        </el-option>
                    </el-select>
                </el-form-item>
                <!-- <el-form-item class="form-submit" style="width: calc(400px + 30vw); text-align: center;">
                    <el-button @click="onSave" :loading="saving" size="default" type="primary">保存 </el-button>
                    <el-button @click="onDelete" :loading="saving" size="default" type="danger" v-if="formData.id"
                        >删除
                    </el-button>
                    <el-button @click="$router.go(-1)" size="default">取消</el-button>
                </el-form-item> -->
            </el-form>
        </div>
    </div>
</template>
<script>
import logoPatent from '@/mixins/logoPatent';
export default {
    name: 'LogoPatentEdit',
    mixins: [logoPatent],
    props: {
        info: {
            type: Object,
            default: () => {
                return {};
            }
        }
    },
    created() {
        this.$http
            .post('/partner/all', { size: 1000, query: { del: false } }, { body: 'json' })
            .then(res => {
                if (res.content.length > 0) {
                    this.clientPartnerIdOptions = res.content
                        .filter(item => {
                            return item.type === 'CLIENT';
                        })
                        .map(item => {
                            return {
                                label: item.name,
                                value: item.id
                            };
                        });
                    this.supplierPartnerIdOptions = res.content
                        .filter(item => {
                            return item.type === 'SUPPLIER';
                        })
                        .map(item => {
                            return {
                                label: item.name,
                                value: item.id
                            };
                        });
                }
            })
            .catch(e => {
                console.log(e);
                this.$message.error(e.error);
            });
    },
    data() {
        return {
            saving: false,
            formData: {},
            rules: {},
            clientPartnerIdOptions: [],
            supplierPartnerIdOptions: []
        };
    },
    methods: {
        init() {
            this.formData = this.info;
        },
        onSave() {
            this.$refs.form.validate(valid => {
                if (valid) {
                    this.submit();
                } else {
                    return false;
                }
            });
        },
        submit() {
            this.$emit('submit', this.formData);
            // let data = { ...this.formData };

            // this.saving = true;
            // this.$http
            //     .post('/logoPatent/save', data, { body: 'json' })
            //     .then(res => {
            //         this.saving = false;
            //         this.$message.success('成功');
            //         // this.$router.go(-1);

            //         this.$emit('getInfo')
            //     })
            //     .catch(e => {
            //         console.log(e);
            //         this.saving = false;
            //         this.$message.error(e.error);
            //     });
        },
        onDelete() {
            this.$alert('删除将无法恢复，确认要删除么？', '警告', { type: 'error' })
                .then(() => {
                    return this.$http.post(`/logoPatent/del/${this.formData.id}`);
                })
                .then(() => {
                    this.$message.success('删除成功');
                    this.$router.go(-1);
                })
                .catch(e => {
                    if (e !== 'cancel') {
                        console.log(e);
                        this.$message.error((e || {}).error || '删除失败');
                    }
                });
        }
    }
};
</script>
<style lang="less" scoped></style>
