<template>
  <div class="app-container">
    <div v-if="orderNoteList.length === 0" class="order_empty">
      <span>暂无订单备注</span>
      <!-- <el-button type="primary" @click="handlePayNote">添加备注</el-button> -->
    </div>
    <div v-else>
      <!-- <div class="filter-container" style="text-align: right; padding: 0;">
        <el-button type="primary" @click="handlePayNote">添加备注</el-button>
      </div> -->
      <el-card v-for="item in orderNoteList" :key="item.id" class="box-card" style="margin: 0 auto;">
        <div class="refund-item">
          <el-form label-width="120px">
            <el-form-item :label="item.createName">
              <div class="order_time">
                {{ item.createDate }}
              </div>
            </el-form-item>
            <el-form-item label="备注内容：">
              {{ item.remarks }}
            </el-form-item>
            <el-form-item label="图片：">
              <el-image v-for="(img, index) in item.images" :key="index" :preview-src-list="[img]" style="width: 148px;height: 148px;margin-right: 20px;" :src="img" />
            </el-form-item>
            <el-form-item label="文件：">
              <div v-for="file, i in item.ossFiles" :key="i">
                <span class="order_text">{{ file.name }}</span>
                <el-button type="text" @click="handlerDownload(file)">下载</el-button>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
      <div class="goBack">
        <el-button plain @click="backToList">返回</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { orderNotes, fileDownload } from '@/api/order'
export default {
  name: 'OrderRemarks',
  filters: {
  },
  data() {
    return {
      orderInfo: {},
      productRadio: null,
      orderNoteList: [] // 订单备注列表
    }
  },
  computed: {
    orderId: function() {
      return this.$route.query.orderId * 1
    },
    disabled() {
      return this.productRadio === null
    },
    shopOrderId() {
      return this.$route.query.shopOrderId * 1
    }
  },
  created() {
    this.orderNotes({ orderId: this.orderId, shopOrderId: this.shopOrderId })
  },
  methods: {
    // 获取订单备注列表
    async orderNotes(orderId) {
      try {
        const { data } = await orderNotes(orderId)
        this.orderNoteList = data
      } catch (error) {
        console.log('error', error)
      }
    },
    // 文件下载
    async handlerDownload(res) {
      try {
        const response = await fileDownload({ fileId: res.id })
        // 获取文件流数据
        const blob = new Blob([response])
        const link = document.createElement('a')
        link.href = URL.createObjectURL(blob)
        link.download = res.name
        document.body.appendChild(link)
        link.click()
        document.body.removeChild(link)
      } catch (error) {
        console.log(error)
      }
    },
    handlePayNote() {
      this.$router.push({ path: '/order/add-remarks', query: { orderId: this.orderId }})
    },
    backToList() {
      this.$store.dispatch('tagsView/delView', this.$route).then(() => {
        this.$nextTick(() => {
          this.$router.replace({
            path: '/order/deliver',
            query: {
              orderId: this.orderId
            }
          })
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.order_empty {
  width: 100%;
  height: 40vh;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.order_empty span {
  color: #409EFF;
  margin: 1vw;
}
.order_time {
  font-weight: 700;
}
.order_text {
  margin-right: 20px;
}
.goBack {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
::v-deep .el-form-item__content {
  margin-left: 130px !important;
}
.goBack {
  margin: 3vw 0;
  ::v-deep .el-button--medium {
    width: 100px !important;
  }
}
::v-deep .el-card {
  margin: 20px auto !important;
}
  .app-title{
    line-height: 36px;
    font-size: 26px;
    font-weight: bold;
    color: #409EFF;
    text-align: center;
    margin: 0;
  }
  .box-card{
    font-size: 14px;
  }
  .box-row{
    padding: 10px 0;
  }
  .box-row .dropdown{
    margin-top: -10px;
  }
  .refund-item{
    padding: 10px 0;
  }
  .order-item{
    background:#f7f7f7;
    margin-bottom: 20px;
    padding: 10px 15px;
    border-radius: 5px;
  }
  .product-row{
    padding: 10px 0;
    background: #EBEEF5;
    border-top: 1px dashed #DCDFE6;
  }
  .op-item{
    padding: 5px 0;
  }
  .el-span-warning{
    color: #E6A23C;
  }
  .el-span-success{
    color: #67C23A;
  }
  .el-span-danger{
    color: #F56C6C;
  }
</style>

