<template>
  <div class="app-container">
    <!-- Start 列表页面 -->
    <div v-show="viewState == 1">
      <button-bar view-title="资方信审终审结果反馈" ref="btnbar" :btndisabled="btndisabled" @btnhandle="btnHandle"/>
      <div class="main-content">
        <div class="switch_btn">
          <el-button :class="{btn_style:viewState === 1}">待反馈</el-button>
          <el-button class="" @click="handleClick">已反馈</el-button>
        </div>
        <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-input v-model="listQuery.params.useOrgName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="销售部门">
                <el-input v-model="listQuery.params.saleDeptName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="销售专员">
                <el-input v-model="listQuery.params.staffName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="消贷合同编号">
                <el-input v-model="listQuery.params.loanContractNo" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="贷款人">
                <el-input v-model="listQuery.params.loanPeoName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="资方">
                <el-input v-model="listQuery.params.capitalName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="金融产品">
                <el-input v-model="listQuery.params.policyName" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="资方合同号">
                <el-input v-model="listQuery.params.bankContractNo" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
              <el-form-item label="资方信审结果">
                <el-input v-model="listQuery.params.capCarefulResult" clearable placeholder="" class="addinputw"></el-input>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" icon="el-icon-search" @click="handleFilter" size="small">查询</el-button>
              <el-button type="primary" icon="el-icon-refresh" @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%;">
            <el-table-column fixed width="60" label="序号" type="index" :index="indexMethod" align="center"/>
            <el-table-column fixed label="操作" align="center" width="100">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="handleConfirm(scope.row)">确认</el-button>
              </template>
            </el-table-column>
            <el-table-column label="分公司" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.useOrgName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="销售部门" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.orgName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="销售专员" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.staffName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="消贷合同编号" align="center" min-width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.loanContractNo }}</span>
              </template>
            </el-table-column>
            <el-table-column label="台数" align="center" min-width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.num }}</span>
              </template>
            </el-table-column>
            <el-table-column label="贷款人" align="center" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.borrowerName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="资方" align="center" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.bankName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="金融产品" align="center" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.policyName }}</span>
              </template>
            </el-table-column>
            <el-table-column label="资方信审时间" align="center" width="250">
              <template slot-scope="scope">
                <el-date-picker v-model="scope.row.capCarefulDate" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" placeholder="选择日期"></el-date-picker>
              </template>
            </el-table-column>
            <el-table-column label="资方信审结果" align="center" width="200">
              <template slot-scope="scope">
                <el-select v-model="scope.row.capCarefulResult" placeholder="请选择" clearable filterable>
                  <el-option v-for="item in result_list" :disabled="item.dictValue =='暂无法判定'" :key="item.dictKey" :label="item.dictValue" :value="item.dictValue"></el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="资方合同号" align="center" width="200">
              <template slot-scope="scope">
                <el-input v-model="scope.row.bankContractNo" clearable placeholder=""/>
              </template>
            </el-table-column>
            <el-table-column label="资方合同号" align="center" width="100">
              <template slot-scope="scope">
                <span>{{ scope.row.bankContractNo }}</span>
              </template>
            </el-table-column>
            <el-table-column label="见证附件" align="center" width="150">
              <template slot-scope="scope">
                <div style="display: flex;flex-direction: row;justify-content: space-between;align-items: center">
                  <upload ref="upload" v-model="images_list" :limit="50" @change="uploadFile($event, scope.row.sid)" bucket="map" :upload-data="{ type: '0001' }"/>
                  <el-button type="primary" size="mini" @click="lookFile(scope.row)">查看</el-button>
                </div>
              </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 列表页面 -->
    <!-- 已选择列表 -->
    <managementcreditauditfeedback v-show="viewState == 2" ref="divSelect" @doback="resetState"/>
    <!-- 查看附件 -->
    <el-dialog :visible.sync="dialogVisible">
      <el-image v-for="(item, index) in dialog_list" :key="index" :src="item" :preview-src-list="dialog_list"/>
    </el-dialog>
  </div>
</template>

<script>
import req from '@/api/managementcreditaudit/managementcreditaudit'
import Pagination from '@/components/pagination'
import pageye from '@/components/pagination/pageye'
import ButtonBar from '@/components/ButtonBar'
import { typeValues } from '@/api/Common/dictcommons'
import upload from '@/components/uploadFile/upload'
import managementcreditauditfeedback from './managementcreditauditfeedback'

export default {
  name: 'ManagementCreditAudit',
  components: {
    Pagination,
    pageye,
    ButtonBar,
    upload,
    managementcreditauditfeedback
  },
  data() {
    return {
      viewState: 1,
      btndisabled: false,
      dialogVisible: false,
      btnList: [
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      // 查询条件 -----------
      tableKey: 0,
      list: [],
      sids: [],
      result_list: [],
      images_list: [],
      dialog_list: [],
      listLoading: false,
      listQuery: {
        params: {
          bankContractNo: '',
          capCarefulResult: '',
          capitalName: '',
          loanContractNo: '',
          loanPeoName: '',
          menuUrl: '',
          orgSidPath: '',
          policyName: '',
          saleDeptName: '',
          staffName: '',
          type: '1',
          useOrgName: '',
          userSid: ''
        },
        current: 1,
        size: 10,
        total: 0
      },
      contract: '',
      rules: {}
    }
  },
  created() {
    // 初始化变量
    this.init()
    this.getList()
  },
  mounted() {
    this.$refs['btnbar'].setButtonList(this.btnList)
  },
  methods: {
    init() {
      typeValues({ type: 'examineResult' }).then((resp) => {
        if (resp.success) {
          this.result_list = resp.data
        }
      })
    },
    // 搜索条件效果
    clicksearchShow() {
      this.isSearchShow = !this.isSearchShow
      if (this.isSearchShow) {
        this.searchxianshitit = '隐藏查询条件'
      } else {
        this.searchxianshitit = '显示查询条件'
      }
    },
    btnHandle(btnKey) {
      console.log('XXXXXXXXXXXXXXX    ' + btnKey)
      switch (btnKey) {
        case 'doClose':
          this.doClose()
          break
        default:
          break
      }
    },
    // 序号
    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.orgSidPath = window.sessionStorage.getItem('defaultOrgPath')
      this.listQuery.params.menuUrl = this.$route.path
      this.listQuery.params.userSid = window.sessionStorage.getItem('userSid')
      req.listPage(this.listQuery).then((response) => {
        this.listLoading = false
        if (response.success) {
          this.list = response.data.records
          this.listQuery.total = response.data.total
        } else {
          this.list = []
          this.listQuery.total = 0
        }
      })
    },
    handleConfirm(row) {
      if (row.capCarefulDate === '') {
        this.$message({ showClose: true, type: 'error', message: '资方信审时间不能为空' })
        return
      }
      if (row.capCarefulResult === '') {
        this.$message({ showClose: true, type: 'error', message: '资方信审结果不能为空' })
        return
      }
      if (row.bankContractNo === '') {
        this.$message({ showClose: true, type: 'error', message: '资方合同号不能为空' })
        return
      }
      const params = {
        bankContractNo: row.bankContractNo,
        capCarefulDate: row.capCarefulDate,
        capCarefulResult: row.capCarefulResult,
        loanContractSid: row.loanContractSid,
        sid: row.sid
      }
      req.save(params).then((resp) => {
        if (resp.success) {
          this.$message({ showClose: true, type: 'success', message: '操作成功' })
          this.getList()
        }
      })
    },
    uploadFile(val, sid) {
      if (this.images_list.length > 0) {
        const aa = []
        this.images_list.forEach((e) => {
          aa.push(e.url)
        })
        req.saveImages({ sid: sid, xsImages: aa }).then((res) => {
          if (res.success) {
            this.$message({ showClose: true, type: 'success', message: '上传成功' })
          }
        })
      }
    },
    lookFile(row) {
      req.selectImages({ sid: row.sid }).then((res) => {
        if (res.success && res.data.length > 0) {
          this.dialogVisible = true
          this.dialog_list = res.data
        }
      })
    },
    handleClick() {
      this.viewState = 2
      this.$refs['divSelect'].getList()
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleReset() {
      this.listQuery = {
        params: {
          bankContractNo: '',
          capCarefulResult: '',
          capitalName: '',
          loanContractNo: '',
          loanPeoName: '',
          menuUrl: '',
          orgSidPath: '',
          policyName: '',
          saleDeptName: '',
          staffName: '',
          type: '1',
          useOrgName: '',
          userSid: ''
        },
        current: 1,
        size: 10,
        total: 0
      }
      this.getList()
    },
    resetState() {
      this.viewState = 1
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>
<style scoped>
.btn_style {
  background-color: #018ad2;
  color: white;
  font-weight: 600;
}
</style>
