<template>
  <div class="orderDetail" v-loading="loading">
    <div class="orderDetail-box">
       <div class="orderDetail-box-header">
          订单信息
       </div>
       <div class="orderDetail-box-content">
          <el-row :gutter="20">
            <el-col :span="8"><span class="label">订单编号:</span><span class="txt">{{datas.orderNo}}</span></el-col>
            <el-col :span="8"><span class="label">订单状态:</span><span class="txt">{{datas.state == 0 ? '失效' : '有效'}}</span></el-col>
            <el-col :span="8"><span class="label">下单时间:</span><span class="txt">{{datas.createTime || '-'}}</span></el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8"><span class="label">支付方式:</span><span class="txt">{{datas.payChannel || '-'}}</span></el-col>
            <el-col :span="8"><span class="label">支付流水号:</span><span class="txt">{{datas.payNo || '-'}}</span></el-col>
            <el-col :span="8"></el-col>
          </el-row>
       </div>
    </div>
    <div class="orderDetail-box">
       <div class="orderDetail-box-header">
          客户信息
       </div>
       <div class="orderDetail-box-content">
          <el-row :gutter="20">
            <el-col :span="8"><span class="label">客户账号:</span><span class="txt">{{datas.account || '-'}}</span></el-col>
            <el-col :span="8"><span class="label">联系电话:</span><span class="txt">{{datas.phone || '-'}}</span></el-col>
            <el-col :span="8"><span class="label">客户名称:</span><span class="txt">{{datas.customerName || '-'}}</span></el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="8"><span class="label">客户类型:</span><span class="txt">{{datas.typeName || '-'}}</span></el-col>
            <el-col :span="8"></el-col>
            <el-col :span="8"></el-col>
          </el-row>
       </div>
    </div>
    <div class="orderDetail-box">
       <div class="orderDetail-box-header">
          订单商品
       </div>
       {{payStatusOptions}}
       <div class="orderDetail-box-content">
          <el-table :data="datas.goodsOrderDetailList" border>
            <el-table-column label="序号" type="index" width="50" align="center" />
            <el-table-column label="商品编号" align="center" prop="goodsCode" />
            <el-table-column label="商品名称" align="center" prop="goodsName"/>
            <el-table-column label="商品类型" align="center" prop="typeName"/>
            <el-table-column label="有效期至" align="center" prop="goodsSaleDate"/>
            <el-table-column label="单价" align="center" prop="goodsPrice"/>
            <el-table-column label="碳汇量（kg）" align="center" prop="saleNum"/>
            <el-table-column label="金额" align="center" prop="amount"></el-table-column>
          </el-table>
          <div class="tableTotal">
              总计 <span class="num">{{saleNumTotal}}</span> <span class="price">{{priceTotal}}</span>
          </div>
       </div>
    </div>
    <div class="orderDetail-footer">
       <el-button type="info" @click="goPage">返回</el-button>
    </div>
  </div>
</template>

<script>
  import { orderDetail } from "@/api/order/baseOrder";
  export default{
    name:"baseOrderDetail",
    created() {
      this.getDetail();
      //支付方式
      this.getDicts("order_base_playpaytype").then(response => {
        this.payStatusOptions = response.data;
        console.log(this.payStatusOptions)
      });
    },
    data(){
      return{
        payStatusOptions:[],
        datas:{
          orderNo:'',
          items:[],
        },
        loading:false,
      }
    },
    methods:{
      getDetail(){
        this.loading = true
        let params = {
          orderGuid:this.$route.query.id
        }
        orderDetail(params).then(res => {
            if (res.retHead.errCode === 0) {
              this.loading = false
              this.datas = res.retBody
            }
        });
      },
      goPage(){
        this.$router.go(-1)
      }
    },
    computed:{
      //碳汇量计算
      saleNumTotal(){
        let totalSumAll = 0;
        this.datas.goodsOrderDetailList.map((item) => {
          if(!isNaN(item.saleNum)) totalSumAll += item.saleNum
        })
        if(isNaN(totalSumAll)){
          return 0
        }
        return totalSumAll
      },
      //总价计算
      priceTotal(){
        let totalPrice = 0;
        this.datas.goodsOrderDetailList.map((item) => {
          if(!isNaN(item.goodsPrice)) totalPrice += item.goodsPrice
        })
        if(isNaN(totalPrice)){
          return 0
        }
        return totalPrice
      }
    }
  }
</script>

<style lang="scss" scoped>
  .orderDetail{
    margin:30px 40px;
    &-box{
      border-bottom:1px solid #EBEBEB;
      &-header{
        margin-top:10px;
        height:50px;
        line-height:50px;
        font-size:16px;
        font-weight:bold;
      }
      &-content{
        padding-bottom:10px;
        .el-col{
          height:35px;
          line-height:35px;
          font-size:14px;
          .label{
            color:#272727;
            font-weight:bold;
            margin-right:10px;
          }
          .txt{
            color:#5A5A5A;
          }
        }
        .tableTotal{
          position:relative;
          height:40px;
          line-height:50px;
          .num,
          .price{
            position:absolute;
            top:0;
          }
          .num{
            right:320px;
          }
          .price{
            right:90px;
          }
        }
      }
    }
    &-footer{
      text-align:center;
      padding:15px 0;
    }
  }
</style>
