<template>
    <el-dialog title="订单详情" :visible.sync="dialogVisible" width="50%" top="7vh" v-loading="loading"
        :destroy-on-close="true">
        <el-form :model="form" :label-position="formLabelWidth" label-width="120px" size="mini"
            style="max-height: 66vh; overflow-y: scroll;">
            <el-form-item label="下单时间">
                <el-input v-model="form.paidAt" disabled></el-input>
            </el-form-item>
            <el-form-item label="订单编号">
                <el-input v-model="form.orderNo" disabled></el-input>
            </el-form-item>
            <el-form-item label="订单金额">
                <el-input v-model="form.totalFee" disabled></el-input>
            </el-form-item>
            <el-form-item label="订单状态">
                <el-input v-model="form.status" disabled></el-input>
            </el-form-item>
            <el-form-item label="收件人信息">
                <BaseTable :columns='columns1' :condition='[]' ref="table1" :injectData="[form]" size="small">
                </BaseTable>
            </el-form-item>
            <el-form-item label="商品信息">
                <BaseTable :columns='columns2' :condition='[]' ref="table2" :injectData="form.orderItems" size="small">
                </BaseTable>
            </el-form-item>
            <el-form-item label="备注">
                <el-input v-model="form.remark" type="textarea" disabled></el-input>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import BaseTable from "./order-BaseTable.vue"
import moment from 'moment'
export default {
    name: 'showDialog',
    components: { BaseTable, },
    data() {
        return {
            dialogVisible: false,
            loading: true,
            columns1: [{
                title: "姓名",
                dataIndex: "addressName",
            }, {
                title: "电话",
                dataIndex: "addressPhone",
            }, {
                title: "地址",
                dataIndex: "addressText",
            },],
            columns2: [{
                title: "图标",
                dataIndex: "goodsCover",
                scopedSlots: { customRender: (label, row, index) => `${row.goodsCover}` },
            }, {
                title: "名称",
                dataIndex: "goodsName",
            }, {
                title: "价格",
                dataIndex: "goodsPrice",
            }, {
                title: "数量",
                dataIndex: "goodsAmount",
            }, {
                title: "小计",
                dataIndex: "totalPrice",
            }],
            form: {
                paidAt: "",
                orderNo: '',
                totalFee: 0,
                status: '',
                addressName: '',
                addressPhone: '',
                addressText: '',
                remark: '',
                orderItems: []
            },
            formLabelWidth: '120px'
        };
    },
    methods: {
        show({ id }) {
            this.$http({
                url: '/orderItem/show',
                method: 'post',
                data: { id },
                params: { id }
            }).then(
                ({ data }) => {
                    // this.form
                    // this.$set(this.form,)
                    Object.keys(this.form).forEach(key => {
                        this.form[key] = data[key]
                    })
                    this.form.paidAt = moment(this.form.paidAt).format("yyyy-MM-DD HH:mm:ss")
                    this.loading = false
                }
            )
            this.dialogVisible = true;
        }
    }
}
</script>