<!--转交订单-->
<template>
  <q-dialog v-model="IsShowTransOrderDialog" content-class="bg-grey-1" persistent transition-show="scale"
    transition-hide="scale">
    <q-card style="width: 400px;max-width:500px;">
      <q-card-section>
        <div class="text-h6">{{saveObj.type==1?'转交订单':'修改销售'}}</div>
      </q-card-section>
      <q-card-section>
        <div class="col row" style="justify-content: center;width: 100%">
          <q-select class="" filled :label="saveObj.type==1?'转交人':'修改销售'" v-model="TransOrderMsg.model" use-input hide-selected fill-input
            option-value="Id" option-label="EmployeeName" :options="emList" @filter="filterFn"
            style="width: 250px; padding-bottom: 32px">
            <template v-slot:no-option>
              <q-item>
                <q-item-section class="text-grey">
                  未查询到相关数据
                </q-item-section>
              </q-item>
            </template>
          </q-select>
        </div>
      </q-card-section>
      <q-card-actions align="right" class="bg-white">
        <q-btn label="取消" flat color="grey-10" style="font-weight:400 !important" @click="closeTransOrderForm" />
        <q-btn label="保存" color="accent q-px-md" style="font-weight:400 !important" @click="saveTransOrder()" />
      </q-card-actions>
    </q-card>
  </q-dialog>
</template>
<script>
  import {
    setClassOrderCareOf, //转交订单
    updateOrderSale
  } from '../../api/sale/sale'
  import {
    queryEmployee //员工列表
  } from '../../api/users/user'
  export default {
    name: "transOrder-form",
    props: {
      saveObj: {
        type: Object,
        default: null,
      },
      employeeList: {
        type: Array,
        default: null
      },
    },
    data() {
      return {
        IsShowTransOrderDialog: true,
        TransOrderMsg: {
          model: '',
          OrderId: 0,
        },
        emList:[],
      }
    },
    created() {
      this.emList=this.employeeList;
      this.initData();
    },
    methods: {
      //筛选员工
      filterFn(val, update) {
        update(() => {
          if (val === '') {
            this.emList = JSON.parse(JSON.stringify(this.employeeList))
          } else {
            const needle = val.toLowerCase()
            this.emList = this.employeeList.filter(v => v.EmployeeName.toLowerCase().indexOf(needle) > -1)
          }
        })
      },
      //关闭弹窗
      closeTransOrderForm() {
        this.IsShowTransOrderDialog = false;
        this.$emit('close');
      },
      //初始化数据
      initData() {
        this.TransOrderMsg.OrderId = this.saveObj.OrderId;
        this.IsShowTransOrderDialog = true;
      },
      //保存订单转交
      saveTransOrder() {

          if(this.saveObj.type==1){
            let transMsg = {
              OrderId: this.TransOrderMsg.OrderId,
              CareOfPeople: this.TransOrderMsg.model.Id
            }
            setClassOrderCareOf(transMsg).then(res => {
              if (res.Code == 1) {
                this.$q.notify({
                  icon: 'iconfont icon-chenggong',
                  color: 'accent',
                  timeout: 2000,
                  message: '修改成功！',
                  position: 'top'
                })
                //调用父页面成功方法
                this.$emit('success');
                this.$emit('close');
              }
            })
          }else {
            let transMsg = {
              OrderId: this.TransOrderMsg.OrderId,
              EnterID: this.TransOrderMsg.model.Id
            }
            updateOrderSale(transMsg).then(res => {
              if (res.Code == 1) {
                this.$q.notify({
                  icon: 'iconfont icon-chenggong',
                  color: 'accent',
                  timeout: 2000,
                  message: '修改成功！',
                  position: 'top'
                })
                //调用父页面成功方法
                this.$emit('success');
                this.$emit('close');
              }
            })
          }

      }
    }
  }

</script>
