<!--
  @description: 退货管理
  @Modifier：dijia
  @routerPath:/personalCenter/refund
  @date：2021/09/28
-->
<template>
  <div>
    <div class="shopmall-page-title">
      退货管理
    </div>
    <div class="search-content clearfix">
      <section class="fl">
        <el-form ref="infoFromRef" :inline="true" :model="infoFrom">
          <el-form-item label="商品名称" prop="goodsName" placeholder="请输入商品名称">
            <el-input v-model="infoFrom.goodsName" />
          </el-form-item>
          <el-form-item label="申请时间" prop="date">
            <el-date-picker
              v-model="infoFrom.date"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            />
          </el-form-item>
          <el-form-item label="退货状态" prop="status">
            <el-select v-model="infoFrom.status" placeholder="--请选择--">
              <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
      </section>
      <div class="fr">
        <el-button type="purple" @click="onSearch">
          搜索
        </el-button>
        <el-button type="gray" @click="resetList">
          重置
        </el-button>
      </div>
    </div>
    <div v-if="allList.length" class="list-title font_normal">
      <div>商品信息</div>
      <div>退款金额（元）</div>
      <div>申请时间</div>
      <div>申请部门</div>
      <div>申请人</div>
      <div>状态</div>
      <div>操作</div>
    </div>
    <div v-for="(item,index) in allList" :key="index" class="all-order">
      <div class="item-title font_normal">
        <span>订单号: {{ item.orderNo }}</span>
        <span>退款编号: {{ item.returnId }}</span>
        <span>店铺: <span class="depart_name">{{ item.goodsDepartName }}</span></span>
      </div>
      <div class="item">
        <div class="item-left font_normal">
          <div v-for="(goodslist,ind) in item.orderBackGoods" :key="ind" class="shop-item">
            <div>
              <img :src="goodslist.productPicture" alt width="40px" height="40px">
            </div>
            <div class="goods_name cursor" :title="goodslist.goodsName" @click="goToDetail(item.productId)">
              {{ goodslist.goodsName }}
            </div>
            <div class="gooslist_count">
              x{{ goodslist.number }}
            </div>
          </div>
        </div>
        <div class="item-right font_normal">
          <div class="total-count">
            <div>
              <span class="count">¥ {{ item.backAmount }}</span>
            </div>
            <!-- <div>在线支付</div> -->
          </div>
          <div class="sleep-fk">
            <div>{{ item.applyDate }}</div>
          </div>
          <div class="order-status">
            <div>{{ item.goodsDepartName }}</div>
          </div>
          <div class="order-status">
            <div>{{ item.goodsDepartName }}</div>
          </div>
          <div class="order-status flex1">
            <div class="status">
              {{ formatStatus(item.status) }}
            </div>
          </div>
          <div class="assess">
            <div v-if="roleCode==='shopSupplier' && item.status==='00'" class="order_option font_normal cursor mb10" @click="orderConfirm(item)">
              审核退货
            </div>
            <div class="order_option font_normal cursor" @click="refundDetail(item)">
              查看
            </div>
            <div v-if="roleCode==='shopSupplier' && item.status==='01'" class="order_option font_normal cursor mt10" @click="confirmReceive(item)">
              确认收货
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="!allList.length" class="empty_box">
      <span class="empty_text">暂无数据</span>
    </div>
    <!--分页组件-->
    <pagination :pagination-data="paginationData" shopmall-pagination="shopmall-pagination" @change="searchList" />
    <refundDialog :dialog-data="dialogData" @call-back="callback" />
  </div>
</template>
<script>
import { getOrdersBack } from '@/api/shoppingmall/order'
/* 组件*/
import pagination from '@comp/common/pagination/pagination'// 分页
import refundDialog from './refund-dialog.vue'
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 常用方法
export default {
  components: {
    pagination,
    refundDialog
  },
  filters: {
  },
  data() {
    return {
      total: 0,
      current: 1,
      infoFrom: {
        applyEndDate: null,
        applyStartDate: null,
        goodsName: null,
        pageNo: 0,
        pageSize: 10,
        status: null,
        userId: null,
        date: ''
      },
      allList: [
      ],
      // 分页数据
      paginationData: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      },
      // dialog对象数据
      dialogData: {
        visible: false,
        id: '',
        type: 'audit' // audit:审核 confirm:收货确认
      },
      // 状态数组
      statusList: [
        {
          value: '00', label: '待处理'
        },
        {
          value: '01', label: '退货中'
        },
        {
          value: '02', label: '已取消'
        },
        {
          value: '03', label: '拒绝退货'
        },
        {
          value: '04', label: '未收到退货'
        },
        { label: '买家退货', value: '05' },
        { label: '卖家确认并发货', value: '06' },
        { label: '卖家确认退货完毕', value: '09' },
        { label: '买家确认换货结束', value: '10' }
      ]
    }
  },
  computed: {
    // 角色编码 供应商：shopSupplier 采购人：19 电商管理员：shopPlatAdmin 电商采购部门负责人：shopAdmin
    roleCode() {
      return this.$store.getters.info.currentRol.roleCode
    }
  },
  created() {
    this.searchList()
  },
  methods: {
    // 获取列表信息
    searchList() {
      const params = this.getQueryParams()// 查询条件
      // 调用获取列表接口
      getOrdersBack(params).then(res => {
        this.allList = res.data.records
        this.paginationData.total = res.data.total
      })
    },
    // 查询条件
    getQueryParams() {
      const param = Object.assign({}, this.infoFrom)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      param.applyStartDate = this.infoFrom.date[0]
      param.applyEndDate = this.infoFrom.date[1]
      const array = JSON.parse(JSON.stringify(param))
      delete array.date
      return filterObj(array)
    },
    // 搜索
    onSearch() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 获取列表信息
      this.searchList()
    },
    resetList() {
      // 搜素条件置空
      this.$refs.infoFromRef.resetFields()
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      // 调用获取列表接口
      this.searchList()
    },
    orderConfirm(item) {
      // 审核
      this.dialogData.visible = true
      this.dialogData.id = item.id
      this.dialogData.type = 'audit'
    },
    // 退货详情
    refundDetail(item) {
      this.$router.push({
        path: '/personalCenter/refundOrderDetail',
        query: {
          orderDetailId: item.orderDetailId,
          orderBackId: item.id,
          from: '/personalCenter/refund'
        }
      })
    },
    // 确认收货
    confirmReceive(item) {
      // 确认收货
      this.dialogData.visible = true
      this.dialogData.id = item.id
      this.dialogData.type = 'confirm'
    },
    formatStatus(val) {
      if (!val) return 'null'
      for (const { value, label } of this.statusList) {
        if (value === val) {
          return label
        }
      }
    },
    callback() {
      this.searchList()
    },
    goToDetail(id) {
      this.$router.push({
        path: '/shop/goodsClassDetail',
        query: { id }
      })
    }
  }
}
</script>

<style scoped lang="less">
.list-title {
  border: 1px solid #f2f2f2;
  background: #fafafa;
  height: 40px;
  line-height: 40px;
  margin: 12px 12px 0 12px;
  div {
    float: left;
    text-align: center;
    &:nth-child(1) {
      width: 40%;
    }

    &:nth-child(2) {
      width: 9.6%;
    }

    &:nth-child(3) {
      width: 14.4%;
    }

    &:nth-child(4) {
      width: 9.6%;
    }
    &:nth-child(5) {
      width: 9.6%;
    }
    &:nth-child(6) {
      width: 7.2%;
    }
    &:nth-child(7) {
      width: 9.6%;
    }
  }
}
.all-order {
  padding: 0 12px;
}
.item-title {
  margin-top: 20px;
  width: 100%;
  background-color: #fafafa;
  height: 40px;
  display: flex;
  align-items: center;
  border: 1px solid #f2f2f2;
  border-bottom: 0;
  >span {
    display: inline-block;

    &:nth-child(1) {
      margin-left: 10px;
    }

    &:nth-child(2) {
      margin-left: 20px;
      margin-right: 30px;
    }
  }
  .depart_name {
    background-color: #f59a23;
    margin-left: 10px;
    border-radius: 4px;
    border-width: 0px;
    color: #FFFFFF;
    padding: 1px 5px;
  }
}

.item {
  display: flex;
  margin-bottom: 30px;

  .item-left {
    width: 40%;
    border-top: 1px solid #f2f2f2;

    .shop-item {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      border-left: 1px solid #f2f2f2;
      // border-right: 1px solid #cccccc;
      border-bottom: 1px solid #f2f2f2;
      height: 90px;
      div {
        &:nth-child(1) {
          margin-left: 10px;
          border: 1px solid #eee;
          padding: 1px;
        }

        &:nth-child(2) {
          margin-left: 20px;
          margin-right: 30px;
        }

        &:nth-child(4) {
          margin-left: 80px;
          color: #1f94f4;
        }
      }
    }
  }

  .item-right {
    width: 60%;
    border: 1px solid #f2f2f2;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;

    .total-count {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      border-right:1px solid #f2f2f2;
      height: 100%;
      flex: 4;
      .count {
        color: #ff4444;
      }
    }

    .sleep-fk {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      flex: 6;
      height: 100%;
      border-right:1px solid #f2f2f2;
      .order-detail {
        color: #1f94f4;
      }
    }
    .order-status {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      flex: 4;
      height: 100%;
      border-right:1px solid #f2f2f2;
      .status {
        color: #1f94f4;
      }
    }
    .assess {
      flex: 4;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
    }
    .flex1 {
      flex: 3;
    }
    .order_option {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 68px;
      height: 28px;
      background: #F2F2F2;
      border-radius: 2px;
      border: 1px solid #e0e0e0;
      color: #333333;
      &:hover {
        background: @hyacinthine;
        color: #fff;
        border: 1px solid @hyacinthine;
      }
    }
  }
}
.gooslist_count{
  margin-left: 30px;
  width: 60px;
  color: red;
}
.goods_name {
    flex: 1;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    font-family: "MicrosoftYaHei";
    &:hover {
      color: #00aaca;
    }
}
.font_normal {
  font-family: 'PingFangSC-Regular', 'PingFang SC';
  font-weight: 400;
  font-style: normal;
  font-size: 12px;
}
.empty_box {
  width: 100%;
  height: 300px;
  padding: 130px 12px;
  margin: 0 auto;
  text-align: center;
  .empty_text {
    line-height: 40px;
    color: #909399;
    font-size: 12px;
  }
}
</style>
