<template>
    <div class="edit-view">
        <el-form :model="formData" :rules="rules" ref="form" label-width="108px" label-position="right" size="small"
                 style="max-width: 500px;">
            <el-form-item prop="nickname" label="用户信息">
                <!--<el-card shadow="hover">
                    <div class="">{{formData.nickname}}</div>
                    <div class="text item">{{address.name}} {{address.phone}}</div>
                    <div class="text item">{{address.info}}</div>
                </el-card>-->

                <el-input v-model="formData.nickname"></el-input>
            </el-form-item>
            <el-form-item prop="userAddress" label="配送地址">
                <el-input v-model="address.name" style="width: 100px;padding-right: 10px"></el-input>
                <el-input v-model="address.phone" style="width: 150px"></el-input>
                <el-input type="textarea" v-model="address.info" style="padding-top: 10px"></el-input>
            </el-form-item>
            <el-form-item prop="merchantShowName" label="商户">
                <el-input v-model="formData.merchantShowName"></el-input>
            </el-form-item>
            <el-form-item prop="merchantStatus" label="商家状态">
                <!--<el-select v-model="formData.merchantStatus" disabled placeholder="请选择">
                    <el-option
                            v-for="item in merchantStatusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>-->
                <el-steps :active="number" >
                    <el-step  title="未接单/已拒单" ></el-step>
                    <el-step  title="已接单" ></el-step>
                    <el-step title="已完成" ></el-step>
                </el-steps>
            </el-form-item>
            <!--            <el-form-item prop="merchantAddress" label="商家地址">-->
            <!--                <el-input v-model="formData.merchantAddress"></el-input>-->
            <!--            </el-form-item>-->
            <el-form-item prop="riderName" label="骑手">
                <el-input v-model="formData.riderName"></el-input>
                <!--<el-button type="primary" @click="changeStatus">{{formData.riderStatus}}</el-button>-->
            </el-form-item>
            <el-form-item prop="jobNumber" label="骑手工号">
                <el-input v-model="formData.jobNumber"></el-input>
                <!--<el-button type="primary" @click="changeStatus">{{formData.riderStatus}}</el-button>-->
            </el-form-item>

            <!--      <el-form-item prop="riderStatus" label="骑手状态">
                      <el-input v-model="formData.riderStatus"></el-input>
                  </el-form-item>-->
            <el-form-item prop="riderStatus" label="骑手状态">
                <!--<el-select v-model="formData.riderStatus" disabled placeholder="请选择">
                    <el-option
                            v-for="item in riderStatusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>-->
                <el-steps :active="riderNumber" >
                    <el-step v-for="item in riderStatusOptions" :key="item.value" :title="item.label" ></el-step>
                </el-steps>
            </el-form-item>
            <el-form-item prop="totalAmount" label="总价">
                <el-input v-model="formData.totalAmount" readonly></el-input>
            </el-form-item>
            <!--            <el-form-item prop="goodsAmount" label="商品总价">-->
            <!--                <el-input-number type="number" v-model="formData.goodsAmount"></el-input-number>-->
            <!--            </el-form-item>-->
            <el-form-item prop="deliveryAmount" label="配送费">
                <el-input v-model="formData.deliveryAmount" readonly></el-input>
            </el-form-item>
            <el-form-item prop="realAmount" label="实付金额">
                <el-input v-model="formData.realAmount" readonly></el-input>
            </el-form-item>
            <el-form-item prop="payMethod" label="支付方式">
                <el-select v-model="formData.payMethod" disabled placeholder="请选择">
                    <el-option
                            v-for="item in payMethodOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item prop="cancel" label="取消订单">
                <el-switch v-model="formData.cancel"></el-switch>
            </el-form-item>
            <el-form-item prop="rated" label="已评价">
                <el-switch v-model="formData.rated"></el-switch>
            </el-form-item>
            <el-form-item prop="orderTime" label="下单时间">
                <el-date-picker
                        readonly
                        v-model="formData.orderTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <!--            <el-form-item prop="merchantOrderTime" label="商家接单时间">-->
            <!--                <el-date-picker-->
            <!--                        v-model="formData.merchantOrderTime"-->
            <!--                        type="datetime"-->
            <!--                        value-format="yyyy-MM-dd HH:mm:ss"-->
            <!--                        placeholder="选择日期时间">-->
            <!--                </el-date-picker>-->
            <!--            </el-form-item>-->
            <!--            <el-form-item prop="riderOrderTime" label="骑手接单时间">-->
            <!--                <el-date-picker-->
            <!--                        v-model="formData.riderOrderTime"-->
            <!--                        type="datetime"-->
            <!--                        value-format="yyyy-MM-dd HH:mm:ss"-->
            <!--                        placeholder="选择日期时间">-->
            <!--                </el-date-picker>-->
            <!--            </el-form-item>-->
            <el-form-item prop="userReceivedTime" label="用户收到时间">
                <el-date-picker
                        readonly
                        v-model="formData.userReceivedTime"
                        type="datetime"
                        value-format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <!--            <el-form-item prop="isCoupon" label="使用优惠券">-->
            <!--                <el-switch v-model="formData.isCoupon"></el-switch>-->
            <!--            </el-form-item>-->
            <el-form-item prop="goods" label="商品详情">
                <template v-if="goods">
                    <el-card shadow="never">
                        <el-table :data="goods">
                            <!--<el-table-column prop="goodsId" label="商品ID">
                            </el-table-column>-->
                            <el-table-column prop="goods.name" label="商品名称" min-width="110px"></el-table-column>
                            <el-table-column prop="num" label="数量" width="60px">
                            </el-table-column>
                            <el-table-column prop="specification" label="规格">
                            </el-table-column>
                            <el-table-column prop="goodsPrice" label="价格">
                            </el-table-column>
                        </el-table>
                    </el-card>
                </template>
            </el-form-item>

            <el-form-item>
                <!--<el-button @click="onSave" :loading="saving"
                           type="primary">保存
                </el-button>
                <el-button @click="onDelete" :loading="saving"
                           type="danger" v-if="formData.id">删除
                </el-button>-->
                <el-button @click="appraisal" v-if="formData.rated"
                           type="primary">评价
                </el-button>
                <el-button @click="$router.go(-1)">返回</el-button>
            </el-form-item>


        </el-form>
    </div>
</template>
<script>
    export default {
        name: 'OrderInfoEdit',
        created() {
            if (this.$route.query.id) {
                this.$http
                    .get('orderInfo/get/' + this.$route.query.id)
                    .then(res => {
                        this.formData = res;
                        this.active();
                    })
                    .catch(e => {
                        console.log(e);
                        this.$message.error(e.error);
                    });

                this.$http
                    .get('/orderGoodsSpec/byOrder',
                        {
                            orderId: this.$route.query.id
                        }
                    )
                    .then(res => {
                        this.goods = res;
                    })
                    .catch(e => {
                        console.log(e);
                    });
            }
        },
        data() {
            return {
                saving: false,
                formData: {},
                rules: {},
                riderStatusOptions: [
                    {"label": "未接单", "value": "NOT_RECEIVED"},
                    {"label": "接单中", "value": "RECEIVED"},
                    {"label": "取餐中", "value": "TAKE_MEAL"},
                    {"label": "送餐中", "value": "MEAL_DELIVERY"},
                    {"label": "完成", "value": "CARRY_OUT"}],
                payMethodOptions: [
                    {"label": "支付宝", "value": "ALI_PAY"},
                    {"label": "货到付款", "value": "CASH_DELIVERY"},
                    {"label": "信用卡", "value": "CREDIT_CARD"}],
                merchantStatusOptions: [
                    {"label": "已完成", "value": "CARRY_OUT"},
                    {"label": "接单", "value": "RECEIVED"},
                    {"label": "未接单", "value": "NOT_RECEIVED"},
                    {"label": "已拒单", "value": "REJECTED"}],
                goods: [],
                address: {
                    name: "",
                    phone: "",
                    info: "",
                },
                number: 1,
                riderNumber: 1,
            }
        },
        methods: {
            onSave() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        this.submit();
                    } else {
                        return false;
                    }
                });
            },
            submit() {
                let data = {...this.formData};

                this.saving = true;
                this.$http
                    .post('/orderInfo/save', data, {body: 'json'})
                    .then(res => {
                        this.saving = false;
                        this.$message.success('成功');
                        this.$router.go(-1);
                    })
                    .catch(e => {
                        console.log(e);
                        this.saving = false;
                        this.$message.error(e.error);
                    });
            },
            onDelete() {
                this.$alert('删除将无法恢复，确认要删除么？', '警告', {type: 'error'}).then(() => {
                    return this.$http.post(`/orderInfo/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);
                    }
                })
            },
            changeStatus() {
                this.$alert('确认此状态已完成？', '提示').then(() => {
                    return this.$http.post("/orderInfo/riderStatus", {
                        orderId: this.formData.id,
                        pass: true
                    })
                }).then(() => {
                    this.$message.success('状态已改');
                    this.$router.go(0);
                    //this.$router.go(-1);
                }).catch(e => {
                    if (e !== 'cancel') {
                        console.log(e);
                        this.$message.error(e.error);
                    }
                })
            },
            appraisal() {
                this.$router.push({
                    path: "/appraisalEdit",
                    query: {
                        id: this.formData.appraisalId
                    }
                });
            },
            active(){
                let add = this.formData.userAddress.split(",");
                this.address.name = add[0];
                this.address.phone = add[1];
                this.address.info = add[2];

                switch (this.formData.merchantStatus) {
                    case "RECEIVED":this.number = 2;break;
                    case "CARRY_OUT":this.number = 3;break;
                }
                switch (this.formData.riderStatus) {
                    case "RECEIVED":this.riderNumber = 2;break;
                    case "TAKE_MEAL":this.riderNumber = 3;break;
                    case "MEAL_DELIVERY":this.riderNumber = 4;break;
                    case "CARRY_OUT":this.riderNumber = 5;break;
                }
            }
        }
    }
</script>
<style lang="less" scoped>
</style>
