<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input :size="sizeType" v-model.trim="search.orderCode" placeholder="平台单号" style="width: 200px;"
                class="filter-item"/>

      <el-button :size="sizeType" class="filter-item" type="success" icon="el-icon-check" @click="addPdf">
        生成设计PDF
      </el-button>
      <el-button :size="sizeType" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getScriptInfo" />
        </el-tooltip>
      </div>
    </div>
    <el-table
      :data="tableData"
      :size="sizeType"
      v-loading="listLoading"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all>
      <el-table-column
        prop="createTime"
        label="创建时间">
        <template slot-scope="{row}">
          <span v-if="row.createTime">
          {{ row.createTime | getTime }}
            </span>
        </template>
      </el-table-column>
      <el-table-column
        label="设计模板"
        prop="designTemplateName"
      ></el-table-column>
      <el-table-column
        label="平台单号"
        prop="orderCode"
      ></el-table-column>

      <el-table-column
        label="生成次数"
        prop="pdfCount"
      ></el-table-column>

      <el-table-column
        label="设计文件下载"
      >
        <template slot-scope="{row}">
          <el-link v-if="row.pdfFileUrl" type="primary" :href="row.pdfFileUrl+'?filename='+row.orderCode+'.pdf'" target="_blank">下载文件</el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getScriptInfo" />
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
  </div>
</template>


<script>
import { selectcupDraw } from '@/api/system/myTask'
import { testCupOrderPdf } from '@/api/system/myTask'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'
const form = {
  businessName: '',
  businessCode: '',
  businessModule: ''
}
export default {
  components: {
    Cancledialog
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        1: 'success',
        0: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      sizeType: 'mini',
      dialogStatus: 1, // 1增加，2修改
      dialogTitle: '',
      dialogVisible: false,
      search: {
        keyWord: '',
        orderCode:""
      },
      form: Object.assign({}, form),
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      options: [],
      moduleOptions: [],

      confirmdialog: false,
      listLoading: false,
      tableData: [],
      menuId: ''
    }
  },
  mounted() {
    this.getScriptInfo()
  },
  methods: {
    searchData(){
      this.tableRefresh();
    },
    addPdf(){
      const _that = this;
      var data = {
        orderCode:_that.search.orderCode
      }
      testCupOrderPdf(data).then(response => {
        _that.$message.success("成功");
        _that.getScriptInfo()

      }).catch(err => {

      })
    },
    // 获取列表
    getScriptInfo() {
      const _that = this
      _that.listLoading = true
      _that.search.keyWord = _that.search.orderCode;
      var params = _that.search
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }
      if (_that.listData.pageSize == 10) {
        _that.sizeType = 'medium'
      } else {
        _that.sizeType = 'mini'
      }
      selectcupDraw(data).then(response => {
        const data = response.data
        // //  组合表单数据
        _that.tableData = data

        _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.listLoading = false
      })
    },
    // testCupOrderPdf(data) {
    //   orderCode:
    // },
    // 刷新表格
    tableRefresh() {
      this.getScriptInfo()
    }
  }
}
</script>

<style lang="scss" scoped>
.filter-container {
  margin-bottom: 15px;
}
</style>
