<!--
  @description:再次购买--购物车
  @Modifier: haofengxian
  @routerPath:
  @date: 2021-12-05 16:29
-->
<template>
  <div>
    <el-dialog
      v-if="visibleDialog"
      :visible.sync="visibleDialog"
      :fullscreen="true"
      custom-class="shop_mall_dialog"
      title="再次购买"
    >
      <shoppingCartComp :list="list" :loading="loading" buyer-type="03" @getCartList="initData" @onceAgainPurchaseSubmit="submit" />
      <!--      <span slot="footer" class="dialog-footer">
        <el-button @click="visibleDialog = false">关 闭</el-button>
      </span>-->
    </el-dialog>
    <!--结算页-->
    <onceAgainPurchaseSettleDialog ref="onceAgainPurchaseSettle" />
  </div>
</template>

<script>
// api
import { buyAgainFromBackCollections } from '@/api/shoppingmall/order'
import headerSearch from '../../shoppingcart/headerSearch' // 头部组件
import shoppingCartComp from '../../shoppingcart/shoppingCartComp' // 购物车组件
import onceAgainPurchaseSettleDialog from './onceAgainPurchaseSettle-dialog' // 再次购买结算

export default {
  name: 'OnceAgainPurchaseCart',
  components: {
    headerSearch, // 头部组件
    shoppingCartComp, // 购物车组件
    onceAgainPurchaseSettleDialog
  },
  data() {
    return {
      loading: false,
      visibleDialog: false,
      list: [],
      selectOrderIds: [] // 再次购买
    }
  },
  methods: {
    // 打开弹框
    openDialogGetMyCartList(selectOrderIds) {
      this.visibleDialog = true
      this.selectOrderIds = selectOrderIds
      this.initData()
    },
    // 初始化数据
    initData() {
      this.loading = true
      const onceAgainPurchaseParams = {
        orderDetailIds: this.selectOrderIds
      }
      buyAgainFromBackCollections(onceAgainPurchaseParams).then(res => {
        this.list = res.data ?? []
        this.list.forEach((item) => {
          item.checked = false
          item.productsList.forEach((chidren) => {
            chidren.checked = false
          })
        })
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 下单
    submit() {
      this.$refs.onceAgainPurchaseSettle.openDialogSettle()
    }
  }
}
</script>

<style scoped lang="less">
/deep/.cart_null {
  text-align: center;
  padding-top: 30vh;
}
/deep/.shopping_cart_wrap {
  margin-top: 10px;
  margin-bottom: 10px;
  min-height: calc(100vh - 100px);
}
</style>
