<template>
  <div class="app-container">
    <!-- Start 列表页面 -->
    <div>
      <button-bar view-title="出纳付款列表" ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle"/>
      <div class="main-content">
        <div class="searchcon">
          <el-button size="small" class="searchbtn" @click="clicksearchShow">{{ searchxianshitit }}</el-button>
          <div v-show="isSearchShow" class="search">
            <el-form ref="listQueryform" :inline="true" :model="listQuery" class="tab-header">
              <el-form-item label="状态">
                <el-select v-model="listQuery.params.state" placeholder="请选择" clearable class="addinputw">
                  <el-option v-for="item in state_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
              <el-form-item label="款项类别">
                <el-select v-model="listQuery.params.costTypeKey" placeholder="请选择" clearable class="addinputw">
                  <el-option v-for="item in costType_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
              <el-form-item label="款项名称">
                <el-select v-model="listQuery.params.costTitleKey" placeholder="请选择" clearable class="addinputw">
                  <el-option v-for="item in costTitle_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
              </el-form-item>
              <el-form-item label="审批日期">
                <div class="block" style="float: left;">
                  <el-date-picker v-model="listQuery.params.createStartDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
                </div>
                <div style="float: left;margin: 0px 10px">至</div>
                <div class="block" style="float: left;">
                  <el-date-picker v-model="listQuery.params.createEndDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
                </div>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" @click="handleFilter" size="small">查询</el-button>
              <el-button type="primary" @click="handleReset" size="small">重置</el-button>
            </div>
          </div>
        </div>
        <div class="listtop">
          <div class="tit">付款列表</div>
          <pageye v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
        <div class="">
          <el-table :key="tableKey" v-loading="listLoading" :data="list" border style="width: 100%;" @selection-change="handleSelectionChange">
            <el-table-column width="50px" fixed type="selection" align="center"/>
            <el-table-column width="80px" fixed label="序号" type="index" :index="indexMethod" align="center"/>
            <el-table-column label="操作" fixed width="100px" align="center">
              <template slot-scope="scope">
                <el-button type="success" size="mini" @click="handleEdit(scope.row)">办理</el-button>
              </template>
            </el-table-column>
            <el-table-column label="状态" width="140px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.state }}</span>
              </template>
            </el-table-column>
            <el-table-column label="审批日期" align="center">
              <template slot-scope="createTime">
                <span>{{ scope.row.engineTypeValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="业务编号" align="center" width="150px">
              <template slot-scope="scope">
                <span>{{ scope.row.billNo }}</span>
              </template>
            </el-table-column>
            <el-table-column label="款项类别" align="center" width="180px">
              <template slot-scope="scope">
                <span>{{ scope.row.costTypeValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="款项名称" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.costTitleValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收款单位名称" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.receiveCompany }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收款账号" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.receiveBankAccount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="金额" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.cost }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款银行" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.payBank }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款账户" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.payBankAccount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款备注" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.payRemark }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款人" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款日期" align="center" width="130px">
              <template slot-scope="scope">
                <span>{{ scope.row.payDate }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款凭证" align="center" width="180px" class-name="small-padding fixed-width">
              <template slot-scope="scope">
                <el-button size="mini" type="primary" @click="handleGetCheck(scope.row)">查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="pages">
          <!-- 翻页 -->
          <pagination v-show="list.length > 0" :total="listQuery.total" :page.sync="listQuery.current" :limit.sync="listQuery.size" class="pagination" @pagination="getList"/>
        </div>
      </div>
    </div>
    <!-- End 列表页面 -->
    <!-- 照片弹窗 -->
    <el-dialog title="查看" :visible.sync="dialogImgVisible">
      <el-image v-for="item in srcList" style="width: 100px; height: 100px" :src="item"></el-image>
    </el-dialog>
    <el-dialog :visible.sync="dialogVisible" width="50%" center>
      <el-form ref="" :model="formobj" class="formadd" label-position="right">
        <el-row style="border-top: 1px solid #e0e3eb">
          <el-col :span="4">
            <span>付款方式</span>
          </el-col>
          <el-col :span="8">
            <el-select v-model="formobj.payWayValue" placeholder="请选择" clearable>
              <el-option v-for="item in payWay_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
            </el-select>
          </el-col>
          <el-col :span="4">
            <span>付款日期</span>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-date-picker v-model="formobj.createTime" type="date" clearable value-format="yyyy-MM-dd" style="width: 93%" placeholder="请选择日期"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <span>付款银行</span>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-input v-model="formobj.payBank" clearable placeholder="请填写付款银行"/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <span>付款账号</span>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-input v-model="formobj.payBankAccount" clearable placeholder="请填写付款账号"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <span>付款备注</span>
          </el-col>
          <el-col :span="20">
            <el-form-item>
              <el-input v-model="formobj.payRemark" placeholder="请填写备注" clearable/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="4">
            <span>付款凭证</span>
          </el-col>
          <el-col :span="20">
            <el-form-item>
              <upload ref="uploadImg" v-model="diploma_list" :limit="1" bucket="map" :upload-data="{ type: '0001' }"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="success" icon="el-icon-check" size="small" @click="handlePass">通过</el-button>
        <el-button type="info" icon="el-icon-close" size="small" @click="handColse">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import ButtonBar from '@/components/ButtonBar'
import upload from '@/components/uploadFile/upload'
import { typeValues } from '@/api/jichuxinxi/dictcommons'
import req from '@/api/anruifinmanagement/chunafukuan/cashier'

export default {
  name: 'cashier',
  components: {
    Pagination,
    pageye,
    upload,
    ButtonBar
  },
  data() {
    return {
      btndisabled: false,
      btnList: [
        {
          type: 'primary',
          size: 'small',
          icon: 'list',
          btnKey: 'doDispose',
          btnLabel: '批量处理'
        },
        {
          type: 'success',
          size: 'small',
          icon: 'export',
          btnKey: 'build',
          btnLabel: '导出'
        },
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      dialogImgVisible: false,
      dialogVisible: false,
      // 查询条件 -----------
      tableKey: 0,
      list: [],
      srcList: [],
      sids: [],
      diploma_list: [],
      state_list: [
        {
          dictKey: 1,
          dictValue: '未付款'
        },
        {
          dictKey: 2,
          dictValue: '已付款'
        }
      ],
      costType_list: [],
      costTitle_list: [],
      payWay_list: [],
      FormLoading: false,
      listLoading: false,
      listQuery: {
        params: {
          costTitleKey: '',
          costTypeKey: '',
          createEndDate: '',
          createStartDate: '',
          state: '',
          userSid: ''
        },
        current: 1,
        size: 10,
        total: 0
      },
      formobj: {
        name: '',
        payBank: '',
        payBankAccount: '',
        payDate: '',
        payFile: '',
        payRemark: '',
        payWayKey: '',
        payWayValue: '',
        sids: [],
        userSid: ''
      },
      imgList: [],
      rules: {}
    }
  },
  created() {
    // 初始化变量
    this.init()
  },
  mounted() {
    this.$refs['btnbar'].setButtonList(this.btnList)
  },
  methods: {
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    btnHandle(btnKey) {
      console.log('XXXXXXXXXXXXXXX    ' + btnKey)
      switch (btnKey) {
        case 'doDispose':
          this.doDispose()
          break
        case 'doExport':
          this.doExport()
          break
        case 'doClose':
          this.doClose()
          break
        default:
          break
      }
    },
    init() {
      typeValues({ type: 'payCostType' }).then((res) => {
        if (res.success) {
          this.costType_list = res.data
        }
      })
      typeValues({ type: 'payCostTitle' }).then((res) => {
        if (res.success) {
          this.costTitle_list = res.data
        }
      })
    },
    handleSelectionChange(row) {
      console.log('aaa', row)
      const aa = []
      row.forEach(element => {
        aa.push(element.sid)
      })
      this.sids = aa
      console.log('获取sids数组', this.sids)
    },
    // 序号
    indexMethod(index) {
      var pagestart = (this.listQuery.current - 1) * this.listQuery.size
      var pageindex = index + 1 + pagestart
      return pageindex
    },
    // 查询列表信息
    getList() {
      this.listLoading = true
      this.listQuery.params.userSid = window.sessionStorage.getItem('userSid')
      req.listPage(this.listQuery).then((response) => {
        console.log('列表查询结果：', response)
        this.listLoading = false
        if (response.success && response.data && response.data.total > 0) {
          this.list = response.data.records
          this.listQuery.total = response.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleReset() {
      this.listQuery = {
        params: {
          costTitleKey: '',
          costTypeKey: '',
          createEndDate: '',
          createStartDate: '',
          state: '',
          userSid: ''
        },
        current: 1,
        size: 10,
        total: 0
      }
      this.getList()
    },
    handleGetCheck(row) {
      this.dialogImgVisible = true
    },
    handleEdit(row) {
      this.dialogVisible = true
      const aa = []
      aa.push(row.sid)
      this.sids = aa
    },
    doDispose() {
      this.dialogVisible = true
    },
    handlePass() {
      this.formobj.sids = this.sids
    },
    handColse() {
      this.dialogVisible = false
      this.formobj = {}
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>
<style scoped>
.upload_img {
  display: inline-block;
  padding-left: 10px;
}
.btn {
  padding: 15px 0 15px 0;
  border: 1px solid #e0e3eb;
}

.tab-header {
  background-color: #edf1f7;
  padding: 8px 20px;
  margin-bottom: 0 !important;
}

.tab-header /deep/ .el-form-item {
  margin-bottom: 10px;
}
.listtop {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #dfe4ed;
  height: 40px;
}
.tit {
  margin-bottom: -10px;
}
.pagination {
  margin-bottom: -10px;
}
/deep/ .el-col-4 {
  text-align: right;
  float: left;
  font-size: 14px;
  color: #606266;
  line-height: 40px !important;
  font-weight: 600;
}
</style>
