<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" @click="checkPre">批量审核</el-button>
      <el-button :size="sizeType" type="danger" @click="uncheckPre">批量退回</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"
      stripe
      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"
          sortable="custom"
          fixed
          show-overflow-tooltip>
          <template slot-scope="{row}">
            <a href="javascript:;" style="color: #20a0ff" @click.stop="getOrderStep(row)">{{ row[column.field] }}
              <span v-if="row.businessKind==3" style="display: inline-block;color: red">(补{{ row.rePrintIndex}})</span>
              <el-image v-if="row.firstOrderFlag == 1" :src="new_badge"></el-image></a>
          </template>
        </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] == 1" type="info">待入账</el-tag>
            <el-tag v-else-if="row[column.field] == 2" type="warning">已入账</el-tag>
            <el-tag v-else-if="row[column.field] == 11" type="danger">审核作废</el-tag>
            <el-tag v-else-if="row[column.field] == 12" type="danger">入账作废</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          v-else-if="column.id == 6"
          header-align="center"
          :prop="column.field"
          :label="column.name"
          :width="column.width">
          <template slot-scope="{row}">
            <template v-if="row.orderMessage">
              <a href="javascript:;" style="color: #20a0ff" @click="openMessage(row)">{{row.orderMessage}}</a>
              <el-button size="mini" type="primary" style="float: right" icon="el-icon-plus" @click="openMessage(row)"></el-button>
            </template>
            <template v-else>
              <el-button size="mini" type="primary" icon="el-icon-plus" @click="openMessage(row)"></el-button>
            </template>
          </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"/>
    <el-dialog title="预收款审核退回" :visible.sync="voidVisible" width="500">
      <el-form label-width="80px" label-position="right">
        <el-form-item label="退回备注">
          <el-input type="textarea" v-model="sMemo"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="voidVisible = false">取 消</el-button>
        <el-button type="primary" @click="uncheckBtnFun">确 定</el-button>
      </div>
    </el-dialog>
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
    <order-step ref="orderStep"></order-step>
  </div>

</template>

<script>
import { getOrderPrePayList, unCheckOrderPrePay } from '@/api/order/depositAudit'
import Cancledialog from '@/components/Dialog/Cancledialog.vue'
import OrderStep from "@/components/orderStep/orderStep";

const defaultItems = [
  {
    name: '订单编号', id: 3, field: 'orderCode', width: '125px'
  },
  {
    name: '印品名称', id: 10, field: 'orderName', width: '190px'
  },
  {
    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: 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: 'DepositAudit',
  components: {
    OrderStep,
    Cancledialog
  },
  data() {
    return {
      sizeType: 'mini',
      detailVisible: false,
      pluploadVisible: false,
      memoDrawer: false,
      defaultItem: Object.assign([], defaultItems), // 默认列
      orderStatus: '',
      search: {
        keyWord: '',
        billState: 0
      },

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

      listLoading: false,
      listData: {
        total: 0,
        page: 1,
        pageSize: 20
      },
      selectedVal: [],

      voidVisible: false,
      sMemo: ''
    }
  },
  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)
      this.selectedVal = val
    },
    // 获取脚印
    getOrderStep(row) {
      const _that = this
      _that.$refs.orderStep.idOrder = row.id
      _that.$refs.orderStep.getOrderStep()
    },
    // 刷新变革
    tableRefresh() {
      // 刷新变革
      this.getList()
    },
    handleClickTableRow(row, event, column) {
      // console.log(row);
      // console.log(column);
      this.$refs.orderTable.toggleRowSelection(row)
    },
    // 批量审核
    checkPre() {
      var _that = this
      if (_that.selectedVal.length > 0) {
        var idArr = [];
        (_that.selectedVal).forEach((item) => {
          idArr.push(item.id)
        })
        // console.log(idArr)
        var params = {
          'ids': idArr.join(',')
        }
        // console.log(params);
        var url = '/order/v1/checkOrderPrePay'
        _that.$refs.confirmDialog.updataClick(params, url)
      } else {
        _that.$message.error('请先选择审核订单')
      }
    },
    // 批量退回
    uncheckPre() {
      var _that = this
      if (_that.selectedVal.length > 0) {
        _that.voidVisible = true
        _that.sMemo = ''
      } else {
        _that.$message.error('请先选择退回订单')
      }
    },
    // 退回确认
    uncheckBtnFun() {
      var _that = this
      var idArr = [];
      (_that.selectedVal).forEach((item) => {
        idArr.push(item.id)
      })
      // console.log(idArr)
      var data = {
        'ids': idArr.join(','),
        'sMemo': _that.sMemo
      }
      unCheckOrderPrePay(data).then(response => {
        console.log(response)
        if (response.httpCode == 200) {
          _that.$message({
            message: '退回成功',
            type: 'success'
          })
        }
      }).catch(err => {
        _that.$message.error(err)
      })
    }

  }
}
</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>
