<template>
  <div class="withinLine">
    <el-button type="primary" :disabled="disabled" size="mini" @click="save">
      {{ orderInfo.id ? '保存' : '下派工单' }}
    </el-button>
  </div>
</template>

<script>
import buttonMixin from './button_mixin.js'
import { EventBus } from '@/utils/eventBus'
import { orderBaseSave } from '@/api/workOrderPool.js'
export default {
  mixins: [buttonMixin],
  methods: {
    save() {
      this.acquireVerify(
        this,
        'allVerify'
      )(v => {
        if (v) {
          this.lockBtn()
          orderBaseSave({
            ...this.orderInfo
          })
            .then(res => {
              if (this.orderInfo.id) {
                // 编辑保存后不跳转列表，刷新数据
                this.acquireVerify(this, 'getorderDetail')()
                // 刷新操作记录
                this.acquireVerify(this, 'getOrderBaseLogList')()
                this.$message({
                  type: 'success',
                  message: '保存成功'
                })
              } else {
                // 创建保存后跳转列表
                EventBus.$emit('handleOrderClone')
              }
              this.unlockBtn()
            })
            .catch(() => {
              this.unlockBtn()
            })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.withinLine {
  display: inline-block;

  ::v-deep .el-button {
    margin-left: 0;
    margin-right: 10px;
    margin-bottom: 10px;
  }
}
</style>
