<template>
  <div class="app-container">
    <div class="filter-container">
      <el-select :size="sizeType" v-model="search.billState">
        <el-option
          v-for="item in stateOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value"></el-option>
      </el-select>
      <el-input :size="sizeType" v-model="search.keyWord" placeholder="关键字" style="width: 200px;" class="filter-item"/>
      <el-button :size="sizeType" class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <el-button :size="sizeType" type="green">批量入账</el-button>
      <el-button :size="sizeType" type="danger">批量作废</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="getList"/>
        </el-tooltip>
      </div>
    </div>
    <el-table
      :size="sizeType"
      :data="tableData"
      v-loading="listLoading"
      row-key="id"
      border
      style="margin-top: 10px"
      ref="orderTable"
      @row-click="handleClickTableRow"
      @selection-change="handleSelectionChange"
      default-expand-all>
      <el-table-column
        type="selection"
        fixed="left"
        width="55">
      </el-table-column>
      <el-table-column
        label="序号"
        fixed
        align="center"
        width="50"
        type="index">
        <template slot-scope="scope">
          <span>{{(listData.page - 1) *listData.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <template v-for="column in defaultItem">
        <el-table-column
          v-if="column.id == 3"
          :prop="column.field"
          :label="column.name"
          :width="column.width"
          fixed
          show-overflow-tooltip></el-table-column>
        <el-table-column
          v-else-if="column.id == 21"
          :prop="column.field"
          :label="column.name"
          :width="column.width">
          <template slot-scope="{row}">
            <el-tag v-if="row[column.field] == 0">待审核</el-tag>
            <el-tag v-else-if="row[column.field] == 2" type="danger">待入账</el-tag>
            <el-tag v-else-if="row[column.field] == 3" type="warning">已入账</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="column.id == 2 || column.id == 4 || column.id == 5"
          header-align="center"
          :prop="column.field"
          :label="column.name"
          :width="column.width"
        >
          <template slot-scope="{row}">
            <span v-if="row[column.field]">
          {{ row[column.field] | getTime }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          v-else
          :prop="column.field"
          :label="column.name"
          :width="column.width"
          show-overflow-tooltip>
        </el-table-column>
      </template>
    </el-table>
    <pagination v-show="listData.total>0" :total="listData.total" :page.sync="listData.page" :limit.sync="listData.pageSize" @pagination="getList"/>
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
  </div>

</template>

<script>
import { getOrderPrePayList } from '@/api/order/depositAudit'
import orderMessage from '@/components/orderMessage/orderMessage'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'

const defaultItems = [
  {
    name: '订单编号', id: 3, field: 'orderCode', width: '125px'
  },
  {
    name: '预付款金额', id: 1, field: 'prePayMoney', width: '160'
  },
  {
    name: '制单时间', id: 2, field: 'orderCreateTime', width: '160'
  },
  {
    name: '预收款审核状态', id: 21, field: 'billState', width: '100px'
  },
  {
    name: '客户编码', id: 7, field: 'clientCode', width: '100'
  }, {
    name: '客户名称', id: 8, field: 'clientName', width: '120'
  },
  {
    name: '订单名称', id: 10, field: 'orderName', width: '190px'
  },
  {
    name: '申请人', id: 11, field: 'createMan', width: '75'
  },
  {
    name: '申请时间', id: 4, field: 'createTime', width: '160'
  },
  {
    name: '审核人', id: 12, field: 'editMan', width: '75'
  },
  {
    name: '审核时间', id: 5, field: 'editTime', width: '160'
  },
  {
    name: '订单印量', id: 14, field: 'orderQty', width: '120'
  },
  {
    name: '总金额', id: 17, field: 'orderMoneyTotal', width: '120'
  },
  {
    name: '申请说明', id: 20, field: 'prePayMemo', width: '220px'
  }
]
export default {
  name: 'DepositEntry',
  components: {
    Cancledialog
  },
  data() {
    return {
      sizeType: 'mini',
      detailVisible: false,
      pluploadVisible: false,
      memoDrawer: false,
      defaultItem: Object.assign([], defaultItems), // 默认列
      orderStatus: '',
      search: {
        keyWord: '',
        billState: 1
      },

      stateOptions: [
        {
          label: '待入账',
          value: 1
        },
        {
          label: '已入账',
          value: 2
        },
        {
          label: '入账作废',
          value: 12
        }
      ],
      tableData: [],

      listLoading: false,
      listData: {
        total: 0,
        page: 1,
        pageSize: 20
      },
      voidVisible: false,
      sMemo: '',
      orderId: '',

      // 上传文件
      showUpload: true,
      files: [],
      upIdOrder: '',
      upOrderCode: '',
      confirmdialog: false
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      var _that = this
      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'
      }
      // console.log(data);
      getOrderPrePayList(data).then(response => {
        console.log(response)
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total
        // console.log(_that.tableData)
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    // 搜索
    searchData() {
      this.listData.page = 1
      this.getList()
    },
    handleSelectionChange(val) {
      console.log(val)
    },

    // 刷新变革
    tableRefresh() {
      // 刷新变革
      this.getList()
    },
    // 审核
    backOrderBtn() {
      var _that = this
      var data = {
        'id': _that.orderId,
        'sMemo': _that.sMemo,
        'orderState': _that.orderState
      }
      backPrintOrder(data).then(response => {
        console.log(response)
        if (response.httpCode == 200) {
          _that.voidVisible = false
          _that.$message({
            message: '退回成功',
            type: 'success'
          })
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    },
    // 点击行内任何地方选中
    handleClickTableRow(row, event, column) {
      // console.log(row);
      // console.log(column);
      this.$refs.orderTable.toggleRowSelection(row)
    },

  }
}
</script>
<style>
/*1.显示滚动条：当内容超出容器的时候，可以拖动：*/
.el-drawer__body {
  overflow: auto;
}
.stepList .el-card__body{
  padding: 10px;
}
:focus{
  outline:0;
}
</style>

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