<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container >
            <a-form-model ref="form" :model="model" slot="detail">
                <a-row>
                    <a-col :span="24">
                        <a-form-model-item :label="maxMoney > 0 ?'应收金额':'应退金额'" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
                            <a-input-number disabled
                                            v-model="Math.abs(maxMoney)"
                                            style="width: 30%"
                            />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentMethod">
                            <a-select
                                    v-model="model.paymentMethod"
                                    style="width: 30%"
                                    placeholder="支付方式" >
                                <a-select-option
                                        v-for="(item, index) in paymentMethodList"
                                        :key="index"
                                        :value="item.id"
                                >{{ item.name }}</a-select-option>
                            </a-select>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="支付金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
                            <a-input-number
                                    v-model="model.price"
                                    placeholder="请输入金额"
                                    :min="0"
                                    style="width: 30%"
                            />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remarks">
                            <a-textarea
                                    v-model="model.remarks"
                                    rows="4"
                                    placeholder="请输入备注"
                            />
                        </a-form-model-item>
                    </a-col>

                </a-row>
            </a-form-model>
        </j-form-container>
        <!--        <a-row>-->
        <!--            <a-col :span="8" :offset="3">-->
        <!--                <a-button @click="handleSubmit" type="primary" >确认</a-button>-->
        <!--            </a-col>-->
        <!--        </a-row>-->

    </a-spin>
</template>

<script>
    import { httpAction, getAction } from "@/api/manage";

    export default {
        name: 'settlementForm',
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            },
            agreementModel:{
                type: Object,
                required: false,
                default: () => {
                }
            },
            maxMoney: {
                type: Number,
                default: 200,
                required: false
            },
            orderIds: {
                type: String,
                default: 200,
                required: false
            }
        },
        data () {
            return {
                confirmLoading: false,
                model: {},
                labelCol: {
                    xs: { span: 24 },
                    sm: { span: 3 },
                },
                wrapperCol: {
                    xs: { span: 24 },
                    sm: { span: 18 },
                },
                paymentMethodList: [],
                url: {
                    list: "/rooms/cesGoods/queryList",
                    updateStatusBatch: "/business/busAgreementOrderFee/updateStatusBatch",
                },
            }
        },
        created() {
            httpAction(
                "/business/busRoomPayType/queryList",
                { pageNo: 1, pageSize: 100 },
                "get"
            ).then((res) => {
                if (res.success) {
                    this.paymentMethodList = res.result;
                }
            });
        },
        methods:{
            edit() {
                // console.log(record)
                // this.model = Object.assign({}, record);
                // this.changeColumns(this.model.roomType, this.model.fixedDiscount)
                // this.visible = true;
            },
            submitForm(){
                console.log(this.$parent)
                const that = this;
                if(this.model.price != Math.abs(this.maxMoney)){
                    that.$message.warning("支付金额应等于应收/应退金额");
                    return;
                }
                that.confirmLoading = true;
                let httpurl = this.url.updateStatusBatch;
                let method = 'post';

                var order = {
                    agreementUnitId:that.agreementModel.id,
                    projectName:that.maxMoney >=0?"结算收款":"结算退款",
                    type:5,
                    payPrice:that.maxMoney,
                    payType:that.model.paymentMethod,
                    remarks:that.model.remarks,
                }
                var data = {
                    busAgreementOrderFee:order,
                    orderIds:that.orderIds
                }
                console.log(data);
                httpAction(httpurl,data,method).then((res)=>{
                    if(res.success){
                        that.$message.success(res.message);
                        that.$emit('ok');
                    }else{
                        that.$message.warning(res.message);
                    }
                }).finally(() => {
                    that.confirmLoading = false;
                })
            },
        }
    }
</script>

<style scoped>

</style>
