<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="收款单位名称">
                <el-input v-model="listQuery.params.receiveCompany" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="收款账号">
                <el-input v-model="listQuery.params.receiveBankAccount" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="金额">
                <el-input v-model="listQuery.params.cost" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="付款时需备注内容">
                <el-input v-model="listQuery.params.busRemarks" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="开户名称">
                <el-input v-model="listQuery.params.payBank" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="付款账号">
                <el-input v-model="listQuery.params.payBankAccount" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="批量付款编号">
                <el-input v-model="listQuery.params.batchNumber" placeholder="" clearable/>
              </el-form-item>
              <el-form-item label="审批日期">
                <el-date-picker v-model="listQuery.params.createStartDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
                <span style="padding: 0 8px">至</span>
                <el-date-picker v-model="listQuery.params.createEndDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="选择日期"/>
              </el-form-item>
            </el-form>
            <div class="btn" style="text-align: center;">
              <el-button type="primary" @click="handleFilter" icon="el-icon-search" size="small">查询</el-button>
              <el-button type="primary" @click="handleReset" icon="el-icon-refresh" 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="180px" align="center">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="handlePrint(scope.row)">审批下载</el-button>
                <el-button type="primary" :disabled="scope.row.state === '未支付' ? false : true" size="mini" @click="handleEdit(scope.row)">办理</el-button>
              </template>
            </el-table-column>
            <el-table-column label="状态" width="100px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.state }}</span>
              </template>
            </el-table-column>
            <el-table-column label="审批日期" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.createTime }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款编号" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.id }}</span>
              </template>
            </el-table-column>
            <el-table-column label="款项名称" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.costTypeValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="款项详情" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.costTitleValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款方式" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.payWayValue }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收款单位名称" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.receiveCompany }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收款账号" align="center" width="130">
              <template slot-scope="scope">
                <span>{{ scope.row.receiveBankAccount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="收款账户开户行" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.receiveBank }}</span>
              </template>
            </el-table-column>
            <el-table-column label="金额" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.cost }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款时需备注内容" align="center" width="200">
              <template slot-scope="scope">
                <span>{{ scope.row.busRemarks }}</span>
              </template>
            </el-table-column>
            <el-table-column label="开户名称" align="center" width="150">
              <template slot-scope="scope">
                <span>{{ scope.row.payBank }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款账号" align="center" width="180">
              <template slot-scope="scope">
                <span>{{ scope.row.payBankAccount }}</span>
              </template>
            </el-table-column>
            <el-table-column label="本次付款说明" align="center" width="180">
              <template slot-scope="scope">
                <span>{{ scope.row.payRemark }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款人" align="center" width="130">
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款日期" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.payDate }}</span>
              </template>
            </el-table-column>
            <el-table-column label="批量付款编号" align="center" width="120">
              <template slot-scope="scope">
                <span>{{ scope.row.batchNumber }}</span>
              </template>
            </el-table-column>
            <el-table-column label="付款凭证" align="center" class-name="small-padding fixed-width" width="120">
              <template slot-scope="scope">
                <el-button v-show="scope.row.payFiles" 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" :append-to-body="true">
      <el-form>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-image style="width: 178px;height: 178px;" v-for="(item, index) in url_list" @click="open(item)" :key="index" :src="item"></el-image>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <el-dialog :visible.sync="dialogUrlVisible" :append-to-body="true">
      <img width="100%" :src="dialogUrl" alt="">
    </el-dialog>
    <el-dialog :visible.sync="dialogVisible" width="70%" center :show-close="false">
      <el-form ref="form_obj" :rules="rules" :model="formobj" class="formaddcopy02">
        <el-row style="border-top: 1px solid #e0e3eb">
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>收款单位名称</div>
            <el-form-item prop="receiveCompany">
              <el-select class="addinputInfo addinputw" :disabled="sids.length > 1" v-model="formobj.receiveCompany" placeholder="请选择" @change="changerRceiveCompany" clearable filterable>
                <el-option v-for="item in receiveCompany_list" :key="item.sid" :label="item.name" :value="item.name"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>收款银行账号</div>
            <el-form-item prop="receiveBankAccount">
              <el-select class="addinputInfo addinputw" :disabled="sids.length > 1" v-model="formobj.receiveBankAccount" placeholder="请选择" @change="changeReceiveBankAccount" clearable filterable>
                <el-option v-for="item in receiveBankAccount_list" :key="item.receiveBankAccount" :label="item.receiveBankAccount" :value="item.receiveBankAccount"/>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="span-sty">收款账户开户行</div>
            <el-form-item><span class="addinputInfo">{{ formobj.receiveBank }}</span></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>付款金额</div>
            <el-form-item prop="cost"><el-input class="addinputInfo addinputw" v-model="formobj.cost" :disabled="disabledCost" clearable placeholder="" /></el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">付款手续费</div>
            <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.paymentCharges" clearable placeholder="对应金蝶付款单”手续费“" /></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>付款方式</div>
            <el-form-item prop="payWayValue">
              <el-select class="addinputInfo addinputw" v-model="formobj.payWayValue" placeholder="请选择" @change="changePayWay" clearable filterable>
                <el-option v-for="item in payWay_list" :key="item.dictKey" :label="item.dictValue" :value="item.dictValue"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>付款日期</div>
            <el-form-item prop="payDate"><el-date-picker class="addinputInfo addinputw" v-model="formobj.payDate" type="date" clearable value-format="yyyy-MM-dd" placeholder="请选择日期"/></el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="showHide">
          <el-col :span="12">
            <div class="span-sty"><span class="icon">*</span>付款账号</div>
            <el-form-item prop="payBankAccount">
              <el-select class="addinputInfo addinputw" v-model="formobj.payBankAccount" placeholder="请选择" @change="changePayBankAccount" clearable filterable>
                <el-option v-for="item in payBankAccount_list" :key="item.bankAccount" :label="item.bankAccount" :value="item.bankAccount"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <div class="span-sty">开户名称</div>
            <el-form-item><span class="addinputInfo">{{ formobj.payBank }}</span></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="span-sty">本次付款说明</div>
            <el-form-item><el-input class="addinputInfo addinputw" v-model="formobj.payRemark" placeholder="请填写本次付款说明" clearable/></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="span-sty"><span class="icon">*</span>付款凭证</div>
            <el-form-item><upload ref="uploadImg" class="addinputInfo" v-model="diploma_list" :accept="accept" :limit="50" 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" :disabled="submitdisabled" @click="handlePayment">无需付款</el-button>
        <el-button type="success" icon="el-icon-check" size="small" :disabled="submitdisabled" @click="handlePass">通过</el-button>
        <el-button type="info" icon="el-icon-close" size="small" :disabled="submitdisabled" @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, selectAccountByUseOrgSid, getDetailsList, getOrgSidByPath, getBankList, getButtonPermissions } from '@/api/jichuxinxi/dictcommons'
import req from '@/api/anruifinmanagement/chunafukuan/cashier'
import { getStorage } from '@/utils/auth'

export default {
  name: 'Cashier',
  components: {
    Pagination,
    pageye,
    upload,
    ButtonBar
  },
  data() {
    return {
      btndisabled: false,
      submitdisabled: false,
      showHide: true,
      btnList: [
        {
          type: 'primary',
          size: 'small',
          icon: 'list',
          btnKey: 'doDispose',
          btnLabel: '批量处理'
        },
        {
          type: 'success',
          size: 'small',
          icon: 'export',
          btnKey: 'build',
          btnLabel: '导出'
        },
        {
          type: 'danger',
          size: 'small',
          icon: '',
          btnKey: 'doCancellation',
          btnLabel: '作废'
        },
        {
          type: 'info',
          size: 'small',
          icon: 'cross',
          btnKey: 'doClose',
          btnLabel: '关闭'
        }
      ],
      accept: '.jpg,.jpeg,.png,.JPG,.JPEG',
      isSearchShow: false,
      searchxianshitit: '显示查询条件',
      dialogImgVisible: false,
      dialogUrlVisible: false,
      dialogVisible: false,
      // 查询条件 -----------
      tableKey: 0,
      list: [],
      dialogUrl: '',
      url_list: [],
      sids: [],
      nodeState_list: [],
      diploma_list: [],
      payBankAccount_list: [],
      state_list: [
        {
          dictKey: 1,
          dictValue: '未支付'
        },
        {
          dictKey: 2,
          dictValue: '已支付'
        },
        {
          dictKey: 3,
          dictValue: '已作废'
        }
      ],
      costType_list: [],
      costTitle_list: [],
      payWay_list: [],
      receiveCompany_list: [],
      receiveBankAccount_list: [],
      FormLoading: false,
      listLoading: false,
      listQuery: {
        params: {
          costTitleKey: '',
          costTypeKey: '',
          createEndDate: '',
          createStartDate: '',
          state: '',
          userSid: '',
          orgPath: '',
          receiveCompany: '',
          receiveBankAccount: '',
          cost: '',
          busRemarks: '',
          payBank: '',
          payBankAccount: '',
          batchNumber: ''
        },
        current: 1,
        size: 10,
        total: 0
      },
      formobj: {
        name: '',
        payBank: '',
        payBankAccount: '',
        payDate: '',
        payFiles: [],
        payRemark: '',
        payWayKey: '',
        payWayValue: '',
        sids: [],
        userSid: '',
        receiveCompany: '', // 供应商名称
        receiveBank: '', // 收款银行名称
        receiveBankAccount: '', // 收款银行账号
        payCode: '', // 供应商编码
        cost: '',
        paymentCharges: ''
      },
      disabledCost: false,
      imgList: [],
      rules: {
        payWayValue: [{ required: true, message: '请选择付款方式', trigger: 'change' }],
        payDate: [{ required: true, message: '请选择付款日期', trigger: 'blur' }],
        payBankAccount: [{ required: true, message: '请选择付款账号', trigger: 'change' }],
        receiveCompany: [{ required: true, message: '收款单位不能为空', trigger: 'change' }],
        receiveBankAccount: [{ required: true, message: '收款银行账号不能为空', trigger: 'change' }],
        cost: [{ required: true, message: '付款金额不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    // 初始化变量
    this.init()
  },
  mounted() {
    getButtonPermissions({ userSid: window.sessionStorage.getItem('userSid'), url: this.$route.path, type: 0 }).then((res) => {
      if (res.success) {
        for (var i = 0; i < res.data.length; i++) {
          for (var k = 0; k < this.btnList.length; k++) {
            if (res.data[i].buttonId === this.btnList[k].btnKey) {
              this.btnList.splice(k, 1)
            }
          }
        }
        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
        case 'doCancellation':
          this.doCancellation()
          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
        }
      })
      typeValues({ type: 'paymentType' }).then((res) => {
        if (res.success) {
          this.payWay_list = res.data
        }
      })
      selectAccountByUseOrgSid({ userSid: window.sessionStorage.getItem('userSid'), orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((resp) => {
        if (resp.success) {
          this.payBankAccount_list = resp.data
        }
      })
      getOrgSidByPath({ orgPath: window.sessionStorage.getItem('defaultOrgPath') }).then((res) => {
        if (res.success) {
          getDetailsList({ orgSid: res.data }).then((resp) => {
            if (resp.success) {
              this.receiveCompany_list = resp.data
            }
          })
        }
      })
      this.getList()
    },
    changePayBankAccount(value) {
      const choose = this.payBankAccount_list.filter((item) => item.bankAccount === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.payBank = choose[0].accountName
      } else {
        this.formobj.payBank = ''
      }
    },
    handleSelectionChange(row) {
      const aa = []
      row.forEach(element => {
        aa.push(element.sid)
      })
      this.sids = aa
      this.nodeState_list = row
    },
    // 序号
    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')
      this.listQuery.params.orgPath = window.sessionStorage.getItem('defaultOrgPath')
      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
        }
      })
    },
    // 查询按钮
    handleFilter() {
      this.listQuery.current = 1
      this.getList()
    },
    handleReset() {
      this.listQuery = {
        params: {
          costTitleKey: '',
          costTypeKey: '',
          createEndDate: '',
          createStartDate: '',
          state: '',
          userSid: '',
          orgPath: '',
          receiveCompany: '',
          receiveBankAccount: '',
          cost: '',
          busRemarks: '',
          payBank: '',
          payBankAccount: '',
          batchNumber: ''
        },
        current: 1,
        size: 10,
        total: 0
      }
      this.getList()
    },
    changePayWay(value) {
      const choose = this.payWay_list.filter((item) => item.dictValue === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.payWayKey = choose[0].dictKey
        if (choose[0].groupName === '0') {
          this.showHide = false
        } else {
          this.showHide = true
        }
      } else {
        this.formobj.payWayKey = ''
        this.showHide = true
      }
    },
    changerRceiveCompany(value) {
      const choose = this.receiveCompany_list.filter((item) => item.name === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.payCode = choose[0].payCode
        getBankList({ sid: choose[0].sid }).then((res) => {
          if (res.success) {
            this.receiveBankAccount_list = res.data
          }
        })
      } else {
        this.formobj.payCode = ''
        this.receiveBankAccount_list = []
      }
    },
    changeReceiveBankAccount(value) {
      const choose = this.receiveBankAccount_list.filter((item) => item.receiveBankAccount === value)
      if (choose !== null && choose.length > 0) {
        this.formobj.receiveBank = choose[0].receiveBank
      } else {
        this.formobj.receiveBank = ''
      }
    },
    handleGetCheck(row) {
      this.dialogImgVisible = true
      this.url_list = row.payFiles
    },
    handlePrint(row) {
      req.createPdf({ sid: row.sid, userName: window.sessionStorage.getItem('name') }).then((resp) => {
        if (resp.success && resp.data.pdfPath !== '') {
          var xhr = new XMLHttpRequest()
          xhr.open('GET', process.env.VUE_APP_BASE_API + '/base/file/download?filePath=' + resp.data.pdfPath + '&outFileName=' + '出纳', true)
          xhr.setRequestHeader('token', getStorage())
          xhr.responseType = 'blob'
          xhr.onload = function(e) {
            // 如果请求执行成功
            var blob = this.response
            var filename = '预付款申请.pdf'
            var a = document.createElement('a')
            // blob.type="application/octet-stream";
            // 创键临时url对象
            var url = URL.createObjectURL(blob)
            a.href = url
            a.download = filename
            a.click()
            // 释放之前创建的URL对象
            window.URL.revokeObjectURL(url)
          }
          // 发送请求
          xhr.send()
        }
        if (resp.success && resp.data.fjPath !== '' && resp.data.fjType !== '') {
          var FJ = new XMLHttpRequest()
          FJ.open('GET', process.env.VUE_APP_BASE_API + '/base/file/download?filePath=' + resp.data.fjPath + '&outFileName=' + '车辆外采合同附件', true)
          FJ.setRequestHeader('token', getStorage())
          FJ.responseType = 'blob'
          FJ.onload = function(e) {
            // 如果请求执行成功
            var blob = this.response
            var filename = '申请附件' + resp.data.fjType
            var a = document.createElement('a')
            // blob.type="application/octet-stream";
            // 创键临时url对象
            var url = URL.createObjectURL(blob)
            a.href = url
            a.download = filename
            a.click()
            // 释放之前创建的URL对象
            window.URL.revokeObjectURL(url)
          }
          // 发送请求
          FJ.send()
        }
      })
    },
    handleEdit(row) {
      this.dialogVisible = true
      if (row.costTypeValue === '垫款' || row.costTypeValue === '月还代收') {
        this.disabledCost = true
      }
      this.formobj.payRemark = row.payRemark
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      this.formobj.cost = row.cost
      this.formobj.receiveCompany = row.receiveCompany
      this.formobj.receiveBankAccount = row.receiveBankAccount
      this.formobj.receiveBank = row.receiveBank
      this.formobj.payCode = row.payCode
      this.formobj.payWayValue = row.payWayValue
      this.changePayWay(row.payWayValue)
      const aa = []
      aa.push(row.sid)
      this.sids = aa
    },
    doDispose() {
      if (this.sids.length === 0 || this.sids.length === 1) {
        this.$message({ showClose: true, type: 'error', message: '请选择至少一条以上记录进行批量处理' })
        return
      } else {
        if (this.nodeState_list.length > 0) {
          for (var i = 0; i < this.nodeState_list.length; i++) {
            if (this.nodeState_list[i].state !== '未支付') {
              this.$message({ showClose: true, type: 'error', message: '因选择的记录中包含已支付的,操作失败' })
              return
            }
            if (this.nodeState_list[i].receiveBankAccount !== this.nodeState_list[this.nodeState_list.length - 1].receiveBankAccount || this.nodeState_list[i].finDataType !== this.nodeState_list[this.nodeState_list.length - 1].finDataType) {
              this.$message({ showClose: true, type: 'error', message: '请选择收款账号和推送财务数据类型一致的记录进行操作' })
              return
            }
          }
          this.$nextTick(() => {
            this.$refs['form_obj'].clearValidate()
          })
          this.dialogVisible = true
          this.disabledCost = true
          var num = 0
          for (let i = 0; i < this.nodeState_list.length; i++) {
            if (i === 0) {
              this.formobj.receiveCompany = this.nodeState_list[i].receiveCompany
              this.formobj.receiveBankAccount = this.nodeState_list[i].receiveBankAccount
              this.formobj.receiveBank = this.nodeState_list[i].receiveBank
            }
            num = Math.round((parseFloat(num) + parseFloat(this.nodeState_list[i].cost !== '' ? this.nodeState_list[i].cost : 0)) * 100) / 100
          }
          this.formobj.cost = num
        }
      }
    },
    handlePayment() {
      if (this.formobj.payCode === '' || this.formobj.payCode === null || this.formobj.payCode === undefined) {
        const choose = this.receiveCompany_list.filter((item) => item.name === this.formobj.receiveCompany)
        if (choose !== null && choose.length > 0) {
          this.formobj.payCode = choose[0].payCode
        }
      }
      this.formobj.sids = this.sids
      this.submitdisabled = true
      req.updateAllState(this.formobj).then((resp) => {
        if (resp.success) {
          this.submitdisabled = false
          this.$message({ showClose: true, type: 'success', message: '保存成功' })
          this.handColse()
          this.getList()
        } else {
          this.submitdisabled = false
        }
      }).catch(() => {
        this.submitdisabled = false
      })
    },
    handlePass() {
      if (this.formobj.payCode === '' || this.formobj.payCode === null || this.formobj.payCode === undefined) {
        const choose = this.receiveCompany_list.filter((item) => item.name === this.formobj.receiveCompany)
        if (choose !== null && choose.length > 0) {
          this.formobj.payCode = choose[0].payCode
        }
      }
      this.formobj.sids = this.sids
      this.formobj.name = window.sessionStorage.getItem('name')
      this.formobj.userSid = window.sessionStorage.getItem('userSid')
      this.$refs['form_obj'].validate(valid => {
        if (valid) {
          if (this.diploma_list.length > 0) {
            for (var i = 0; i < this.diploma_list.length; i++) {
              this.formobj.payFiles.push(this.diploma_list[i].url)
            }
          }
          if (this.formobj.payFiles.length === 0) {
            this.$message({ showClose: true, type: 'error', message: '请上传付款凭证' })
            return
          }
          this.submitdisabled = true
          if (this.formobj.sids.length > 1) {
            req.batchUpdate(this.formobj).then((resp) => {
              if (resp.success) {
                this.submitdisabled = false
                this.$message({ showClose: true, type: 'success', message: resp.msg })
                this.handColse()
                this.getList()
              } else {
                this.submitdisabled = false
              }
            }).catch(() => {
              this.submitdisabled = false
            })
          } else {
            req.update(this.formobj).then((resp) => {
              if (resp.success) {
                this.submitdisabled = false
                this.$message({ showClose: true, type: 'success', message: resp.msg })
                this.handColse()
                this.getList()
              } else {
                this.submitdisabled = false
              }
            }).catch(() => {
              this.submitdisabled = false
            })
          }
        } else {
          return false
        }
      })
    },
    open(value) {
      this.dialogUrlVisible = true
      this.dialogUrl = value
    },
    doCancellation() {
      if (this.sids.length === 0) {
        this.$message({ showClose: true, type: 'error', message: '请选择至少一条记录进行作废操作' })
        return
      }
      if (this.nodeState_list.length > 0) {
        for (var i = 0; i < this.nodeState_list.length; i++) {
          if (this.nodeState_list[i].state !== '未支付') {
            this.$message({ showClose: true, type: 'error', message: '因选择的记录中包含已支付的,操作失败' })
            return
          }
        }
      }
      const tip = '请确认是否作废所选 ' + this.sids.length + ' 条记录?'
      this.$confirm(tip, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        req.abandonApply(this.sids).then(resp => {
          loading.close()
          if (resp.success) {
            this.$message({ type: 'success', message: resp.msg, showClose: true })
            this.getList()
          }
        }).catch(e => {
          loading.close()
        })
      }).catch(() => {})
    },
    handColse() {
      this.dialogVisible = false
      this.formobj = {
        name: '',
        payBank: '',
        payBankAccount: '',
        payDate: '',
        payFiles: [],
        payRemark: '',
        payWayKey: '',
        payWayValue: '',
        sids: [],
        userSid: '',
        receiveCompany: '', // 供应商名称
        receiveBank: '', // 收款银行名称
        receiveBankAccount: '', // 收款银行账号
        payCode: '', // 供应商编码
        cost: '',
        paymentCharges: ''
      }
      this.disabledCost = false
      this.submitdisabled = false
      this.showHide = true
      this.diploma_list = []
      this.$refs['form_obj'].resetFields()
    },
    doClose() {
      this.$store.dispatch('tagsView/delView', this.$route)
      this.$router.go(-1)
    }
  }
}
</script>
<style scoped>
.span-sty {
  width: 130px !important;
}
.addinputInfo {
  margin-left: 120px !important;
}
/deep/ .el-form-item__error {
  margin-left: 120px !important;
}
.formaddcopy02 .el-row .el-col /deep/ .el-form-item .addinputw {
  margin-left: 120px !important;
  width: calc(100% - 115px);
}
</style>
