<template>
    <div style="background-color: #f0f2f5; padding-bottom: 20px; min-height: 100%; " >
      <div style="padding: 20px; background-color: #fff;">
         积分订单详情
      </div>
<div class="contentx" v-if="item!=null">
        <div class="desct"> 积分订单信息</div>
        <div class="order-status" v-if="item!=null" >
                  <el-steps  :active="item.status==3?item.status:item.status-1" align-center finish-status="success">
                    <el-step title="待发货"></el-step>
                    <el-step title="待收货"></el-step>
                    <el-step title="已完成"></el-step>
                  </el-steps>
        </div>
         <el-card shadow="never" style="margin-top: 15px">
           <div class="operate-container"  v-if="item!=null">
             <span style="margin-left: 20px" class="color-danger">订单状态：
                <el-tag prop="status" v-for="(ite, index) in statusOptions"    v-if="item.status==ite.dictValue">{{ite.dictLabel}}</el-tag>
             </span>
             <div class="operate-button-container"  v-if="item.status==1" v-hasPermi="['his:integralOrder:sendGoods']">
                <el-button size="mini" @click="sendVisible=true" >发货</el-button>
             </div>
            <div class="operate-button-container"   v-if="item.deliverySn!=null" v-hasPermi="['his:integralOrder:express']">
              <el-button size="mini" @click="showExpress()" >查看物流</el-button>
            </div>

            <div class="operate-button-container"  v-hasPermi="['his:integralOrder:edit']">
              <el-button size="mini" @click="updateOrder()" >修改订单</el-button>
            </div>
           </div>
           <div class="desct">
            基本信息
           </div>
           <el-descriptions title="" :column="3" border>
             <el-descriptions-item label="订单编号"><span v-if="item!=null">{{item.orderCode}}</span></el-descriptions-item>
              <el-descriptions-item label="会员ID"><span v-if="item!=null">{{item.userId}}</span></el-descriptions-item>
             <el-descriptions-item label="会员"><span v-if="item.nickName!=null">{{item.nickName}}({{item.phone}})</span></el-descriptions-item>
             <el-descriptions-item label="用户名称"><span v-if="item!=null">{{item.userName}}</span></el-descriptions-item>
             <el-descriptions-item label="用户电话"><span v-if="item!=null">{{item.userPhone}}</span>
              <el-button icon="el-icon-search" size="mini" @click="handlePhone()" style="margin-left: 20px;" circle v-hasPermi="['his:integralOrder:queryPhone']"></el-button>
            </el-descriptions-item>
              <el-descriptions-item label="用户地址"><span v-if="item!=null">{{item.userAddress}}</span></el-descriptions-item>
             <el-descriptions-item label="支付积分"><span v-if="item!=null">{{item.integral}}</span></el-descriptions-item>
             <el-descriptions-item label="状态"><span v-if="item!=null"> <dict-tag :options="statusOptions" :value="item.status"/></span></el-descriptions-item>
             <el-descriptions-item label="快递公司编号"><span v-if="item!=null">{{item.deliveryCode}}</span></el-descriptions-item>
             <el-descriptions-item label="快递名称"><span v-if="item!=null">{{item.deliveryName}}</span></el-descriptions-item>
             <el-descriptions-item label="快递单号"><span v-if="item!=null">{{item.deliverySn}}</span></el-descriptions-item>
             <el-descriptions-item label="发货时间"><span v-if="item!=null">{{item.deliveryTime}}</span></el-descriptions-item>
             <el-descriptions-item label="提交时间"><span v-if="item!=null">{{item.createTime}}</span></el-descriptions-item>
           </el-descriptions>
         </el-card>

    </div>
      <div class="contentx" v-if="item!=null" style="padding-bottom: 70px;">
       <div class="desct">
           商品信息
          </div>
       <el-table
              border
              v-if="prod!=null"
              :data="prod"
              size="small"
              style="margin-top: 20px" >
              <el-table-column label="商品图片"  align="center">
                <template slot-scope="scope">
                  <img :src="scope.row.imgUrl" style="height: 80px">
                </template>
              </el-table-column>
              <el-table-column label="商品名称"  align="center">
                <template slot-scope="scope">
                  <p>{{scope.row.goodsName}}</p>
                </template>
              </el-table-column>
              <el-table-column label="积分" align="center">
                <template slot-scope="scope">
                  <p>￥{{scope.row.integral}}</p>
                </template>
              </el-table-column>

            </el-table>
       </div>
      <el-dialog
           width="50%"
           title="发货"
           :visible.sync="sendVisible"
           append-to-body @close="sendCancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
          <el-form-item label="快递公司编号" prop="deliveryCode">
                    <el-input v-model="form.deliveryCode" placeholder="请输入快递公司编号" />
                  </el-form-item>
                  <el-form-item label="快递名称" prop="deliveryName">
                    <el-input v-model="form.deliveryName" placeholder="请输入快递名称" />
                  </el-form-item>
                  <el-form-item label="快递单号" prop="deliverySn">
                    <el-input v-model="form.deliverySn" placeholder="请输入快递单号" />
                  </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
                          <el-button type="primary" @click="sendGoods">确 定</el-button>
                          <el-button @click="sendCancel">取 消</el-button>
        </div>

          </el-dialog>

          <el-dialog :title="expressDialog.title" :visible.sync="expressDialog.open" width="600px" append-to-body>
            <el-table style="margin-top: 20px;width: 100%"
                      ref="orderHistoryTable"
                      :data="traces" border>
              <el-table-column label="操作时间"  width="160" align="center">
                <template slot-scope="scope">
                  {{scope.row.AcceptTime}}
                </template>
              </el-table-column>
               <el-table-column label="位置" align="center">
                <template slot-scope="scope">
                  {{scope.row.Location}}
                </template>
              </el-table-column>
              <el-table-column label="描述" align="center">
                <template slot-scope="scope">
                  {{scope.row.AcceptStation}}
                </template>
              </el-table-column>
            </el-table>
          </el-dialog>

          <el-dialog :title="editOrder.title" :visible.sync="editOrder.open" width="600px" append-to-body>
            <el-form ref="editForm" :model="editForm" :rules="editRules" label-width="100px">
              <el-form-item label="订单状态" prop="status" >
                <el-select v-model="editForm.status" placeholder="请选择状态" clearable size="small" filterable>
                    <el-option
                      v-for="dict in statusOptions "
                      :key="dict.dictValue"
                      :label="dict.dictLabel"
                      :value="dict.dictValue"
                    />
                  </el-select>
                </el-form-item>
              <el-form-item label="详情地址" prop="userAddress"  >
                <el-input v-model="editForm.userAddress" placeholder="请输入" />
              </el-form-item>
              <el-form-item label="备注" prop="remark"  >
                <el-input v-model="editForm.remark" placeholder="请输入备注" />
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="submitEditForm">确 定</el-button>
            </div>
          </el-dialog>
    </div>
</template>

<script>
import {getExpress, listIntegralOrder, sendgoods,getIntegralOrder, delIntegralOrder, addIntegralOrder, updateIntegralOrder, exportIntegralOrder,getOrderUserPhone } from "@/api/store/integralOrder";
  export default {
    name: "integralOrder",
    data() {
      return {
        expressDialog:{
          title:"物流信息",
          open:false,
        },
        editOrder:{
          title:"修改订单",
          open:false,
        },
        editForm:{
          orderId:null,
          status:null,
          userAddress:null,
          remark:"",
        },
        editRules:{},
        item:null,
        express:null,
        traces:[],
        rules:{
      deliveryCode: [
        { required: true, message: '请输入快递公司编号', trigger: 'blur' }
      ],
      deliveryName: [
        { required: true, message: '请输入快递名称', trigger: 'blur' }
      ],
      deliverySn: [
        { required: true, message: '请输入快递单号', trigger: 'blur' }
      ]
    },
        sendVisible:false,
        form: {
          deliveryCode: null,
          deliveryName:null,
          deliverySn:null,
          orderId:null,
        }
      }
    },
    created() {
      this.getDicts("sys_integral_order_status").then(response => {
        this.statusOptions = response.data;
      });
    },
    methods: {
      handlePhone(){
        const orderId = this.item.orderId;
        getOrderUserPhone(orderId).then(response =>{
            this.item.userPhone = response.userPhone;
        })
      },
      updateOrder(){
        this.editOrder.open=true;
        this.editForm.orderId=this.item.orderId;
        this.editForm.remark=this.item.remark;
        this.editForm.status = this.item.status.toString();
        this.editForm.userAddress = this.item.userAddress.toString();
      },
     //修改订单状态
     submitEditForm(){
        this.$refs["editForm"].validate(valid => {
        if (valid) {
          updateIntegralOrder(this.editForm).then(response => {
            if (response.code === 200) {
              this.msgSuccess("操作成功");
              this.editOrder.open = false;
              this.getDetails(this.item.orderId);
              }
            });
          }
        });
      },
      sendCancel(){
           this.sendVisible = false;
           this.form={
             deliveryCode: null,
             deliveryName:null,
             deliverySn:null,
             orderId:null,
           }
      },
      showExpress(){
        this.expressDialog.open=true;
        getExpress(this.item.orderId).then(response => {
            this.express = response.data;
            if(this.express!=null&&this.express.Traces!=null){
                this.traces=this.express.Traces
            }
        });
      },
          sendGoods(){
              this.form.orderId=this.item.orderId;
              sendgoods(this.form).then(response => {
                    this.msgSuccess("修改成功");
                    this.sendVisible = false;
                    getIntegralOrder(this.item.orderId).then(response => {
                        this.item = response.data;
                        this.$parent.$parent.getList();
                    });

                    this.form={
                    deliveryCode: null,
                    deliveryName:null,
                    deliverySn:null,
                    orderId:null,
                  }
              });
            },
      getDetails(orderId) {
        this.item=null;
        getIntegralOrder(orderId).then(response => {
            this.item = response.data;
            this.prod=[JSON.parse(this.item.itemJson)];
        });
      },
    }
  }
</script>
<style>
  .contentx{
      height: 100%;
      background-color: #fff;
      padding: 0px 20px 20px;


      margin: 20px;
  }
  .el-descriptions-item__label.is-bordered-label{
    font-weight: normal;
  }
  .el-descriptions-item__content {
    max-width: 150px;
    min-width: 100px;
  }
  .desct{
      padding-top: 20px;
      padding-bottom: 20px;
      color: #524b4a;
      font-weight: bold;
    }
.operate-container {
  background: #F2F6FC;
  height: 60px;
  margin: -20px -20px 0;
  line-height: 60px;
}
.order-content{
  margin: 10px;

}
.operate-button-container {
  float: right;
  margin-right: 20px
}
</style>
