<template>
  <q-dialog v-model="persistent" maximized full-height seamless position="right">
    <q-card style="margin-top:61px;width:500px" class="no-border-radius classinfo_Dialog">
      <div class="drawerTop">
        <div style="display:flex;align-items:center;margin-left:10px;">
          <span class="drawer_Span">学员报名</span>
        </div>
      </div>
      <div style="padding:20px 15px;">
        <q-input filled stack-label maxlength="4" :dense="false" v-model="enrollMsg.GuestNum" type="number"
          @input="countPrice" class="col-12" label="人数" :rules="[val => !!val || '请填写人数']" />
        <q-input filled stack-label :dense="false" maxlength="8" v-model="enrollMsg.Unit_Price"
          :disable="UPrice==true?false:true" @blur="countPrice" class="col-12" label="成交单价"
          :rules="[val => !!val || '请填成交单价']" />
        <q-select standout="bg-primary text-white" option-value="Id" option-label="Name" v-model="enrollMsg.OrderSource"
          :options="SourceEnumList" emit-value map-options label="客人来源" />
        <q-input filled stack-label type="textarea" maxlength="500" :dense="false" v-model="enrollMsg.SaleRemark"
          style="margin-top: 20px" class="col-12" label="备注" />
        <div style="margin:30px 10px 0 0;">
          <q-btn class="q-mr-md" label="取消" @click="persistent=false" />
          <q-btn color="accent" class="q-mr-md" label="保存" @click="saveSatMsg()" />
        </div>
      </div>
    </q-card>
    <div class="dialog-out-close" @click="persistent=false"
      style="height:40px !important;border-top-left-radius: 4px !important;border-bottom-left-radius: 4px !important;">
      <q-icon name="iconfont icon-jujue1" size="26px" />
    </div>
  </q-dialog>
</template>
<script>
  import {
    getOrderSourceEnumList, //获取订单来源 枚举
    setClassOrder, //新增 修改订单
  } from '../../api/sale/sale';
  export default {
    name: "studyOrder-form",
    props: {
      saveObj: {
        type: Object,
        default: null,
      },
    },
    data() {
      return {
        persistent: true,
        //学员报名
        enrollMsg: {
          ClassId: 0,
          GuestNum: 1,
          Unit_Price: 0, //成交单价
          PreferPrice: 0, //应收总额
          OrderSource: 0, //客人来源 枚举
          SaleRemark: '', //备注
          OrderType: 2, //订单类型(1-班级课程订单，2-留学就业订单)
          SourceId: 0, //来源变化
        },
        UPrice: 0, //单价
        SourceEnumList: [], //来源
      }
    },
    created() {
      this.getOrderSEList();
    },
    mounted() {
      this.enrollMsg.Unit_Price = this.saveObj.SellPrice;
      this.enrollMsg.SourceId = this.saveObj.Id;
      this.countPrice();
    },
    methods: {
      //获取客人来源列表
      getOrderSEList() {
        getOrderSourceEnumList({}).then(res => {
          if (res.Code == 1) {
            var tempArray = res.Data;
            this.SourceEnumList = tempArray;
            this.enrollMsg.OrderSource = tempArray[0].Id;
          }
        })
      },
      //计算价格
      countPrice() {
        var guestNum = 0;
        var unit_price = 0;
        if (this.enrollMsg.GuestNum && this.enrollMsg.GuestNum > 0) {
          guestNum = Number(this.enrollMsg.GuestNum);
        }
        if (this.enrollMsg.Unit_Price && this.enrollMsg.Unit_Price > 0) {
          unit_price = Number(this.enrollMsg.Unit_Price);
        }
        this.enrollMsg.PreferPrice = Number(guestNum * unit_price).toFixed(2);
      },
      //保存订单
      saveSatMsg() {
        setClassOrder(this.enrollMsg).then(res => {
          if (res.Code == 1) {
            this.$q.notify({
              icon: 'iconfont icon-chenggong',
              color: 'accent',
              timeout: 2000,
              message: '报名成功！',
              position: 'top'
            })
            this.$emit("save");
          }
        }).catch(() => {})
      },
    }
  }

</script>
