<template>
  <div>
    <el-row class="handle-box" style="margin-bottom: 10px">
      <el-col :span="8">
        <div class="Pageform">
          <div class="formlabel">买受人</div>
          <div class="formvalue">
            <el-input v-model="search.buyerName" class="ch-input ch-input-size" placeholder="买受人" size="small" @keyup.enter.native="handleSearch()" />
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="Pageform">
          <div class="formlabel">房屋</div>
          <div class="formvalue">
            <el-input v-model="search.houseName" class="ch-input ch-input-size" placeholder="房号" size="small" @keyup.enter.native="handleSearch()" />
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="Pageform">
          <div class="formlabel">身份证</div>
          <div class="formvalue">
            <el-input v-model="search.buyerIdentityCard" class="ch-input ch-input-size" placeholder="身份证" size="small" @keyup.enter.native="handleSearch()" />
          </div>
        </div>
      </el-col>
      <el-col :span="8">
        <div class="Pageform">
          <div class="formlabel">批次号</div>
          <div class="formvalue">
            <el-input v-model="search.batchNumber" class="ch-input ch-input-size" placeholder="批次号" size="small" @keyup.enter.native="handleSearch()" />
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row class="handle-box" style="margin-bottom: 10px;text-align: right">
      <el-col :span="24" style="margin-top: 20px">
        <el-button size="small" class="ch-button-warning" @click="handleReset()"><i class="el-icon-refresh" />&nbsp;重置</el-button>
        <el-button size="small" class="ch-button" @click="handleSearch()"><i class="el-icon-search" />&nbsp;查询</el-button>
      </el-col>
    </el-row>
    <el-row class="handle-box">
      <el-col :span="24">
        <el-table
          v-loading="loading"
          :data="AllData"
          row-class-name="g_table_row"
          border
          :header-cell-style="{background:'#f2f2f2'}"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column type="index" width="60" />
          <el-table-column label="批次号" prop="number" />
          <el-table-column label="买受人" prop="buyerName" width="200" />
          <el-table-column label="房屋" prop="houseName" width="200" />

          <el-table-column label="票据类型" prop="receiptTypeStr" />
          <el-table-column label="票面金额" prop="receiptMoney" />
          <el-table-column label="票据编号" prop="receiptNumber" width="200">
            <template scope="scope">
              <el-button size="mini" type="text" @click="downLoad(scope.row)">
                {{ scope.row.receiptNumber }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="经办人" prop="createdName" />
          <el-table-column label="经办时间" prop="createdAt" width="110" />
          <el-table-column label="票据状态" prop="receiptStatusStr">
            <template scope="scope">
              <span
                :style="{'color':scope.row.receiptStatusStr==='已红冲'?'red'
                  :scope.row.receiptStatusStr==='已开'?'green':'gray'}"
              >
                {{ scope.row.receiptStatusStr }}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="关联票号" prop="associationNumber" width="200">
            <template scope="scope">
              <el-button size="mini" type="text" @click="downLoad(scope.row)">
                {{ scope.row.associationNumber }}
              </el-button>
            </template>
          </el-table-column>

        </el-table>
        <div class="table-page">
          <el-pagination
            :current-page.sync="currentPage"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            background
            layout="total, sizes, prev, pager, next, jumper"
            :total="allpage"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </el-col>
    </el-row>

  </div>
</template>
<script>
import Base from '@/views/base/base'
import BaseData from '@/views/base/baseData'
import constant from '@/static/utils/constant'

export default {
    name: 'ReceiptManage',
    components: { },
    mixins: [Base, BaseData],
    data() {
        return {
            dc_key: ['RECEIPT_TYPE', 'RECEIPT_STATUS'],
            // 列表相关
            search: {
            },
            AllData: [],
            loading: false,
            // 弹框相关
            dialogVisible: false,
            dialogTitle: '新增',
            selected: [],
            excelFlag: false,
            dialogBatchVisible: false,
            dialogBatchTitle: ''
        }
    },
    mounted() {
        this.initDict(this.dc_key).then((res) => {
            this.getData()
        })
    },
    methods: {

        getData: function() {
            const _this = this
            _this.loading = true
            _this.AllData = []

            this.search.pageNum = this.currentPage
            this.search.pageSize = this.pageSize
            this.baseRequest('listByModel', this.search).then((res) => {
                if (res.data.rows) {
                    res.data.rows.forEach(function(item) {
                        const json = _this.getItemJson(item)
                        _this.AllData.push(json)
                    })
                    _this.allpage = res.data.total
                }
                _this.loading = false
            }).catch((e) => {
                // console.log(e)
            })
            // this.initOutData()
        },
        handleSearch: function() {
            this.getData()
        },
        handleReset: function() {
            for (const i in this.search) {
                if (i !== 'pageNum' && i !== 'pageSize') {
                    this.search[i] = ''
                }
            }
            this.handleSearch()
        },
        getItemJson: function(item) {
            item.number = item.batchNumber + '-' + item.roomSelectionNumber
            item.receiptTypeStr = this.dc_map.RECEIPT_TYPE[item.receiptType]
            item.receiptStatusStr = this.dc_map.RECEIPT_STATUS[item.receiptStatus]
            return item
        },

        handleView(val) {

        },
        handleSelectionChange(val) {
            this.selected = val
        },
        cancel: function() {
            this.dialogVisible = false
        },
        downLoad(row) {
            const url = constant.BASE_URI + '/ReceiptManageController/downLoadReceipt?id=' + row.id
            window.open(url, '_blank')
        },
        baseRequest(opUrl, postData) {
            return this.$channel.globeRequest('ReceiptManageController', opUrl, postData, 'project')
        }
    }
}
</script>
<style lang="scss">
.Pageform{
    display: flex;
    align-items: center;
    .formlabel{
        width: 15%;
        text-align: right;
        font-size:14px ;
    }
    .formvalue{
        width: 75%;
        display: flex;
        margin-left: 2%;
        .ch-input{
            width: 100%;
        }
        .zhi{
            width: 60px;
            text-align: center;
        }
    }
}
</style>
<style scoped>
  .ch-input .el-input__inner {
      border-color: #32323A;
  }
  .ch-input-size {
      width: 150px;
  }
  .ch-button {
      border-color: #32323A;
      background-color: #32323A;
      color: #fff;
  }
  .ch-button-warning {
      margin-left: 10px;
      border-color: #E6A23C;
      background-color: #E6A23C;
      color: #fff;
  }
  .ch-button-export {
      margin-left: 10px;
      border-color: #98CC1F;
      background-color: #98CC1F;
      color: #fff;
  }
  /deep/.el-dialog__header {
      padding: 10px 20px;
  }
  /deep/.el-dialog__body {
      padding: 10px 20px;
  }
</style>
