<template>
  <div class="mod-menu">
    <div class="mt30">
      <el-form :inline="true" :model="params" style="text-align: center">
        <el-form-item label="核销码">
          <el-input style="width: 400px" v-model="params.verificationCode" @input="inputFun" placeholder="请输入订单核销码" clearable></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="loadList()">查询</el-button>
          <el-button v-if="btnshow" type="primary" @click="addOrUpdateHandle()">核销</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="table-data" v-loading="tableLoading">
      <div class="table-content" v-for="(v, i) in dataList" :key="i">
        <div class="goods-info">
          <div class="good-img-div">
            <el-image class="table-img" :src="v.productCover" :preview-src-list="[v.productCover]">
            </el-image>
          </div>
          <div class="info">
            <div class="goods-title">{{ v.productTitle }}</div>
            <div class="price">
              ￥
              <span class="can-inpu">{{ v.realPrice }}</span>
            </div>
            <div class="remark">x{{ v.productNum }}</div>
            <div class="remark">{{ v.skuSetName }}</div>
          </div>
        </div>
      </div>
      <p></p>
      <div class="pickUp" v-if="goodsData && goodsData.orderSelfPickup">
        <h3>自提人信息</h3>
        <p>自提人姓名：{{ goodsData.orderSelfPickup.receiverName }}</p>
        <p>自提人手机号：{{ goodsData.orderSelfPickup.receiverPhone }}</p>
        <!-- <p>自提人联系地址：{{ goodsData.self_take.self_pick_address_str }}</p> -->
        <template v-if="goodsData.orderSelfPickup">
          <h3>自提点信息</h3>
          <p>
            自提点名称：{{ goodsData.orderSelfPickup.pointName }}
          </p>
          <p>
            自提点店长姓名：{{
              goodsData.orderSelfPickup.receiver
            }}
          </p>
          <p>
            自提点联系电话：{{ goodsData.orderSelfPickup.phone }}
          </p>
          <p>
            自提点联系地址：{{
              goodsData.orderSelfPickup.address
            }}
          </p>
        </template>
      </div>
    </div>
    <div v-if="dataList.length == 0" class="no-data">暂无数据</div>
  </div>
</template>

<script>
import { getOrderByVerificationCode, pickUpVerification } from '@/api/order.js'
export default {
  data () {
    return {
      params: {
        verificationCode: null
      },
      tableLoading: false,
      btnshow: false,
      dataList: [],
      goodsData: null
    }
  },
  components: {},
  created () { },
  methods: {
    loadList () {
      if (this.params.verificationCode) {
        this.tableLoading = true
        getOrderByVerificationCode(this.params)
          .then((res) => {
            if (res && res.code == 200) {
              this.tableLoading = false
              this.dataList = res.data.orderDetails
              this.btnshow = true
              this.goodsData = res.data
            } else {
              this.tableLoading = false
            }
          })
          .finally((res) => {
            this.tableLoading = false
          })
      } else {
        this.$message.warning('请输入核销码')
      }
    },
    inputFun () {
      this.btnshow = false
    },
    addOrUpdateHandle () {
      if (this.params.verificationCode) {
        pickUpVerification(this.params).then((res) => {
          if (res && res.code == 200) {
            this.$message.success('核销成功！');
            this.btnshow = false;
          }
        })
      } else {
        this.$message.warning('请输入核销码')
      }
    },


    /**
     * 没有发货直接退款
     * */

    refund (id) {
      console.log(id)
      this.$confirm('确认是否退款？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          orderService.orderRefund(id).then((res) => {
            if (res.data && res.data.code == 200) {
              this.$message.success('退款成功！')
              this.loadList()
            }
          })
        })
        .catch(() => { })
    }
  }
}
</script>
<style scoped lang="scss">
.mt30 {
  margin-top: 30px;
}

.good-img-div {
  .table-img {
    width: 85px;
    height: 85px;
    display: flex;
  }
}

.flex_bet {
  display: flex;
  justify-content: space-between;
}

.title-div {
  padding: 0 30px;
  height: 40px;
  background-color: #e5e5e5;
  color: #333333;
  line-height: 40px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
}

.tc {
  text-align: center;
}

.table-data {
  width: 80%;
  margin: 0 auto;
  .alipay {
    color: #009fe8;
  }

  .wechatpay {
    color: #1aad19;
  }

  .platformpay {
    color: #17b3a3;
  }

  > div {
    border: 1px solid #f0f0f0;
  }

  .table-content {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #f0f0f0;

    > div {
      min-width: 15%;
    }

    .goods-info {
      display: flex;
      align-items: center;
      width: 100%;

      .info {
        text-align: left;
        margin-left: 10px;
        width: 60%;
      }

      .goods-title {
        font-size: 14px;
        height: 30px;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        overflow: hidden;
      }

      .remark {
        font-size: 12px;
        color: #b1b1b1;
      }

      .price {
        font-size: 14px;
        color: #f3415f;
        margin-bottom: 15px;
        display: flex;
        align-items: center;

        i {
          cursor: pointer;
        }
      }

      .price > input {
        border: none;
        color: #f3415f;
        width: auto;
        width: 50%;
        padding: 5px;
        margin: 0 2px;
        box-sizing: border-box;
        // transition: all .3s;
      }

      input:focus {
        outline: unset;
      }
    }
  }

  .table-foot {
    height: 40px;
    text-align: right;
    color: #333333;
    line-height: 40px;
    font-size: 14px;
    padding: 0 15px;

    .price {
      color: #f3415f;
    }

    .freight {
      color: #b1b1b1;
      margin-right: 10px;
    }
  }
}

.ml10 {
  margin-left: 10px;
}

.can-input {
  border: 1px solid #dfdfdf !important;
  border-radius: 2px;
}
.cosstype {
  text-align: center;
  div {
    margin-bottom: 15px;
  }
}

.pickUp {
  padding: 0 20px;
  font-size: 14px;
}
.no-data {
  text-align: center;
  color: #909399;
  margin: 20px auto;
}
h3 {
  font-weight: 700;
}
</style>
