import list from '@/mixins/list'
import routerUserMenu from '@/mixins/router-user-menu'
import breadcrumbComponent from '@/components/breadcrumb.vue'
import tableComponent from '@/components/table.vue'
import picUploaderComponent from '@/components/picuploader.vue'
// import {copyObjByJson,randomStr} from '@/utils/tools'
import QRCode from "qrcode"

/**
 * 列表页管理
 *
 *  version = "1.0.0";
 *  author = "徐飞";
 *  email = "xu.fei@data-u.com";
 * */
export default {
  name: 'chart',
  components: { breadcrumbComponent, tableComponent, picUploaderComponent, QRCode },
  mixins: [list,routerUserMenu],
  data () {
    return {
      topicList: {
        subjectListUp: [],
        subjectListDown: []
      },
      chartTypeOptions: [],
      chartsType: '',
      videoUrl: '',
      imgSrc: '',
      richText: '',
      showDialog: false,
      baiduPoints: [],
      chartJson:{},
      // 搜索表单信息
      searchForm: {
        topicType: '',
        topicName: '',
        pageSize: 10,
        page: 1,
      }
    }
  },
  created () {
  },
  mounted () {
    // 获取客户列表
    this.init()
  },
  methods: {
    init () {
      this.getList()
    },
    /* 元素编辑 */
    editDom (obj) {
      this.go('ChartSet', {id: obj.id})
    },
    /* 查看详情 */
    detail (obj) {},
    // 获取列表页列表
    getList () {
      let params = this.searchForm
      this.$api.topicList.list(params)
        .then(res => {
          if (res.code == 1) {
            this.topicList.subjectListUp = res.data.subjectListUp
            this.topicList.subjectListDown = res.data.subjectListDown
          }
        })
    },

    // 执行删除
    delAction (obj) {
      let params = {id: obj.id}
      this.$api.chart.delChartInfo(params)
        .then(res => {
          if (res.code == 1) {
            this.$message.success(res.msg)
            this.getList()
          }
        })
    },
    // 删除
    del (obj) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.delAction(obj)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    // 修改
    edit (obj) {
      this.go('ChartEdit', {id: obj.id})
    },
    /* 查看 */
    showEdit (obj) {
      this.go('ChartView', {id: obj.id, readonly: true})
    },
    // 预览
    view (obj) {
      this.showDialog = true
      let params = {id: obj.id}
      this.$api.chart.chartView(params)
        .then(res => {
          if (res.code == 1) {
            this.chartsType = res.data.chartType
          }
        })
    },
    // dialog 打开时
    openedDlg () {
      let obj = document.getElementsByTagName("embed")
      if (obj.length > 0) {
      }
      // console.log(obj)
    },
    // 图表展示
    showCharts (optionData) {
      let myChart = this.$echarts.init(document.getElementById("previewCharts"))
      // 绘制图表
      optionData = optionData ? JSON.parse(optionData) : {}
      myChart.setOption(optionData)
    },
    // 关闭对话框
    closeDialog () {
      this.showDialog = false
      let previewVedio = document.getElementById("previewVedio")
      if (previewVedio) {
        previewVedio.pause()
      }
    }
  }
}
