<template>
  <zj-page-container>
    <zj-page-fill>
      <div style="box-sizing: border-box; padding: 10px">
        <div>
          <div class="order-main">
            <el-row style="padding: 15px 15px 10px">
              <el-col :span="24">
                <div class="order-main-title">
                  <span>售后编号：{{ orderDetail.esOrderRefundId }}</span>
                  <span>订单号：{{ orderDetail.esOrderId }}</span>
                  <span>下单时间：{{ orderDetail.createTime }}</span>
                </div>
              </el-col>
            </el-row>
            <div style="width: 100%; padding: 10px 15px 15px 15px">
              <el-row>
                <el-col :span="10">
                  <div v-if="~['WAIT'].indexOf(orderDetail.status)">
                    <el-form ref="formTHref" :model="formTH" label-width="80px" size="mini">
                      <el-form-item
                        label="处理结果"
                        prop="refundType"
                        :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
                      >
                        <el-radio-group v-model="formTH.refundType">
                          <el-radio label="GOODS">仅退货</el-radio>
                          <el-radio label="REFUND">仅退款</el-radio>
                          <el-radio label="GOODS_REFUND">退货退款</el-radio>
                          <el-radio label="FAIL">驳回</el-radio>
                        </el-radio-group>
                      </el-form-item>
                      <el-form-item
                        v-if="~['GOODS', 'GOODS_REFUND'].indexOf(formTH.refundType)"
                        label="退货数量"
                        prop="refundNum"
                        :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
                      >
                        {{
                          (() => {
                            if (formTH.refundType == 'GOODS') formTH.refundPrice = ''
                          })()
                        }}
                        <el-input v-model="formTH.refundNum"></el-input>
                      </el-form-item>
                      <el-form-item
                        v-if="~['REFUND', 'GOODS_REFUND'].indexOf(formTH.refundType)"
                        label="退款金额"
                        prop="refundPrice"
                        :rules="[{ required: true, message: '请填写', trigger: 'blur' }]"
                      >
                        {{
                          (() => {
                            if (formTH.refundType == 'REFUND') formTH.refundNum = ''
                          })()
                        }}
                        <el-input type="number" v-model="formTH.refundPrice"></el-input>
                      </el-form-item>
                      <el-form-item label="备注">
                        <el-input type="textarea" v-model="formTH.refundRemark"></el-input>
                      </el-form-item>
                    </el-form>
                  </div>
                  <div v-else style="display: flex">
                    <div>
                      <div class="order-main-status">
                        <span>{{ { WAIT: '平台处理', OVER: '完成' }[orderDetail.status] }}</span>
                      </div>
                    </div>
                  </div>
                </el-col>
                <el-col :span="14" style="padding-top: 10px">
                  <el-steps :active="zhuangtai" align-center>
                    <el-step title="买家申请"></el-step>
                    <el-step title="平台处理"></el-step>
                    <el-step title="维权完成"></el-step>
                  </el-steps>
                </el-col>
              </el-row>
            </div>
          </div>

          <div class="order-receive-info">
            <el-row :gutter="10">
              <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
                <div class="info">
                  <div class="info_title">卖家信息</div>
                  <div class="info_bottom">
                    <div v-if="orderDetail.sellUrl" class="info_bottom_lt">
                      <el-image style="width: 40px; height: 40px" :src="$showImgUrl(orderDetail.sellUrl)"></el-image>
                    </div>
                    <div class="info_bottom_rt">
                      <div>昵称：{{ orderDetail.sellName }}</div>
                      <div>手机号：{{ orderDetail.sellMobile }}</div>
                      <div>发布时间：{{ orderDetail.sellTime }}</div>
                    </div>
                  </div>
                </div>
              </el-col>
              <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
                <div class="info">
                  <div class="info_title">买家信息</div>
                  <div class="info_bottom">
                    <div v-if="orderDetail.wechatUserUrl" class="info_bottom_lt">
                      <el-image style="width: 40px; height: 40px" :src="$showImgUrl(orderDetail.wechatUserUrl)">
                      </el-image>
                    </div>
                    <div class="info_bottom_rt">
                      <div v-if="orderDetail.wechatUserName">昵称：{{ orderDetail.wechatUserName }}</div>
                      <div v-if="orderDetail.wechatUserMobile">手机号：{{ orderDetail.wechatUserMobile }}</div>
                      <div>收货人信息：({{ orderDetail.userName }}){{ orderDetail.userMobile }}</div>
                      <div>
                        收货人地址：{{
                          orderDetail.province +
                          orderDetail.city +
                          orderDetail.area +
                          orderDetail.street +
                          orderDetail.receAddress
                        }}
                      </div>
                      <div>
                        支付方式：{{
                          { WECHAT: '微信支付', CASH: '到店支付', TRANSFER: '转账支付' }[orderDetail.payType]
                        }}
                      </div>
                    </div>
                  </div>
                </div>
              </el-col>
              <el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="8">
                <div class="info">
                  <div class="info_title">维权信息</div>
                  <div class="info_bottom">
                    <div class="info_bottom_rt">
                      <div>
                        退款方式：{{
                          { REFUND: '退款', GOODS_REFUND: '退货退款', FAIL: '驳回', GOODS: '退货' }[
                            orderDetail.refundType
                          ] || ''
                        }}
                      </div>
                      <div>退款原因：{{ orderDetail.refundNote || '' }}</div>
                      <div>
                        退款凭证：<el-image
                          v-for="(item, index) in orderDetail.esOrderRefundFiles || []"
                          :preview-src-list="
                            (orderDetail.esOrderRefundFiles || []).map(item => $showImgUrl(item.fileUrl))
                          "
                          :key="index"
                          style="width: 60px; height: 60px"
                          :src="$showImgUrl(item.fileUrl)"
                        ></el-image>
                      </div>
                    </div>
                  </div>
                </div>
              </el-col>
            </el-row>
          </div>

          <h3>商品信息</h3>
          <div class="order-main" style="border: none">
            <!-- 订单表格 -->
            <el-table :data="[orderDetail]" style="width: 100%" border>
              <el-table-column label="商品信息" min-width="200">
                <template slot-scope="scope">
                  <el-row>
                    <el-col v-if="scope.row.goodsUrl" :span="6">
                      <el-image style="width: 40px; height: 40px" :src="$showImgUrl(scope.row.goodsUrl)">
                        <div slot="error" class="image-slot">
                          <i class="el-icon-picture-outline"></i>
                        </div>
                      </el-image>
                    </el-col>
                    <el-col :span="18">
                      <div>{{ scope.row.esGoodsName }}</div>
                    </el-col>
                  </el-row>
                </template>
              </el-table-column>
              <el-table-column prop="goodsPrice" label="单价" align="center"></el-table-column>
              <el-table-column prop="num" label="数量" align="center"></el-table-column>
              <el-table-column prop="totalAmount" label="商品总金额" align="center" min-width="100"></el-table-column>
              <el-table-column prop="refundPrice" label="退款金额" align="center"></el-table-column>
            </el-table>
          </div>

          <h3 v-if="orderDetail.status == 'OVER'">退款记录</h3>
          <div v-if="orderDetail.status == 'OVER'" class="order-main" style="border: none">
            <!-- 订单表格 -->
            <el-table :data="[orderDetail]" style="width: 100%" border>
              <el-table-column label="处理结果" min-width="200">
                <template slot-scope="scope">
                  {{ { REFUND: '退款', GOODS_REFUND: '退货退款', FAIL: '驳回', GOODS: '退货' }[scope.row.refundType] }}
                </template>
              </el-table-column>
              <el-table-column prop="refundNum" label="退货数量" align="center"></el-table-column>
              <el-table-column prop="refundPrice" label="退款金额" align="center"></el-table-column>
              <el-table-column prop="refundRemark" label="备注" align="center" min-width="100"></el-table-column>
              <el-table-column prop="refundName" label="退款人" align="center"></el-table-column>
              <el-table-column prop="refundTime" label="退款时间" align="center"></el-table-column>
            </el-table>
          </div>
        </div>
      </div>
    </zj-page-fill>
    <div v-if="~['WAIT'].indexOf(orderDetail.status)" style="box-sizing: border-box; padding: 10px; text-align: right">
      <el-button type="primary" size="small" @click="faqituikuan">确定</el-button>
    </div>
  </zj-page-container>
</template>

<script>
import { esOrderDetailRefund, esOrderRefundPrice } from '@/api/orderManagement'
export default {
  props: {
    detailsId: {
      type: [String, Number],
      default: ''
    },
    detailsType: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      detailsTypeCp: this.detailsType,
      // 退货退款表单
      formTH: {
        refundType: '',
        refundNum: '',
        refundPrice: '',
        refundRemark: ''
      },
      // 订单详情
      orderDetail: {}
    }
  },
  computed: {
    zhuangtai() {
      return !!~['WAIT'].indexOf(this.orderDetail.status) ? 2 : !!~['OVER'].indexOf(this.orderDetail.status) ? 3 : -1
    }
  },
  watch: {
    detailsId: {
      handler(newVal, oldVal) {
        this.getEsOrderDetail()
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    getEsOrderDetail() {
      esOrderDetailRefund({
        esOrderRefundId: this.detailsId
      }).then(res => {
        this.orderDetail = {
          ...res.data
        }
      })
    },
    faqituikuan() {
      this.$refs.formTHref.validate(valid => {
        if (valid) {
          esOrderRefundPrice({
            ...this.formTH,
            esOrderRefundId: this.detailsId
          }).then(res => {
            this.$message({ type: 'success', message: `操作成功!` })
            this.$emit('removeTab')
          })
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.info {
  .info_title {
    font-size: 16px;
    font-weight: 700;
  }

  .info_bottom {
    display: flex;
    margin: 10px 0;

    .info_bottom_lt {
      width: 40px;
      height: 40px;
    }

    .info_bottom_rt {
      padding: 0 0 0 10px;
      line-height: 30px;

      .photoPZ {
        display: inline-block;
        vertical-align: text-top;
      }
    }
  }
}

.order-main {
  margin-top: 15px;
  border: 1px solid #e5e5e5;

  .order-main-title {
    font-size: 14px;
  }

  .order-main-title span {
    margin-right: 15px;
  }

  .order-main-status {
    padding: 15px 0;
    font-size: 24px;
    color: #409eff;
  }

  .order-main-opt-btn {
    padding: 15px 0;
  }
}

.order-receive-info {
  margin: 15px 0 30px;
  padding: 15px;
  background: #f5f7fa;

  :first-child div span {
    padding-right: 15px;
  }
}

.order-detail {
  background: #f5f7fa;

  .order-amount-info {
    padding: 15px 0;
    font-size: 12px;
    font-weight: bold;
  }

  ::v-deep .el-table tr,
  ::v-deep .el-table th {
    background-color: #f5f7fa;
  }
}

.main-detail {
  .title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
  }

  .item {
    display: flex;
    font-size: 14px;
    color: #666;
    padding-bottom: 12px;

    .label {
      white-space: nowrap;
    }
  }
}

.order-evaluate-info {
  margin: 15px 0;
  padding: 30px 15px;
  background: #f5f7fa;

  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .left {
      font-size: 16px;
      font-weight: 700;

      span {
        font-weight: normal;
        margin-left: 20px;
        font-size: 14px;
        color: #666;
      }
    }

    .right {
      display: flex;
      align-items: center;
      font-size: 14px;

      span {
        margin-right: 10px;
      }
    }
  }

  .main {
    margin-top: 20px;
    display: flex;

    .rate-list {
      font-size: 14px;
      flex-shrink: 0;
    }

    .tag-list {
      margin-left: 30px;

      ::v-deep .el-tag {
        margin-right: 10px;
        margin-bottom: 10px;
      }
    }
  }

  .content {
    width: 400px;
    line-height: 20px;
    font-size: 14px;
    color: #333;
    margin-top: 10px;
  }

  .img-list {
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    width: 400px;

    ::v-deep .el-image {
      width: 100px;
      height: 100px;
      margin-right: 10px;
      margin-bottom: 10px;
      border: 1px solid #eaeaea;
    }
  }
}
</style>
