<!--修改-提成和额外金额-->
<template>
  <q-dialog v-model="persistent" content-class="bg-grey-1" persistent transition-show="scale" transition-hide="scale">
    <q-card style="width: 400px;max-width:500px;padding:0 20px;">
      <q-card-section>
        <div class="text-h6">一键制单</div>
      </q-card-section>
      <q-card-section class="q-pt-none scroll" style="max-height: 70vh;display:none;">
        <div class="col" style="margin-top: 20px">
          <q-select standout="bg-primary text-white" option-value="ID" option-label="Name"
            v-model="FinanceMsg.CurrencyId" :options="CurrencyList" emit-value map-options label="币种"
            class="col-6 q-pr-lg q-pb-lg" />
        </div>
      </q-card-section>
      <q-card-section>
        <q-card-section class="q-pt-none scroll">
          <div class="col">
            <q-select standout="bg-primary text-white" option-value="Id" option-label="Name"
              v-model="addMsg.AccountClassify" :options="AccountClassifyList" emit-value map-options label="账号分类"
              class="col-6 q-pr-lg q-pb-lg" @input="changeTitle" disable style="display:none;" />
          </div>
          <div class="col" v-if='addMsg.AccountClassify==2'>
            <q-input filled stack-label maxlength="100" :dense="false" v-model="addMsg.BankName"
              class="col-6 q-pr-lg q-pb-lg" label="所属机构" placeholder="例如:中国银行" disable />
          </div>
          <div class="col" v-if='addMsg.AccountClassify!=3 && addMsg.AccountClassify!=4'>
            <q-input filled stack-label maxlength="100" :dense="false" v-model="addMsg.OpenBankName"
              class="col-6 q-pr-lg q-pb-lg" :label="nameA" placeholder="例如:锦江支行" disable style="display:none;" />
          </div>
          <div class="col" v-if='addMsg.AccountClassify!=3 && addMsg.AccountClassify!=4'>
            <q-input filled stack-label maxlength="100" :dense="false" v-model="addMsg.AccountHolder"
              class="col-6 q-pr-lg q-pb-lg" :label="nameB" disable style="display:none;" />
          </div>
          <div class="col">
            <q-input filled stack-label maxlength="100" :dense="false" v-model="addMsg.CardNum"
              class="col-6 q-pr-lg q-pb-lg" :label="nameC" disable />
          </div>
          <div class="col">
            <q-input filled stack-label maxlength="100" :dense="false" v-model="addMsg.AccountAlias"
              class="col-6 q-pr-lg q-pb-lg" :label="nameD" disable style="display:none;" />
          </div>
        </q-card-section>
      </q-card-section>
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeStuBillForm" />
        <q-btn label="保存" color="accent" class="q-px-md" style="font-weight:400 !important" @click="addBack" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script>
  import {
    saveStudentBackFinance, //生成财务单据
  } from '../../api/sale/bill'
  export default {
    props: {
      setingObj: {
        type: Object,
        default: null,
      },
    },
    data() {
      return {
        persistent: true,
        FinanceMsg: {
          IsPublic: 1, //公账、私账(默认工作)
          CurrencyId: 21, //币种(默认人民币)
          ClientType: 10,
          ClientId: 0,
          BackClassId: 0, //退课编号
        },
        CurrencyList: [], //币种数组
        //添加常用付款对象
        addMsg: {
          Id: '0',
          ObjID: '-1',
          BankId: '-1',
          OpenBankName: '',
          BankName: '',
          AccountHolder: '',
          CardNum: '',
          AccountAlias: '',
          AccountType: '1',
          AccountClassify: 2,
          Type: '10',
        },
        //查询账号对象
        qBankMsg: {
          BranchId: '-1',
          EmpId: '-1',
          BankId: '',
          AccountHolder: '',
          AccountAlias: '',
          pageIndex: 1,
          pageSize: 100,
          Type: '',
        },
        AccountClassifyList: [{
            Id: 2,
            Name: "银行"
          },
          {
            Id: 4,
            Name: "微信支付宝"
          }
        ],
        nameA: "账号名称",
        nameB: "开户人",
        nameC: "卡号",
        nameD: "账号别名",
        BankAccountList: [], //银行账号列表，
      }
    },
    created() {
      this.FinanceMsg.BackClassId = this.setingObj.DataObj.BackId;
      this.addMsg.ObjID = this.setingObj.GuestId;
      this.addMsg.BankName = this.setingObj.DataObj.BackAccountName;
      this.addMsg.OpenBankName = this.setingObj.DataObj.BackAccountName;
      this.addMsg.CardNum = this.setingObj.DataObj.BackAccount;
      this.addMsg.AccountAlias = this.setingObj.DataObj.BackAccountName;
      //this.GetCurrencyList();
      //this.getGuestBankAccount()
    },
    mounted() {

    },
    methods: {
      //查询旅客的收款账号
      getGuestBankAccount() {
        this.qBankMsg.EmpId = this.setingObj.GuestId;
        this.qBankMsg.Type = 10;
        this.apipost("admin_get_GetEmpBankAccountPageList", this.qBankMsg, res => {
          if (res.data.resultCode == 1) {
            this.BankAccountList = res.data.data.pageData;
          }
        });
      },
      changeTitle() {
        if (this.addMsg.AccountClassify == 1) {
          this.nameA = "平台名称";
          this.nameB = "用户名称";
          this.nameC = "平台账户";
          this.nameD = "账号别名";
          this.addMsg.AccountType = '1'
        } else if (this.addMsg.AccountClassify == 2) {
          this.nameA = "账号名称";
          this.nameB = "开户人";
          this.nameC = "卡号";
          this.nameD = "账号别名";
        } else if (this.addMsg.AccountClassify == 3) {
          this.nameA = "平台名称";
          this.nameB = "用户名称";
          this.nameC = "平台账户";
          this.nameD = "账号别名";
        } else if (this.addMsg.AccountClassify == 4) {
          this.nameA = "平台名称";
          this.nameB = "用户名称";
          this.nameC = "账号"
          this.nameD = "名称"
        }
      },
      addBack() {
        if (this.addMsg.BankName == '') {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请选择填写所属机构!`
          })
          return;
        }
        if (this.addMsg.CardNum == '') {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请填写卡号!`
          })
          return;
        }
        this.apipost("admin_post_SetEmpBankAccount", this.addMsg, res => {
          if (res.data.resultCode == 1) {
            this.FinanceMsg.ClientId = res.data.data;
            this.createStuBill();
          }
        })
      },
      // 获取币种
      GetCurrencyList() {
        this.apipost('financeinfo_post_GetList', {
          Name: '',
          TCID: 0
        }, res => {
          if (res.data.resultCode == 1) {
            this.CurrencyList = res.data.data;
            this.FinanceMsg.CurrencyId = this.CurrencyList[0].ID
          }
        }, err => {})
      },
      //关闭弹窗
      closeStuBillForm() {
        this.persistent = false;
        this.$emit('close');
      },
      //保存修改
      createStuBill() {
        saveStudentBackFinance(this.FinanceMsg).then(res => {
          if (res.Code == 1) {
            this.persistent = false;
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '生成单据成功!',
              position: 'top'
            })
            this.$emit('success');
          }
        });
      }
    }
  }

</script>
