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: 'report',
  components: { breadcrumbComponent, tableComponent, picUploaderComponent, QRCode },
  mixins: [list,routerUserMenu],
  data () {
    return {
      // 下拉项
      reportIfFinishOptions: [],
      reportLevelOptions:[],

      // 搜索表单信息
      searchForm: {
        reportLevel: '',
        ifFinish: '',
        reportName: '',
        pageSize: 10,
        page: 1,
      },

      // 列表数据
      tableData: {
        data: [],
        total: 0
      },
      // 列表设置
      tableOption: {
        // 是否显示序号
        index: true,
        // 是否显示勾选框
        select: false,
        // 默认排序
        defaultSort: {prop: 'updateTime' ,order: 'descending' },
        // 列
        tableLabel: [
          {prop: 'reportName', title: '报表名称', sort: true},
          {prop: 'reportLevelValue', title: '报表层级', sort: true},
          {prop: 'updateTime', title: '修改时间', sort: true},
          {prop: 'updateUserName', title: '修改人' },
          {prop: 'ifFinishValue', title: '完成状态' ,colorOption:{depend: 'ifFinish',option:{1: 'safe', 0: 'warn'}} },
          {prop: 'statusValue', title: '状态' ,colorOption:{depend: 'status',option:{1: 'safe', 0: 'warn'}}},
        ],
        // 操作
        tableOperate: {
          width: '220',
          buttons: [
            {label: '预览', methods: 'view', show:{ifFinish: 1}},
            {label: '修改', methods: 'edit',color: 'safe', show:{status: 0}},
            {label: '授权', methods: 'access',color: 'link', show:{ifFinish: 1}},
            {label: '启用', methods: 'continue',color: 'safe', show:{ifFinish: 1,status: 0}},
            {label: '停用', methods: 'discontinue',color: 'warn', show:{ifFinish: 1,status: 1}},
            {label: '删除', methods: 'del',color: 'warn', show:{status: 0}},
          ]
        },
      },
    }
  },
  created(){
  },
  mounted () {
    // 获取客户列表
    this.init()
  },
  methods: {
    init(){
      /* 报表状态 */
      this.$api.report.listType({id:14}).then(res=>{
        if(res.code==='1'){
          this.reportIfFinishOptions=res.data
        }
      })

      /* 报表层级 */
      this.$api.report.listType({id:8}).then(res=>{
        if(res.code==='1'){
          this.reportLevelOptions=res.data
        }
      })
    },
    /* 启用 */
    continue(obj){
      let params={
        id: obj.id,
        status: 1
      }
      this.$api.report.status(params).then(res=>{
        if (res.code == 1) {
          this.$message.success(res.msg)
          this.getList()
        }
      })
    },
    /* 停用 */
    discontinue(obj){
      let params={
        id: obj.id,
        status: 0
      }
      this.$api.report.status(params).then(res=>{
        if (res.code == 1) {
          this.$message.success(res.msg)
          this.getList()
        }
      })
    },
    /* 查看详情 */
    detail(obj){},
    // 获取列表页列表
    getList () {
      let params = this.searchForm

      this.$api.report.list(params)
        .then(res => {
          if (res.code == 1) {
            this.tableData.data = res.data
            this.tableData.total=res.totalNumber
          }
        })
    },

    // 执行删除
    delAction(obj){
      let params={id: obj.id}
      this.$api.report.deleteById(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('ReportEdit',{id: obj.id})
    },
    /* 查看 */
    view(obj){
      this.go('AutomaticReport',{id: obj.id})
    },
  //  授权
    access(obj){
      this.go('SignalReportAccess',{id: obj.id, name: obj.reportName})
    }
  }
}
