<!--修改-提成和额外金额-->
<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">
        <div class="col">
          <q-radio v-model="FinanceMsg.IsPublic" :val="0" label="私账" />
          <q-radio v-model="FinanceMsg.IsPublic" :val="1" label="公账" />
        </div>
        <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>
        <div class="text-h6">账号信息</div>
        <q-card-section class="q-pt-none scroll">
          <div class="col">
            <q-radio v-model="IsAddBankCount" :val="0" label="选择账号" />
            <q-radio v-model="IsAddBankCount" :val="1" label="添加账号" />
          </div>
          <template v-if="IsAddBankCount==0">
            <div class="col">
              <q-select standout="bg-primary text-white" option-value="ID" option-label="AccountAlias"
                v-model="FinanceMsg.ClientId" :options="BankAccountList" emit-value map-options label="选择账号"
                class="col-6 q-pr-lg q-pb-lg" />
            </div>
          </template>
          <template v-else>
            <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" />
            </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="例如:中国银行" />
            </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="例如:锦江支行" />
            </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" />
            </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" />
            </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" />
            </div>
          </template>
        </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: 0, //公账、私账
          CurrencyId: 0, //币种
          BackClassId: 0, //退课编号
          ClientType: 10,
          ClientId: 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: 3,
            Name: "虚拟账户"
          },
          {
            Id: 4,
            Name: "微信支付宝"
          }
        ],
        nameA: "账号名称",
        nameB: "开户人",
        nameC: "卡号",
        nameD: "账号别名",
        BankAccountList: [], //银行账号列表，
        IsAddBankCount: 0, //0-选择账号，1-添加账号
      }
    },
    created() {
      this.FinanceMsg.BackClassId = this.setingObj.BackId;
      this.addMsg.ObjID = this.setingObj.GuestId;
      this.financeinfo_post_GetList();
      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.IsAddBankCount == 0) {
          if (this.FinanceMsg.ClientId && this.FinanceMsg.ClientId > 0) {
            this.createStuBill();
          } else {
            this.$q.notify({
              type: 'negative',
              position: "top",
              message: `请选择收款账号,如果没有收款账号,请新增收款账号!`
            })
            return;
          }
        } else if (this.IsAddBankCount == 1) {
          if (this.addMsg.AccountClassify == 2) {
            if (this.addMsg.BankName == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请选择填写所属机构!`
              })
              return;
            }
            if (this.addMsg.OpenBankName == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写账号名称!`
              })
              return;
            }
            if (this.addMsg.AccountHolder == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写开户人!`
              })
              return;
            }
            if (this.addMsg.CardNum == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写卡号!`
              })
              return;
            }
            if (this.addMsg.AccountAlias == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写账户别名!`
              })
              return;
            }
          } else if (this.addMsg.AccountClassify == 3) {
            if (this.addMsg.CardNum == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写平台账号!`
              })
              return;
            }
            if (this.addMsg.AccountAlias == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写账户别名!`
              })
              return;
            }
          } else if (this.addMsg.AccountClassify == 4) {
            if (this.addMsg.CardNum == '') {
              this.$q.notify({
                type: 'negative',
                position: "top",
                message: `请填写账号!`
              })
              return;
            }
            if (this.addMsg.AccountAlias == '') {
              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();
            }
          })
        }
      },
      financeinfo_post_GetList() { // 获取币种
        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>
