<template>
  <div>
    <el-dropdown @command="handleClick">
      <span class="el-dropdown-link">
        操作<i class="el-icon-arrow-down el-icon--right"></i>
      </span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item v-if="isShowDetail" :command="beforeGoDetail(params.goodsId)">查看详情</el-dropdown-item>
        <el-dropdown-item divided :command="beforeCopy(params.url)">复制商品</el-dropdown-item>
        <el-dropdown-item divided :command="beforeGoWeb(params.url)">访问商品</el-dropdown-item>
        <el-dropdown-item :command="beforeGoMal(params.mallId)">访问店铺</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>

    <ai-dialog
      title="复制"
      :visible.sync="copyFromDlgShow"
      :close-on-click-modal="false"
      width="790px"
      customFooter
      :append-to-body="true"
      @close="handleClose">
      <ai-copy-from-temu v-if="copyFromDlgShow" :params="temuParams" @onClose="handleClose" @onSuccess="handleSuccess"></ai-copy-from-temu>
    </ai-dialog>
  </div>
</template>
<script>
import AiCopyFromTemu from "./AiCopyFromTemu.vue";
export default {
  name: "AiProductDropDown",
  components: {AiCopyFromTemu},
  props: ['params', 'isShowDetail'],
  data() {
    return {
      info: {},
      copyFromDlgShow: false,
      temuParams: {}
    }
  },
  computed: {
  },
  created() {
  },
  methods: {
    handleClick(e) {
      if (e.type == 'detail') {
        this.$emit('onGoDetail')
      } else if (e.type == 'copy') {
        this.temuParams = {url: 'https://www.temu.com/' + e.url}
        this.copyFromDlgShow = true
      } else if (e.type == 'goMall') {
        window.open('https://www.temu.com/mall.html?mall_id=' + e.mallId, '_blank');
      } else if (e.type == 'goWeb') {
        console.log(e.url)
        window.open('https://www.temu.com/' + e.url, '_blank');
      }
    },
    beforeGoDetail(goodsId) {
      return {type: 'detail', goodsId: goodsId}
    },
    beforeCopy(url) {
      return {type: 'copy', url: url}
    },
    beforeGoMal(mallId) {
      return {type: 'goMall', mallId: mallId}
    },
    beforeGoWeb (url) {
      return {type: 'goWeb', url: url}
    },
    handleClose() {
      this.copyFromDlgShow = false
    },
    handleSuccess() {
      this.copyFromDlgShow = false
    }
  }
}
</script>
<style scoped lang="scss">
</style>
