<template>
  <div class="orderList">
    <div class="head">
      <div style="flex:4;padding-left:20px;">
        <span style="flex:2;">宝贝</span>
        <span style="flex:1;">单价</span>
        <span style="flex:1;">数量</span>
      </div>
      <div style="flex:4;padding-right:20px;">
        <span style="flex:1;">退款金额</span>
        <span style="flex:1;">申请时间</span>
        <span style="flex:1;">状态</span>
        <span style="flex:1;">操作</span>
      </div>
    </div>
    <div v-if="afterSaleList.length > 0">
      <div v-for="(item, index) in afterSaleList" :key="index" class="content">
        <div class="top">
          <div class="left">
            <span class="shopName" @click="toStore(item.shopId)"><img :src="item.shopLogo" alt="">{{ item.shopName }}</span>
            <span class="orderCode">售后编号：{{ item.afterFormid }}</span>
          </div>
        </div>
        <div class="productBox">
          <div class="product">
            <div class="left fs13">
              <div v-for="(pro, inx) in item.skus" :key="inx" class="box">
                <div class="desc cur-poi" @click="toProductDetail(pro, item.shopId)">
                  <img :src="pro.image" alt="">
                  <div>
                    <p class="name">{{ pro.productName }}</p>
                    <p class="size font-color-999"><span v-for="(val, idx) in pro.values" :key="idx">{{ val }}</span></p>
                  </div>
                </div>
                <div class="price">¥{{ pro.price }}</div>
                <div class="num">{{ pro.number }}</div>
              </div>
            </div>
            <div class="right" :class="item.skus.length > 1 ? 'right_line' : ''">
              <div class="actualPay">
                <div>
                  <p class="fs13 mar-bot-5">¥{{ item.price }}</p>
                </div>
              </div>
              <div class="applicationTime">{{ item.createTime }}</div>
              <div class="status">
                <div>
                  <p v-if="item.afterState == 1" class="fs13 mar-bot-5">审核中</p>
                  <p v-if="item.afterState == 2" class="fs13 mar-bot-5">退款中</p>
                  <p v-if="item.afterState == 3" class="fs13 mar-bot-5">退货中</p>
                  <p v-if="item.afterState == 4" class="fs13 mar-bot-5">退款成功</p>
                  <p v-if="item.afterState == 5" class="fs13 mar-bot-5">退款失败</p>
                  <p v-if="item.afterState == 6" class="fs13 mar-bot-5">审核不通过</p>
                  <p v-if="item.afterState == 7" class="fs13 mar-bot-5">评审中</p>
                  <p v-if="item.afterState == 8" class="fs13 mar-bot-5 font-color-999">退货完成，拒绝退款</p>
                  <p v-if="item.afterState == 9" class="fs13 mar-bot-5 font-color-999">已关闭</p>
                  <p v-if="item.afterState == 10" class="fs13 mar-bot-5 font-color-71B">审核通过</p>
                </div>
              </div>
              <div class="operate">
                <el-button
                  size="small"
                  @click="toAfterSaleDetail(item.afterId, item.orderId)"
                >
                  售后详情
                </el-button>
                <p
                  v-if="item.afterState == 6 || item.afterState == 8"
                  v-throttle
                  class="fs13 tex-und cur-poi mar-top-10"
                  @click="platform(item.afterId, item.orderId)"
                >
                  申请平台介入
                </p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-pagination
        :current-page="page"
        :page-size="5"
        :total="total"
        background
        layout="prev, pager, next"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </div>
    <div v-else class="noorder">
      <icon-svg style="width: 240px; height: 240px; margin-bottom: 20px;" icon-class="user-order-nodata" />
      <p class="fs20 font-color-999">你还没有售后订单哦～</p>
    </div>
    <el-dialog
      title="申请平台介入"
      :visible.sync="interventionShow"
      width="37%"
      center
    >
      <el-input
        v-model="reason"
        type="textarea"
        :rows="7"
        placeholder="请输入内容"
        maxlength="200"
      >
      </el-input>
      <el-upload
        :action="action"
        list-type="picture-card"
        :limit="3"
        :on-success="handleSuccess"
        :on-remove="handleRemove"
      >
        <i class="el-icon-camera"></i>
        <span
          style="
                display: block;
                height: 0px;
                line-height: 0px;
                margin-top: -30px;
            "
        >
          最多上传3张
        </span>
      </el-upload>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="interventionFn">确 定</el-button>
        <el-button @click="closeIntervention">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  requestPlatform
} from '@/api/user/afterSale.js'
import {
  upload
} from '@/api/upload.js'
export default {
  props: ['afterSaleList', 'page', 'total'],
  data() {
    return {
      state: 1,
      reason: '',
      images: '',
      interventionShow: false,
      afterId: '',
      orderId: '',
      urls: [],
      action: upload
    }
  },
  methods: {
    // 分页器跳转
    handleCurrentChange(val) {
      this.$emit('handleCurrentChange', val)
    },
    // 跳转到店铺
    toStore(id) {
      this.$router.push({
        path: '/store',
        query: {
          shopData: { shopId: id }
        }
      })
    },
    // 跳转到售后详情
    toAfterSaleDetail(aid, oid) {
      this.$router.push({
        path: '/orderDetail',
        query: {
          afterId: aid, // 售后id
          orderId: oid, // 订单id
          type: 3
        }
      })
    },
    // 跳转到商品详情
    toProductDetail(item, id) {
      const data = {
        productId: item.productId,
        skuId: item.skuId,
        shopId: id
      }
      this.$router.push({
        path: '/productDetail',
        query: {
          proData: JSON.stringify(data)
        }
      })
    },
    // 平台介入
    platform(afterId, orderId) {
      this.afterId = afterId
      this.orderId = orderId
      this.interventionShow = true
    },
    closeIntervention() {
      this.afterId = ''
      this.orderId = ''
      this.reason = ''
      this.interventionShow = false
    },
    // 申请平台介入
    async interventionFn() {
      const response = await requestPlatform({
        afterId: this.afterId,
        orderId: this.orderId,
        image: this.urls.join(','),
        reason: this.reason
      })
      const res = response.data
      if (res.code === '200') {
        this.$message.success('申请平台介入成功')
        this.interventionShow = false
      } else {
        this.$message.warning(res.message)
        this.interventionShow = false
      }
    },
    handleSuccess(res) {
      this.urls.push(res.data.url)
    },
    handleRemove(file, fileList) {
      this.urls = []
      for (var i in fileList) {
        this.urls.push(fileList[i].response.data.url)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.orderList{
  width: 100%;
  .noorder{
    width: 100%;
    text-align: center;
    padding: 100px 0;
    p{
      margin-bottom: 20px;
    }
    .el-button{
      background-color: $mainGlod;
      color: #FFFFFF;
      font-weight: normal;
      border-radius: 0;
    }
  }
  .el-textarea {
    margin-bottom: 7px;
  }
  .upload{
    margin-top: 5px;
    display: flex;
    .title{
      line-height: 40px;
    }
    >>> .el-upload--picture-card{
      height: 140px;
      background-color: #FFF;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      i{
        font-size: 32px;
      }
      &:hover{
        i{
        color: $mainGlod;
        }
      }
    }
  }
  .head{
    box-sizing: border-box;
    width: 100%;
    height: 44px;
    background-color: #F1F2F7;
    display: flex;
    align-items: center;
    text-align: center;
    margin-bottom: 20px;
    div{
      display: flex;
    }
  }
  .content{
    width: 100%;
    margin-bottom: 20px;
    border: 1px solid #E5E5E5;
    border-bottom: 0;
    box-sizing: border-box;
    .top{
      width: 100%;
      font-size: 13px;
      height: 40px;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #F3F3F3;
      .left{
        display: flex;
        .shopName{
          margin-left: 20px;
          margin-right: 60px;
          cursor: pointer;
          display: flex;
          align-items: center;
          img{
            width: 16px;
            height: 16px;
            vertical-align: middle;
            margin-right: 5px;
          }
        }
        .time{
          margin-right: 60px;
        }
      }
    }
    .productBox{
      width: 100%;
      box-sizing: border-box;
      .product{
        width: 100%;
        display: flex;
        .left{
          flex: 4;
          .box{
            padding: 20px 0 20px 20px;
            display: flex;
            border-bottom: 1px solid #E5E5E5;
            .desc{
              flex: 2;
              display: flex;
              img{
                width: 86px;
                height: 86px;
                margin-right: 10px;
              }
              div{
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .name{
                  font-size: 14px;
                }
                .size{
                  font-size: 13px;
                  span{
                    margin-right: 10px;
                  }
                  span:last-child{
                    margin-right: 0;
                  }
                }
              }
            }
            .price,.num{
              flex: 1;
              display: flex;
              align-items: center;
              justify-content: center;
            }
          }
        }
        .right{
          padding: 20px 20px 20px 0;
          flex: 4;
          display: flex;
          border-bottom: 1px solid #E5E5E5;
          .actualPay,.applicationTime,.status,.operate{
            flex: 1;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            div{
              text-align: center;
            }
            .el-button{
              border: 1px solid $mainGlod;
              color: $mainGlod;
              border-radius: 0;
            }
          }
          .status{
            p{
              color: #C83732;
            }
          }
          .operate{
            flex-direction: column;
          }
        }
        .right_line{
          border-left: 1px solid #E5E5E5;
        }
      }
    }
  }
  >>>.el-pagination{
    margin-top: 40px;
    text-align: right;
    .el-pager{
      li:not(.disabled):hover{
        color: $mainGlod;
      }
      li:not(.disabled).active{
        background-color: $mainGlod;
      }
      li:not(.disabled).active:hover{
        color: #F4F4F5;
      }
    }
  }
}
</style>
