<template>
  <div class="borderless" v-loading="pageLoading">
    <div class="customer-head">
      <div class="customer-back">
        <!--        <i class="back-icon el-icon-arrow-left"></i><i style="font-style:normal">返回管理列表</i>-->
        <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
                   @click="backToList">返回列表
        </el-button>
      </div>
      <div class="add-customer-btn">
        <el-button
          v-if="detailData.seeDisabled"
          size="small"
          @click="editHandle"
          type="primary"
          style="margin-right: 8px"
          :loading="saveLoading"
        >编 辑</el-button>
<!--        <el-dropdown style="margin-right: 8px;">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            size="small"-->
<!--          >-->
<!--            审核处理<i class="el-icon-arrow-down el-icon&#45;&#45;right"></i>-->
<!--          </el-button>-->
<!--          <el-dropdown-menu slot="dropdown">-->
<!--            <el-dropdown-item :disabled="!form.id || form.status > 0" @click.native="pleaseCheck">请核数据</el-dropdown-item>-->
<!--            <el-dropdown-item v-if="form.status > 0" @click.native="checkScheduleDialog = true,checkId=form.id">审核进度</el-dropdown-item>-->
<!--            <el-dropdown-item v-if="false">撤销请核</el-dropdown-item>-->
<!--          </el-dropdown-menu>-->
<!--        </el-dropdown>-->
        <el-dropdown style="margin-right: 8px;">
          <el-button
            type="warning"
            size="small"
          >
            账单处理<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              :disabled="detailData.seeDisabled || !form.id"
              @click.native="applyPayment('申请')"
            >
              申请货款
            </el-dropdown-item>
<!--            <el-dropdown-item-->
<!--              @click.stop.native="applyPayment('收费')"-->
<!--              :disabled="!this.form.id"-->
<!--            >申请退款-->
<!--            </el-dropdown-item>-->
            <el-dropdown-item
               @click.native="openApplicationDialog"
               :disabled="!form.id"
            >查看账单
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
        <el-button
          size="small"
          class="el-button--small-yh"
          type="success"
          @click="copyOrder"
          :disabled="detailData.seeDisabled || !this.form.id"
        >
          复制单据
        </el-button>
        <el-button
          size="small"
          class="el-button--small-yh"
          type="primary"
          :disabled="disabled || detailData.seeDisabled"
          @click="editCustomer(false)"
          :loading="saveLoading"
        >保 存
        </el-button>
        <div v-if="checkDisabled" style="float: right;margin-left: 8px">
          <el-button type="primary"
                     size="small"
                     class="el-button--small-yh"
                     @click.stop="openCheckDialog">
            审批
          </el-button>
        </div>
      </div>
    </div>
    <div class="customer-main">
      <el-form :model="form" ref="form" label-width="130px" class="demo-ruleForm">
        <containerTitle title="基础资料"></containerTitle>
        <basic-container style="margin-bottom: 10px">
          <el-row>
            <el-col v-for="(item,index) in basicData.column" :key="index" :span="item.span?item.span:8">
              <el-form-item :label="item.label" :prop="item.prop" :rules="item.rules">
                <!--                <avue-input-tree v-if="item.prop === 'corpsTypeId'"  leaf-only multiple :props="{label:'title'}" v-model="form[item.prop]" placeholder="请选择内容" type="tree" :dic="dic"-->
                <!--                ></avue-input-tree>-->
                <el-date-picker v-if="item.type === 'datetime'" style="width: 100%;" v-model="form[item.prop]"
                                size="small" type="datetime" placeholder="选择日期" value-format="yyyy-MM-dd HH:mm:ss" :disabled="detailData.seeDisabled"/>
                <el-date-picker v-else-if="item.type === 'date'" style="width: 100%;" v-model="form[item.prop]"
                                size="small" type="date" placeholder="选择日期"
                                :disabled="detailData.seeDisabled"/>
                <el-select v-else-if="item.prop === 'paymentType'" v-model="form[item.prop]" placeholder="请选择" clearable filterable style="width: 100%" size="small" :disabled="detailData.seeDisabled">
                  <el-option v-for="(item,index) in paymentOption" :key="index" :label="item.dictValue" :value="item.dictValue"></el-option>
                </el-select>
                <crop-select
                  v-else-if="item.prop === 'corpId'"
                  v-model="form[item.prop]"
                  corpType="GYS"
                  @getCorpData="returnBack"
                  :disabled="detailData.seeDisabled"
                ></crop-select>
                <el-select v-else-if="item.prop === 'banks'"
                           v-model="form[item.prop]" placeholder="请选择"
                           clearable
                           filterable
                           allow-create
                           default-first-option
                           size="small"
                           style="width: 100%;"
                           @change="banksChange"
                           :disabled="detailData.seeDisabled">
                  <el-option v-for="(item,index) in bankList" :key="index" :label="item.accountNo" :value="item.accountNo"></el-option>
                </el-select>
                <el-input
                  v-else-if="item.type == 'number'"
                  placeholder="请输入"
                  v-input-limit="2"
                  size="small"
                  :disabled="item.disabled || detailData.seeDisabled"
                  v-model.trim="form[item.prop]"
                />
                <el-select v-else-if="item.prop === 'packageRemarks'" v-model="form[item.prop]" placeholder="请选择" clearable filterable style="width: 100%" size="small" :disabled="detailData.seeDisabled">
                  <el-option v-for="(item,index) in packageOptions" :key="index" :label="item.dictValue" :value="item.dictValue"></el-option>
                </el-select>
                <el-input type="textarea" v-else-if="item.type === 'textarea'" v-model.trim="form[item.prop]" size="small" autocomplete="off" :disabled="item.disabled || detailData.seeDisabled"></el-input>
                <el-input type="age" v-else v-model.trim="form[item.prop]" size="small" autocomplete="off" :disabled="item.disabled || detailData.seeDisabled" placeholder="请输入"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </basic-container>
        <containerTitle title="商品信息"></containerTitle>
        <basic-container style="margin-bottom: 10px">
          <avue-crud
              :option="customerContact"
              v-model="contactsForm"
              :data="contactsData"
              ref="crudContact"
              @row-save="rowSave"
              @row-click="handleRowClick"
              @row-update="rowUpdate"
              @row-del="rowDel"
              @selection-change="productSelection"
              @saveColumn="saveColumn('goods')"
              @resetColumn="resetColumn"
          >
            <template slot="cname" slot-scope="{ row }">
              <goods-select v-if="row.$cellEdit" v-model="row.cname" @getRow="getGoodsRow($event, row)"
                            :configuration="goodsConfiguration" @receiveList="receiveGoodList" @returnRow="getRow($event, row)"/>
              <span v-else>
                {{ row.cname }}
<!--                <span v-for="item in goodsConfiguration.dicData" v-if="item.cname == row.cname">{{ item.cname }}</span>-->
              </span>
            </template>
            <template slot="orderQuantity" slot-scope="{ row }">
              <el-input
                v-if="row.$cellEdit"
                v-model.trim="row.orderQuantity"
                oninput='this.value=this.value.replace(/[^(\d)]/g,"")'               size="small"
                @input="changeContractAmt(row)"
              ></el-input>
              <span v-else>{{ row.orderQuantity | IntegerFormat }}</span>
            </template>
            <template slot="price" slot-scope="{ row }">
              <el-input
                v-if="row.$cellEdit"
                v-model.trim="row.price"
                oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")'                size="small"
                @input="changeContractAmt(row)"
              ></el-input>
              <span v-else>{{ row.price }}</span>
            </template>
<!--            <template slot="storageQuantity" slot-scope="{ row }">-->
<!--              <el-input-->
<!--                v-if="row.$cellEdit"-->
<!--                v-model.trim="row.storageQuantity"-->
<!--                size="small"-->
<!--                oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")'-->
<!--              ></el-input>-->
<!--              <span v-else>{{ row.storageQuantity }}</span>-->
<!--            </template>-->
<!--            <template slot="actualQuantity" slot-scope="{ row }">-->
<!--              <el-input-->
<!--                v-if="row.$cellEdit"-->
<!--                v-model.trim="row.actualQuantity"-->
<!--                size="small"-->
<!--                oninput='this.value=this.value.replace(/[^\-?\d.]/g,"").replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")'-->
<!--              ></el-input>-->
<!--              <span v-else>{{ row.actualQuantity }}</span>-->
<!--            </template>-->
            <template slot="code" slot-scope="{row,index}">
              <el-button type="text" size="mini" style="padding:4px 10px;float:left" @click="commodityChoice(row)" :disabled="detailData.seeDisabled || !row.$cellEdit">选择</el-button>
              <span>{{ row.code }}</span>
            </template>
            <template slot-scope="{row,index}" slot="menu">
              <el-button
                  type="text"
                  size="small"
                  @click="rowCell(row,index)"
                  :disabled="detailData.seeDisabled"
              >{{ row.$cellEdit ? '保存' : '修改' }}
              </el-button>
              <el-button
                size="small"
                icon="el-icon-delete"
                type="text"
                @click="rowDel(row, index)"
                :disabled="detailData.seeDisabled"
                v-if="!row.$cellEdit"
              >删 除</el-button>
            </template>
            <template slot="menuLeft" slot-scope="{size}">
              <el-button type="primary"
                         icon="el-icon-plus"
                         size="small"
                         @click="commoditySelection"
                         :disabled="detailData.seeDisabled"
              >录入明细
              </el-button>
              <el-button type="warning"
                         icon="el-icon-plus"
                         size="small"
                         :disabled="selection.length < 1 || detailData.seeDisabled"
                         @click="getShipmentC">生成采购确认
              </el-button>
              <el-button type="info" :size="size" icon="el-icon-printer" @click.stop="openReport()">报 表</el-button>
            </template>
          </avue-crud>
        </basic-container>
        <fee-info
          ref="feeInfo"
          :orderFeesList="advantageProjectData"
          :disabled="detailData.seeDisabled"
          feeUrl="/trade-purchase/purchase-order/removeByFees"
          optionType="GN"
          itemType="采购"
          @beforeFinance="beforeFinance"
          :corpId="form.corpId"
        />
<!--        <containerTitle title="费用明细"></containerTitle>-->
<!--        <basic-container style="margin-bottom: 10px">-->
<!--          <avue-crud-->
<!--              :option="advantageProject"-->
<!--              v-model="advantageProjectForm"-->
<!--              :data="advantageProjectData"-->
<!--              ref="crudProject"-->
<!--              @row-save="rowSaveProject"-->
<!--              @row-update="rowUpdateProject"-->
<!--              @row-del="rowDelProject"-->
<!--              @saveColumn="saveColumn('fees')"-->
<!--          >-->
<!--            <template slot="code" slot-scope="{row,index}">-->
<!--              <el-button type="text" size="mini" style="padding:4px 10px;float:left" @click="choice(row)" :disabled="detailData.seeDisabled || !row.$cellEdit">选择</el-button>-->
<!--              <span>{{ row.code }}</span>-->
<!--            </template>-->
<!--            <template slot="corpId" slot-scope="{ row }">-->
<!--              <selectComponent v-if="row.$cellEdit" v-model="row.corpId"-->
<!--                               :configuration="configuration" @receiveList="receiveList" typeData="GYS"/>-->
<!--              <span v-else>-->
<!--                <span v-for="item in configuration.dicData" v-if="item.id == row.corpId">{{ item.cname }}</span>-->
<!--              </span>-->
<!--            </template>-->
<!--            <template slot="amount" slot-scope="{ row }">-->
<!--              <el-input v-if="row.$cellEdit" v-model.trim="row.amount"-->
<!--                        size="small" v-input-limit="2"-->
<!--              ></el-input>-->
<!--              <span v-else>{{ row.amount }}</span>-->
<!--            </template>-->
<!--            <template slot="settlmentAmount" slot-scope="{ row }">-->
<!--              <el-input v-if="row.$cellEdit" v-model.trim="row.settlmentAmount"-->
<!--                        size="small" v-input-limit="2"-->
<!--              ></el-input>-->
<!--              <span v-else>{{ row.settlmentAmount }}</span>-->
<!--            </template>-->
<!--            <template slot-scope="{row,index}" slot="menu">-->
<!--              <el-button-->
<!--                  type="text"-->
<!--                  size="small"-->
<!--                  @click="rowCellTwo(row,index)"-->
<!--                  :disabled="detailData.seeDisabled"-->
<!--              >{{ row.$cellEdit ? '保存' : '修改' }}-->
<!--              </el-button>-->
<!--              <el-button-->
<!--                size="small"-->
<!--                icon="el-icon-delete"-->
<!--                type="text"-->
<!--                @click="rowDelProject(row, index)"-->
<!--                :disabled="detailData.seeDisabled"-->
<!--                v-if="!row.$cellEdit"-->
<!--              >删 除</el-button>-->
<!--            </template>-->
<!--            <template slot="menuLeft" slot-scope="{size}">-->
<!--              <el-button type="primary"-->
<!--                         icon="el-icon-plus"-->
<!--                         size="small"-->
<!--                         @click="costIncrease"-->
<!--                         :disabled="detailData.seeDisabled"-->
<!--              >录入明细-->
<!--              </el-button>-->
<!--            </template>-->
<!--          </avue-crud>-->
<!--        </basic-container>-->
        <containerTitle title="附件上传"></containerTitle>
        <basic-container style="margin-bottom: 40px">
          <avue-crud
              :option="bankOfDeposit"
              v-model="bankOfDepositForm"
              :data="bankOfDepositData"
              @row-save="rowSaveBankOfDeposit"
              @row-update="rowUpdateBankOfDeposit"
              @row-del="rowDelBankOfDeposit"
              :upload-after="uploadAfter"
              ref="uploadCrud"
          >
            <template slot="menuLeft">
              <el-button
                type="primary"
                icon="el-icon-plus"
                size="small"
                @click.stop="$refs.uploadCrud.rowAdd()"
                :disabled="detailData.seeDisabled"
              >上传</el-button
              >
            </template>
            <template slot="menu" slot-scope="{ row, index }">
              <el-button
                size="small"
                icon="el-icon-edit"
                type="text"
                @click="$refs.uploadCrud.rowEdit(row, index)"
                :disabled="detailData.seeDisabled"
              >编 辑</el-button
              >
              <el-button
                size="small"
                icon="el-icon-delete"
                type="text"
                @click="rowDelBankOfDeposit(row, index)"
                :disabled="detailData.seeDisabled"
              >删 除</el-button
              >
            </template>
          </avue-crud>
        </basic-container>
      </el-form>
    </div>
    <el-dialog
        title="导入商品"
        append-to-body
        class="el-dialogDeep"
        :visible.sync="dialogVisible"
        width="80%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        @close="closeGoods">
      <el-row :style="{height: rowHeight}">
        <el-col :span="5" style="height: 100%;overflow-y: auto">
          <div>
            <el-scrollbar>
              <basic-container>
                <avue-tree :option="treeOption" :data="treeDataGoods" @node-click="nodeClick"/>
              </basic-container>
            </el-scrollbar>
          </div>
        </el-col>
        <el-col :span="19">
          <basic-container>
            <avue-crud :option="optionTwo"
                       :table-loading="loading"
                       :data="goodsListShow"
                       ref="crud"
                       @refresh-change="refreshChange"
                       @selection-change="selectionChange"
                       :page.sync="page"
                       @search-change="goodsSearch"
                       @on-load="onLoad">
              <template slot="menuLeft" slot-scope="{size}">
                <el-tabs v-model="activeName" @tab-click="tabHandle">
                  <el-tab-pane label="查询结果" name="searchList"></el-tab-pane>
                  <el-tab-pane label="已选定数据" name="importStaging"></el-tab-pane>
                </el-tabs>
              </template>
              <template slot-scope="scope" slot="menu">
                <el-button
                  type="text"
                  icon="el-icon-edit"
                  size="small"
                  @click.stop="importStagList(scope.row,scope.index)"
                  v-if="activeName=='searchList'"
                  :disabled="goodsListSave.findIndex(item => item.id == scope.row.id) !== -1"
                >选择
                </el-button>
                <el-button
                  type="text"
                  icon="el-icon-delete"
                  size="small"
                  @click.stop="removeStagList(scope.row,scope.index)"
                  v-else
                >移除
                </el-button>
              </template>
            </avue-crud>
          </basic-container>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="importGoods" v-if="commodityData !== true">导入</el-button>
          <el-button type="primary" @click="importChoice" v-if="commodityData === true"
                     :disabled="tableData.length !== 1">导入</el-button>
        </span>
    </el-dialog>
    <el-dialog
        title="导入费用"
        append-to-body
        class="el-dialogDeep"
        :visible.sync="dialogCost"
        width="80%"
        :close-on-click-modal="false"
        :destroy-on-close="true"
        :close-on-press-escape="false"
        @close="closeFees">
      <el-row :style="{height: rowHeight}">
        <el-col :span="5" style="height: 100%;overflow-y: auto">
          <div>
            <el-scrollbar>
              <basic-container>
                <avue-tree :option="treeOptionCost" :data="treeData" @node-click="nodeClickCost"/>
              </basic-container>
            </el-scrollbar>
          </div>
        </el-col>
        <el-col :span="19">
          <basic-container>
            <avue-crud :option="optionTwoCost"
                       :table-loading="loadingCost"
                       :data="dataCost"
                       ref="crud"
                       @refresh-change="refreshChangeCost"
                       @selection-change="selectionChangeCost"
                       :page.sync="pageCost"
                       @searchChange="feesSearch"
                       @on-load="onLoadCost">
            </avue-crud>
          </basic-container>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
          <el-button @click="dialogCost = false">取 消</el-button>
          <el-button type="primary" @click="importCost" v-if="choiceData !== true">导入</el-button>
          <el-button type="primary" @click="choiceCost" v-if="choiceData === true"
                     :disabled="tableDataCost.length !== 1">导入</el-button>
        </span>
    </el-dialog>

    <el-dialog
      title="账单"
      append-to-body
      class="el-dialogDeep"
      :visible.sync="applyPaymentDialog"
      width="60%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      v-dialog-drag
    >
      <apply-payment
        :billType="billType"
        :billData="billData"
        itemType="采购"
        @choceFun="choceFun"
      >
      </apply-payment>
    </el-dialog>

    <el-dialog
      append-to-body
      title="账单"
      class="el-dialogDeep"
      :visible.sync="financialAccountDialog"
      width="70%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      v-dialog-drag
    >
      <financial-account
        :billType="billType"
        :billData="{}"
        :arrList="applyPaymentList"
        :checkData="financeData"
        @choceFun="choceFun"
      >
      </financial-account>
    </el-dialog>

    <el-dialog
      title="申请记录"
      append-to-body
      class="el-dialogDeep"
      :visible.sync="applicationDialog"
      width="60%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      v-dialog-drag
    >
      <bill-application
        :billId="form.id"
        @choceApplication="choceApplication"
      >
      </bill-application>
    </el-dialog>
    <report-dialog
      :switchDialog="switchDialog"
      :reportId="form.id"
      reportName="发货通知单"
      @onClose="onClose()"
    ></report-dialog>
    <el-dialog
      append-to-body
      title="审批"
      class="el-dialogDeep"
      :visible.sync="checkDialog"
      width="50%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      v-dialog-drag
    >
      <check
        :checkData="checkData"
        :checkDetail="false"
        :idList="[]"
        @choceCheckFun="choceCheckFun"
      >
      </check>
    </el-dialog>
    <el-dialog
      append-to-body
      title="审批进度"
      class="el-dialogDeep"
      :visible.sync="checkScheduleDialog"
      width="40%"
      :close-on-click-modal="false"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      v-dialog-drag
    >
      <check-schedule
        :checkId="checkId"
        :batchNo="batchNo"
        @choceScheduleFun="choceScheduleFun"
      >
      </check-schedule>
    </el-dialog>
  </div>
</template>

<script>
import {
  typeSave,
  detail,
  corpsattn,
  corpsbank,
  corpsitem,
  // getList,
  getDeptLazyTreeS,
  getSysNo,
  generateShipment
} from "@/api/basicData/purchaseOrder"
import {getList} from "@/api/basicData/commodityType";
import customerContact from "./configuration/customerContact.json"
import advantageProject from "./configuration/advantageProject.json"
import bankOfDeposit from "./configuration/bankOfDeposit.json"
import commodity from "./configuration/commodity.json"
import optionTwoCost from "./configuration/mainListCost.json"
import {getDeptLazyTree, customerList} from "@/api/basicData/basicFeesDesc";
import {selectGoodsNum} from "@/api/basicData/inventoryAccount"
import { contrastObj, contrastList } from "@/util/contrastData";
//账单组件
import ApplyPayment from "../../../components/finance/applyPayment";
import  billApplication from "@/components/bill/billApplication";
import { getlistBankBy, pleaseCheck, } from "@/api/basicData/configuration"
import feeInfo from "@/components/fee-info/main";
import {
  isDiscount,
  isPercentage,
  micrometerFormat,
  IntegerFormat
} from "@/util/validate";
import financialAccount from "../../../components/finance/financialAccount";
import reportDialog from "@/components/report-dialog/main";
import check from "@/components/check/check";
import checkSchedule from "@/components/check/checkSchedule";
import { customerList as feeList } from "@/api/basicData/basicFeesDesc";

export default {
  name: "detailsPage",
  props: {
    detailData: {
      type: Object,
      default: {
        seeDisabled: false
      }
    }
  },
  components:{
    ApplyPayment,
    billApplication,
    feeInfo,
    financialAccount,
    reportDialog,
    check,
    checkSchedule,
  },
  data() {
    return {
      configuration: {
        multipleChoices: false,
        multiple: false,
        collapseTags: false,
        placeholder: '请点击右边按钮选择',
        dicData: []
      },
      goodsConfiguration: {
        multipleChoices: false,
        multiple: false,
        collapseTags: false,
        placeholder: '请点击右边按钮选择',
        dicData: []
      },
      form: {},
      data: [],
      loadingCost: false,
      choiceData: false,
      commodityData: false,
      financialAccountDialog:false,
      dataCost: [],
      choiceIndex: '',
      dialogCost: false,
      treeDeptId: '',
      treeDeptIdCost: '',
      pageCost: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      loading: false,
      contactsForm: {},
      optionTwo: commodity,
      optionTwoCost: optionTwoCost,
      treeDataGoods: [],
      treeData: [],
      treeOptionCost: {
        nodeKey: 'id',
        lazy: true,
        treeLoad: function (node, resolve) {
          const parentId = (node.level === 0) ? 0 : node.data.id;
          getDeptLazyTree(parentId).then(res => {
            resolve(res.data.data.map(item => {
              return {
                ...item,
                leaf: !item.hasChildren
              }
            }))
          });
        },
        addBtn: false,
        menu: false,
        size: 'small',
        props: {
          labelText: '标题',
          label: 'title',
          value: 'value',
          children: 'children'
        }
      },
      treeOption: {
        nodeKey: 'id',
        lazy: true,
        treeLoad: function (node, resolve) {
          const parentId = (node.level === 0) ? 0 : node.data.id;
          getDeptLazyTreeS(parentId).then(res => {
            console.log(res.data.data)
            resolve(res.data.data.map(item => {
              return {
                ...item,
                leaf: !item.hasChildren
              }
            }))
          });
        },
        addBtn: false,
        menu: false,
        size: 'small',
        props: {
          labelText: '标题',
          label: 'title',
          value: 'value',
          children: 'children'
        }
      },
      billType:"申请",  //账单类型
      billData:{},     //账单需要数据
      financeData: {}, // 账单请核需要的路由
      applyPaymentDialog:false,//生成账单组件
      applicationDialog: false,// 申请记录
      dialogVisible: false,
      advantageProjectForm: {},
      bankOfDepositForm: {},
      contactsData: [],
      advantageProjectData: [],
      saveLoading: false,
      disabled: false,
      bankOfDepositData: [],
      tableDataCost: [],
      dic: [],
      tableData: [],
      customerContact: {},
      advantageProject: {},
      bankOfDeposit: bankOfDeposit,
      basicData: {
        column: [
          {
            label: '供应商',
            prop: 'corpId',
            span: 16,
            rules: [
              {
                required: true,
                message: ' ',
                trigger: 'blur'
              }
            ]
          },{
            label: '付款方式',
            prop: 'paymentType',
            rules: [
              {
                required: true,
                message: ' ',
                trigger: 'blur'
              }
            ]
          },{
            label: '银行账号',
            prop: 'banks',
            rules: [
              {
                required: true,
                message: ' ',
                trigger: 'blur'
              }
            ]
          }, {
            label: '公司户头',
            prop: 'banksAccountName',
            rules: [
              {
                required: false,
                message: ' ',
                trigger: 'blur'
              }
            ]
          }, {
            label: '包装要求',
            prop: 'packageRemarks',
            rules: [
              {
                required: false,
                message: ' ',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '系统编号',
            prop: 'sysNo',
            disabled: true,
            rules: [
              {
                required: false,
                message: ' ',
                trigger: 'blur'
              }
            ]
          }, {
            label: '来源单号',
            prop: 'orgOrderNo',
            disabled: true,
            rules: [
              {
                required: false,
                message: ' ',
                trigger: 'blur'
              }
            ]
          },
          // {
          //   label: '预估运费',
          //   prop: 'predictOceanFreight',
          //   type: 'number',
          //   rules: [
          //     {
          //       required: false,
          //       message: ' ',
          //       trigger: 'blur'
          //     }
          //   ]
          // },
          {
            label: '要求到货日期',
            prop: 'requiredArrivalDate',
            type: 'datetime',
            rules: [
              {
                required: true,
                message: ' ',
                trigger: 'blur'
              }
            ]
          }, {
            label: '已付金额',
            prop: 'settlmentAmount',
            type: 'number',
            disabled: true,
            rules: [
              {
                required: false,
                message: ' ',
                trigger: 'blur'
              }
            ]
          },{
            label: "备注",
            span: 24,
            prop: "orderRemark",
            type: 'textarea',
            mock: {
              type: 'county'
            }
          }
        ]
      },
      paymentOption: [],
      maxFeeNum: 0,
      maxGoodsNum: 0,
      selection: [],
      oldForm: {
        orderStatus: "录入"
      },
      oldGoodsList: [],
      oldFeesList: [],
      oldUploadList: [],
      // 弹窗高度
      rowHeight: '',
      // 查询时loading页面
      pageLoading: false,
      // 银行账号下拉
      bankList: [],
      activeName: 'searchList',
      // 商品列表数据合计
      goodsListShow: [],
      // 商品列表暂存
      goodsListSave: [],
      goodsListTotal: 0,
      goodsListSaveTotal: 0,
      pageList: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      itemType: '采购',
      packageOptions: [],
      switchDialog: false,
      // 请核状态禁用
      browse: false,
      checkDisabled: false,
      checkData: {},
      checkDialog: false,
      checkScheduleDialog: false,
      checkId: '',
      batchNo:'',
      feesOption: [],
      applyPaymentList: [],
    }
  },
  mounted() {
    this.$nextTick(() => {
      // 监听浏览器高度变化，改变表格高度
      window.onresize = () => {
        this.rowHeight = (window.innerHeight - 130) + 'px'
      }
    })
  },
  filters: {
    IntegerFormat(num) {
      return IntegerFormat(num);
    }
  },
  //初始化查询
  async created() {
    this.rowHeight = (window.innerHeight - 130) + 'px'
    this.customerContact = customerContact
    console.log(this.customerContact)
    // this.customerContact = await this.getColumnData(this.getColumnName(18), customerContact);
    this.advantageProject = await this.getColumnData(this.getColumnName(19), advantageProject);
    this.getWorkDicts("payment_term").then(res => {
      this.paymentOption = res.data.data
    })
    this.getWorkDicts("packageRemarks").then(res => {
      this.packageOptions = res.data.data;
    });
    feeList().then(res => {
      this.feesOption = res.data.data.records
    })
    if (this.detailData.check) {
      this.checkDisabled = true
      this.batchNo = this.detailData.check.batchNo
    }
    if (this.detailData.id) {
      this.queryData(this.detailData.id)
    } else if(this.detailData.copyId) {
      this.queryData(this.detailData.copyId, true)
    } else {
    }
  },
  watch: {
  },
  methods: {
    // 明细查询
    queryData(id, isCopy = false) {
      this.pageLoading = true
      detail(id).then(res => {
        this.form = res.data.data;
        this.browse = this.form.status > 0? true: false
        this.contactsData = this.form.itemsVOList? this.form.itemsVOList: []
        this.advantageProjectData = this.form.orderFeesList? this.form.orderFeesList: []
        this.bankOfDepositData = this.form.orderFilesList? this.form.orderFilesList: []
        if (!this.form.itemsVOList) {
          this.contactsData = []
        } else {
          this.contactsData = this.form.itemsVOList
        }
        // if (!this.form.orderFeesList) {
        //   this.advantageProjectData = []
        // } else {
        //   this.advantageProjectData = this.form.orderFeesList
        // }
        // if (!this.form.orderFilesList) {
        //   this.bankOfDepositData = []
        // } else {
        //   this.bankOfDepositData = this.form.orderFilesList
        // }
        if (this.form.corpsName) {
          this.configuration.dicData = this.form.corpsName
        }
        let feesData = []
        this.advantageProjectData.forEach(item => {
          let a = {
            cname: item.corpName,
            id: item.corpId
          }
          feesData.push(a)
        })
        this.configuration.dicData = this.configuration.dicData.concat(feesData)
        // 去重
        this.removeRepeat()
        let goodsData = []
        this.form.orderItemsList = this.form.orderItemsList? this.form.orderItemsList: []
        this.form.orderItemsList.forEach(item => {
          let a = {
            cname: item.cname,
          }
          goodsData.push(a)
        })
        this.goodsConfiguration.dicData = [].concat(goodsData)
        this.removeGoodsRepeat()
        delete this.form.itemsVOList
        delete this.form.orderFeesList
        delete this.form.orderFilesList
        // delete this.form.corpsName
        // 获取最大值
        let num = []
        this.advantageProjectData.forEach(item => {
          num.push(item.sort)
        })
        if (num.length == 0) {
          this.maxFeeNum = 0;
        } else {
          this.maxFeeNum = num.reduce((a, b) => {
            return b > a? b: a;
          })
        }
        let goodsNum = []
        this.contactsData.forEach(item => {
          goodsNum.push(item.sort)
        })
        if (goodsNum.length == 0) {
          this.maxGoodsNum = 0;
        } else {
          this.maxGoodsNum = goodsNum.reduce((a, b) => {
            return b > a? b: a;
          })
        }
        this.oldGoodsList = []
        this.oldFeesList = []
        this.oldUploadList = []
        this.oldForm = Object.assign({}, this.form)
        this.oldGoodsList = this.deepClone(this.contactsData)
        this.oldFeesList = this.deepClone(this.advantageProjectData)
        this.oldUploadList = this.deepClone(this.bankOfDepositData)
        if (isCopy) {
          delete this.form.sysNo;
          delete this.form.id
          this.form.status = 0
          this.browse = false
          this.contactsData.forEach(item => {
            delete item.id
            delete item.pid
          })
          this.advantageProjectData.forEach(item => {
            delete item.id
            delete item.pid
          })
          this.bankOfDepositData.forEach(item => {
            delete item.id
            delete item.pid
          })
        }
      }).finally(() => {
        this.saveLoading = false
        this.pageLoading = false
      });
    },
    copyOrder() {
      this.queryData(this.form.id, true)
    },
    getGoodsRow(event,row) {
      row.priceCategory = event.goodsTypeName
      row.code = event.code
      row.typeno = event.typeno
      row.itemType = event.typeno
      row.itemId = event.id
    },
    receiveGoodList(data) {
      this.goodsConfiguration.dicData = this.goodsConfiguration.dicData.concat(data)
      this.removeGoodsRepeat()
    },
    getRow(event,row) {
      row.priceCategory = event[0].goodsTypeName
      row.code = event[0].code
      row.typeno = event[0].typeno
      row.itemType = event[0].typeno
      row.itemId = event[0].id
    },
    removeGoodsRepeat() {
      let obj = []
      this.goodsConfiguration.dicData = this.goodsConfiguration.dicData.reduce((current,next) => {
        obj[next.cname] ? '': obj[next.cname] = true && current.push(next)
        return current
      }, [])
    },
    getShipmentC() {
      for (let item in this.selection) {
        if (!this.selection[item].id) {
          return this.$message.error('选中数据有新数据，请先保存')
        }
      }
      if (this.$store.getters.domTakeStatus) {
        this.$alert("收货单存在,请保存发货单再进行操作", "温馨提示", {
          confirmButtonText: "确定",
          type: "warning",
          callback: action => {
            console.log(action);
          }
        });
      } else {
        this.generateShipmentC();
      }
    },
    //生成收货单
    generateShipmentC() {
      let lsit = []
      if (contrastObj(this.form, this.oldForm) ||
        contrastList(this.contactsData, this.oldGoodsList) ||
        contrastList(this.advantageProjectData, this.oldFeesList) ||
        contrastList(this.bankOfDepositData, this.oldUploadList)
      ) {
        this.$confirm("数据发生变化未有提交记录, 是否保存?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(async () => {
          await this.editCustomer(false, '收货')
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          });
        })
      } else {
        this.selection.forEach(item => {
          lsit.push(item.id)
        })
        let data = {
          id: this.form.id,
          orderItemIds: lsit
        }
        generateShipment(data).then(res => {
          this.$router.$avueRouter.closeTag("/businessManagement/receipt/index");
          this.$router.push({
            path: "/businessManagement/receipt/index",
            query: {form: JSON.stringify(res.data.data)},
          });
        })
      }
    },
    //点击行可编辑
    handleRowClick(row, event, column) {
      console.log(row.$index)
    },
    //商品编辑
    rowCell(row, index) {
      console.log(row)
      if (row.$cellEdit) {
        if (Number(row.orderQuantity) < Number(row.actualQuantity)) {
          return this.$message.error('订货数量不能小于发货数量')
        }
      }
      this.$refs.crudContact.rowCell(row, index)
    },
    //费用编辑
    rowCellTwo(row, index) {
      console.log(row)
      this.$refs.crudProject.rowCell(row, index)
    },
    //商品选中触发
    productSelection(selection) {
      this.selection = selection
    },
    //费用新增触发
    costIncrease() {
      this.dialogCost = !this.dialogCost
      this.choiceData = false
    },
    //商品新增触发
    commoditySelection() {
      this.dialogVisible = !this.dialogVisible
      this.tableData = []
      this.commodityData = false
      this.goodsListSave = [];
    },
    //点击费用明细选择触发
    choice(row) {
      this.dialogCost = !this.dialogCost
      this.choiceData = true
      console.log(row)
      this.choiceIndex = row.$index
    },
    //点击商品明细选择触发
    commodityChoice(row) {
      this.dialogVisible = !this.dialogVisible
      this.commodityData = true
      console.log(row)
      this.choiceIndexT = row.$index
    },
    //导入商品触发
    importChoice() {
      if (this.tableData.length === 1) {
        this.contactsData[this.choiceIndexT].cname = this.tableData[0].cname
        this.contactsData[this.choiceIndexT].code = this.tableData[0].code
        this.contactsData[this.choiceIndexT].typeno = this.tableData[0].typeno
        this.contactsData[this.choiceIndexT].itemType = this.tableData[0].typeno
        this.contactsData[this.choiceIndexT].itemId = this.tableData[0].id
        this.contactsData[this.choiceIndexT].priceCategory = this.tableData[0].goodsTypeName
        this.contactsData[this.choiceIndexT].orderQuantity = 0
        this.contactsData[this.choiceIndexT].price = 0
        this.contactsData[this.choiceIndexT].amount = 0
        selectGoodsNum({
          goodsId: this.tableData[0].id,
          itemType: this.tableData[0].typeno
        }).then(res => {
          this.contactsData[this.choiceIndexT].storageQuantity =  res.data.data
        })
      }
      this.dialogVisible = !this.dialogVisible
      this.commodityData = false
    },
    //费用编辑导入触发
    choiceCost() {
      if (this.tableDataCost.length === 1) {
        this.advantageProjectData[this.choiceIndex].feeName = this.tableDataCost[0].cname
        this.advantageProjectData[this.choiceIndex].itemId = this.tableDataCost[0].id
        this.advantageProjectData[this.choiceIndex].code = this.tableDataCost[0].code
      }
      this.dialogCost = !this.dialogCost
      this.choiceData = false
    },
    //费用导入触发
    importCost() {
      // this.advantageProjectForm = this.advantageProjectForm.concat(this.tableDataCost)
      if (this.tableDataCost.length > 0) {
        for (let item in this.tableDataCost) {
          console.log(this.tableDataCost[item])
          this.tableDataCost[item].itemId = this.tableDataCost[item].id
          this.tableDataCost[item].feeName = this.tableDataCost[item].cname
          this.tableDataCost[item].sort = this.maxFeeNum + 1
          this.maxFeeNum++
          delete this.tableDataCost[item].id
          this.$refs.crudProject.rowCellAdd(this.tableDataCost[item]);
          this.$refs.crudProject.rowCell(this.tableDataCost[item], this.advantageProjectForm.length - 1)
        }
      }
      this.tableDataCost = []
      this.dialogCost = false
    },
    //确认导入触发
    importGoods() {
      if (this.goodsListSave.length > 0) {
        for (let item in this.goodsListSave) {
          selectGoodsNum({
            goodsId: this.goodsListSave[item].id,
            itemType: this.goodsListSave[item].typeno
          }).then(res => {
            this.$set(this.goodsListSave[item], 'storageQuantity', res.data.data)
            this.goodsListSave[item].itemId = this.goodsListSave[item].id
            this.goodsListSave[item].priceCategory = this.goodsListSave[item].goodsTypeName
            delete this.goodsListSave[item].id
            this.$set(this.goodsListSave[item], 'itemType', this.goodsListSave[item].typeno)
            this.$set(this.goodsListSave[item], 'specificationAndModel', this.goodsListSave[item].typeno)
            this.$set(this.goodsListSave[item], 'priceType', '一般')
            this.$set(this.goodsListSave[item], 'orderQuantity', 0)
            this.$set(this.goodsListSave[item], 'actualQuantity', 0)
            this.goodsListSave[item].price = 0
            this.goodsListSave[item].amount = 0
            this.goodsListSave[item].sort = this.maxGoodsNum + 1
            this.maxGoodsNum++
            this.$refs.crudContact.rowCellAdd(this.goodsListSave[item]);
            // this.$refs.crudContact.rowCell(this.goodsListSave[item], this.goodsListSave.length - 1)
          })
        }
      } else {
        for (let item in this.tableData) {
          selectGoodsNum({
            goodsId: this.tableData[item].id,
            itemType: this.tableData[item].typeno
          }).then(res => {
            this.$set(this.tableData[item], 'storageQuantity', res.data.data)
            this.tableData[item].itemId = this.tableData[item].id
            this.tableData[item].priceCategory = this.tableData[item].goodsTypeName
            delete this.tableData[item].id
            this.$set(this.tableData[item], 'itemType', this.tableData[item].typeno)
            this.$set(this.tableData[item], 'specificationAndModel', this.tableData[item].typeno)
            this.$set(this.tableData[item], 'priceType', '一般')
            this.$set(this.tableData[item], 'orderQuantity', 0)
            this.$set(this.tableData[item], 'actualQuantity', 0)
            this.tableData[item].price = 0
            this.tableData[item].amount = 0
            this.tableData[item].sort = this.maxGoodsNum + 1
            this.maxGoodsNum++
            this.$refs.crudContact.rowCellAdd(this.tableData[item]);
            // this.$refs.crudContact.rowCell(this.tableData[item], this.tableData.length - 1)
          })
        }
      }
      if (this.tableData.length > 0) {
      }
      this.dialogVisible = false
    },
    closeGoods() {
      this.treeDataGoods = [];
      this.treeDeptId = "";
      this.activeName = "searchList";
    },
    closeFees() {
      this.treeDeptIdCost = "";
      this.treeData = [];
    },
    //选中触发
    selectionChange(list) {
      console.log(list);
      this.tableData = list
    },
    //费用选中触发
    selectionChangeCost(list) {
      console.log(list);
      this.tableDataCost = list
    },
    //导入页左商品类型查询
    nodeClick(data) {
      this.treeDeptId = data.id;
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    //导入页左费用类型查询
    nodeClickCost(data) {
      this.treeDeptIdCost = data.id;
      this.pageCost.currentPage = 1;
      this.onLoadCost(this.pageCost);
    },
    //刷新触发
    refreshChange() {
      this.treeDeptId = '';
      this.page.currentPage = 1;
      this.onLoad(this.page);
    },
    //费用刷新触发
    refreshChangeCost() {
      this.treeDeptIdCost = '';
      this.pageCost.currentPage = 1;
      this.onLoadCost(this.pageCost);
    },
    //新增商品信息保存触发
    rowSave(row, done, loading) {
      console.log(row)
      console.log(this.contactsData)
      // this.contactsData.push(row)
      done()
    },
    //修改商品信息触发
    rowUpdate(row, index, done, loading) {
      done(row);
    },
    //删除商品信息触发
    rowDel(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //商品判断是否需要调用删除接口
        if (row.id) {
          corpsattn(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.contactsData.splice(index, 1);
          })
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.contactsData.splice(index, 1);
        }
      })
    },
    //新增费用明细保存触发
    rowSaveProject(row, done, loading) {
      // this.advantageProjectData.push(row)
      done()
    },
    //修改费用明细触发
    rowUpdateProject(row, index, done, loading) {
      done(row);
    },
    goodsSearch(params, done) {
      this.treeDeptId = '';
      this.onLoad(this.page, params);
      done()
    },
    //商品列表查询
    onLoad(page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query), this.treeDeptId).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.goodsListShow = data.records;
        this.loading = false;
      });
    },
    // 费用查询按钮
    feesSearch(params, done) {
      this.treeDeptIdCost = '';
      this.onLoadCost(this.pageCost, params)
      done()
    },
    //费用查询
    onLoadCost(page, params = {}) {
      this.loadingCost = true;
      let queryParams = Object.assign({}, params, {
        pageSize: page.pageSize,
        pageNum: page.currentPage,
        parentId: 0,
        feesTypeId: this.treeDeptIdCost
      })
      customerList(queryParams).then(res => {
        console.log(res)
        const data = res.data.data;
        this.pageCost.total = data.total;
        this.dataCost = data.records;
        this.loadingCost = false;
      });
    },
    //删除费用明细触发
    rowDelProject(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //费用判断是否需要调用删除接口
        if (row.id) {
          corpsitem(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.advantageProjectData.splice(index, 1);
          })
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.advantageProjectData.splice(index, 1);
        }
      })
    },
    //新增附件上传保存触发
    rowSaveBankOfDeposit(row, done, loading) {
      this.bankOfDepositData.push(row)
      done()
    },
    //修改附件上传触发
    rowUpdateBankOfDeposit(row, index, done, loading) {
      done(row);
    },
    //删除附件上传触发
    rowDelBankOfDeposit(row, index, donerowDel) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        //附件判断是否需要调用删除接口
        if (row.id) {
          corpsbank(row.id).then(res => {
            this.$message({
              type: "success",
              message: "操作成功!"
            });
            this.bankOfDepositData.splice(index, 1);
          })
        } else {
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.bankOfDepositData.splice(index, 1);
        }
      })
    },
    uploadAfter(res, done) {
      if (res.originalName) {
        this.bankOfDepositForm.fileName = this.bankOfDepositForm.fileName
          ? this.bankOfDepositForm.fileName
          : res.originalName;
      }
      done();
    },
    // 计算费用
    changeContractAmt(row) {
      let orderQuantity = 0;
      let purchaseAmount = 0;
      if (row.price) {
        purchaseAmount = row.purchaseAmount;
      }
      if (row.orderQuantity) {
        orderQuantity = row.orderQuantity;
      }
      this.$set(row, "amount", Number(orderQuantity) * Number(purchaseAmount)).toFixed(2);
    },
    // 去重
    removeRepeat() {
      let obj = []
      this.configuration.dicData = this.configuration.dicData.reduce((current,next) => {
        obj[next.id] ? '': obj[next.id] = true && current.push(next)
        return current
      }, [])
    },
    receiveList(data){
      this.configuration.dicData = this.configuration.dicData.concat(data)
      this.removeRepeat()
    },
    //修改提交触发
    editCustomer(isBack = false, type) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          for (let item in this.contactsData) {
            if (Number(this.contactsData[item].orderQuantity) < Number(this.contactsData[item].actualQuantity)) {
              return this.$message.error('商品信息第'+ (parseInt(item) + 1) + '行订货数量不能小于发货数量')
            }
          }
          this.form.orderAmount = 0;
          this.contactsData.forEach(item => {
            this.form.orderAmount = Number(this.form.orderAmount) + Number(item.amount)
          })
          //商品信息
          this.form.itemsVOList = this.contactsData
          // this.form.orderFeesList = this.advantageProjectData
          this.form.orderFeesList = this.$refs.feeInfo.submitData()
          this.form.orderFilesList = this.bankOfDepositData
          if (typeof this.form.corpsTypeId == 'object') {
            this.form.corpsTypeId = this.form.corpsTypeId.join(",")
          }

          this.saveLoading = true
          this.form.billType = 'CG'
          this.$set(this.form, 'tradeType', 'GN')
          // 如果有id解锁，没有跳过
          this.form.id && this.unLock({moduleName: 'cg',tableName: 'business_order', billId: this.form.id})
          typeSave(this.form).then(res => {
            this.$message({type: "success", message: this.form.id ? "修改成功!" : "新增成功!"});
            this.detailData.seeDisabled = true;
            if (isBack) {
              //成功关闭此页面回到列表页
              this.$emit("goBack");
            } else {
              this.queryData(res.data.data)
            }
            if (type == '收货') {
              let lsit = []
              this.selection.forEach(item => {
                lsit.push(item.id)
              })
              let data = {
                id: this.form.id,
                orderItemIds: lsit
              }
              generateShipment(data).then(res => {
                this.$router.$avueRouter.closeTag("/businessManagement/receipt/index");
                this.$router.push({
                  path: "/businessManagement/receipt/index",
                  query: {form: JSON.stringify(res.data.data)},
                });
              })
            }
          }).catch(() => {
            this.saveLoading = false
          })
        } else {
          return false;
        }
      });
    },
    beforeBillData(bool,type){
      this.applyPaymentList = [];
      let arr = [];
      this.billType = type
      this.financeData = {
        url:"/financialManagement/paymentRequest/index",
        pageStatus:"this.$store.getters.pqStatus",
        pageLabel:"付费申请",
        checkType: 'ffsq'
      }
      //采购明细提单号 list
      this.billData = {
        srcOrderno:this.form.orderNo,
        itemType:"采购",
        corpsName:this.form.corpsName,
        corpId:this.form.corpId,
        srcParentId: this.form.id,
        currency: 'CNY',
        exchangeRate: '1',
        taxRate: '0',
        accDate: this.form.businesDate,
        srcType: 1,
        tradeType: 'GN',
        optionType: 'GN',
        amount: this.form.orderAmount,
        costType: this.feesOption.find(e => e.cname == '货款').id
      }
      arr.push(this.billData)
      let getFeeList = this.$refs.feeInfo.submitData().filter(item => item.feesType == 2)
      getFeeList.forEach(item => {
        let form = {
          srcOrderno:this.form.orgOrderNo,
          itemType:"采购",
          corpsName:item.corpName,
          corpId: item.corpId,
          srcParentId: this.form.id,
          currency: 'CNY',
          exchangeRate: '1',
          taxRate: '0',
          accDate: this.form.businesDate,
          srcType: 2,
          tradeType: 'GN',
          optionType: 'GN',
          chargeMember: this.form.chargeMember,
          parentId: this.form.id,
          amount: item.amount,
          costType: item.itemId,
          srcFeesId: item.id,
        }
        arr.push(form)
      })
      this.applyPaymentList = [...arr]
      if(bool){ //申请货款
        // this.billData.srcId = -1
      }
    },
    // 查看申请记录
    openApplicationDialog(){
      this.applicationDialog = true
    },
    //关闭申记录
    choceApplication(){
      this.applicationDialog = false
    },
    //申请货款
    applyPayment(type){
      // if (contrastObj(this.form, this.oldForm) ||
      //   contrastList(this.contactsData, this.oldGoodsList) ||
      //   contrastList(this.advantageProjectData, this.oldFeesList) ||
      //   contrastList(this.bankOfDepositData, this.oldUploadList)
      // ) {
      //   this.$confirm("您已改动数据,是否先保存在进行操作!", {
      //     confirmButtonText: "保存",
      //     cancelButtonText: "取消",
      //     type: "warning"
      //   }).then(() => {
      //     this.editCustomer();
      //   })
      // }else{
        this.beforeBillData(true,type);
        this.financialAccountDialog = true;
      // }

    },
    //关闭账单
    choceFun(){
      this.financialAccountDialog  = false
    },
    //返回列表
    backToList() {
      if (contrastObj(this.form, this.oldForm) ||
        contrastList(this.contactsData, this.oldGoodsList) ||
        contrastList(this.advantageProjectData, this.oldFeesList) ||
        contrastList(this.bankOfDepositData, this.oldUploadList)
      ) {
        this.$confirm("数据发生变化未有提交记录, 是否提交?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.editCustomer(true)
        }).catch(() => {
          this.$emit("goBack");
        })
      } else {
        this.$emit("goBack");
      }
    },
    // 保存列设置
    async saveColumn(name) {
      if (name == 'goods') {
        const inSave = await this.saveColumnData(
          this.getColumnName(18),
          this.customerContact
        );
        if (inSave) {
          this.$message.success("保存成功");
          //关闭窗口
          this.$refs.crudContact.$refs.dialogColumn.columnBox = false;
        }
      } else if (name === 'fees') {
        const inSave = await this.saveColumnData(
          this.getColumnName(19),
          this.advantageProject
        );
        if (inSave) {
          this.$message.success("保存成功");
          //关闭窗口
          this.$refs.crudProject.$refs.dialogColumn.columnBox = false;
        }
      }
    },
    async resetColumn() {
      const inSave = await this.delColumnData(
        this.getColumnName(18),
        customerContact
      );
      if (inSave) {
        this.$message.success("重置成功");
        //关闭窗口
        this.$refs.crudContact.$refs.dialogColumn.columnBox = false;
      }
    },
    returnBack(row) {
      this.$set(this.form, 'paymentType', row.paymentType)
      this.$set(this.form, 'packageRemarks', row.packageRemarks)
      getlistBankBy(row.id).then(res =>{
        this.$set(this.form, 'banks', null)
        this.$set(this.form, 'banksAccountName', null)
        this.$set(this.form, 'accountBank', null)
        this.bankList = res.data
        if (this.bankList.length > 0) {
          this.form.banks = this.bankList[0].accountNo
          this.form.banksAccountName = this.bankList[0].accountName
          this.form.accountBank = this.bankList[0].accountBank
        }
      })
    },
    // 银行账号变化
    banksChange(val) {
      let isTrue = false
      this.bankList.forEach(item => {
        if (val == item.accountNo) {
          this.$set(this.form, 'banksAccountName', item.accountName)
          this.$set(this.form, 'accountBank', item.accountBank)
          isTrue = true
        }
      })
      if (!isTrue) {
        this.$set(this.form, 'banksAccountName', null)
        this.$set(this.form, 'accountBank', null)
      }
    },
    // 标签页切换
    tabHandle(data) {
      if (data.name == 'searchList') {
        this.goodsListShow = this.data;
        this.page.total = this.pageList.total
      } else if (data.name == 'importStaging') {
        this.goodsListShow = this.goodsListSave;
        this.page.total = 0
      }
    },
    removeStagList(row, index) {
      this.goodsListSave.splice(index, 1)
    },
    importStagList(row, index) {
      this.goodsListSave.push(row);
    },
    beforeFinance(feesData,callback) {
      this.advantageProjectData = feesData;
      let params = {}
      params.valid = true
      params.parentId = this.form.id
      params.srcOrderno = this.form.orderNo
      callback(params)
    },
    // 报表
    openReport() {
      this.switchDialog =! this.switchDialog;
    },
    onClose(val) {
      this.switchDialog = val;
    },
    //请核
    pleaseCheck() {
      // this.verification()
      if (this.verification()) {
        this.$confirm("您确定提交此次申请吗？", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          const data = {
            id : this.form.id,
            checkType: 'cgqh',
            url: '/businessManagement/purchaseOrder/index',
            pageStatus:"this.$store.getters.domPurStatus",
            pageLabel:"采购订单(N)",
            checkFlag: 1,
          }
          this.pageLoading = true
          pleaseCheck(data).then(res => {
            this.$message.success('请核成功')
            // this.pageLoading = false
            this.saveActives = ''
            this.queryData(this.form.id)
          }).finally(() => {
            this.pageLoading = false
          })
        })
      } else {
      }
    },
    verification() {
      let getFeeList = this.$refs.feeInfo.submitData()
      if (contrastObj(this.form, this.oldForm) ||
        contrastList(this.contactsData, this.oldGoodsList) ||
        // contrastList(getFeeList, this.oldFeesList) ||
        contrastList(this.bankOfDepositData, this.oldUploadList)
      ) {
        this.$confirm("数据发生变化未有提交记录, 是否提交?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.editCustomer(false)
        }).catch(() => {
          return false;   //取消改动数据
        })
      } else {
        return true;  //没有动过数据
      }
    },
    //打开审核
    openCheckDialog(){
      this.checkData  = this.detailData.check
      this.checkDialog = true;
    },
    //关闭审核
    choceCheckFun(){
      this.checkDialog = false;
    },
    choceScheduleFun(){
      this.checkScheduleDialog = false
    },
    editHandle() {
      const data = {
        moduleName: 'cg',
        tableName: 'business_order',
        billId: this.form.id,
        no: 87654567
      }
      this.saveLoading = true
      this.checkLock(data).then(res => {
        if (res.data.code == 200) {
          this.onLock(data).then(response => {
          })
          this.detailData.seeDisabled = false;
        }
      }).catch(error => {
      }).finally(() => {
        this.saveLoading = false
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.back-icon {
  line-height: 64px;
  font-size: 20px;
  margin-right: 8px;
}

//.add-customer-btn {
//  position: fixed;
//  right: 36px;
//  top: 115px;
//}

::v-deep .el-form-item {
  margin-bottom: 0;
}

.el-dialogDeep {
  ::v-deep .el-dialog {
    margin: 1vh auto 0 !important;
    padding-bottom: 10px !important;

    .el-dialog__body, .el-dialog__footer {
      padding-bottom: 0 !important;
      padding-top: 0 !important;
    }
  }
}

.print-div {
  color: #000;
}

.print_table {
  table {
    border-right: 1px solid #000;
    border-bottom: 1px solid #000;
    font-size: 12px;
    margin-bottom: 5px;
  }

  table td {
    border-left: 1px solid #000;
    border-top: 1px solid #000;
    vertical-align: middle;
    padding: 2px;
    text-align: center;
  }
}

.table {
  border-collapse: collapse;
  border-spacing: 0;
  background-color: transparent;
  display: table;
  width: 99%;
  max-width: 100%;
  margin: 0 auto;
}

.table td {
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
  color: #000000;
  padding: 10.5px 0 10.5px 30px;
  //border: 1px solid #000;
}
::v-deep .el-form-item {
  margin-bottom: 0;
}

::v-deep .el-form-item__content{
  line-height: 32px;
}
</style>
