<template>
  <div class="withinLine">
    <el-button type="primary" :disabled="disabled" size="mini" @click="save"> 创建服务单 </el-button>
  </div>
</template>

<script>
import buttonMixin from './button_mixin.js'
import { EventBus } from '@/utils/eventBus'
export default {
  mixins: [buttonMixin],
  methods: {
    save() {
      EventBus.$emit('cloneWorkOrder', {
        ...this.removeFields(JSON.parse(JSON.stringify(this.orderInfo)), [
          'id',
          'createBy',
          'createDate',
          'updateBy',
          'updateTime',
          'orderStatus',
          'orderFlags',
          'orderBaseId',
          'orderWorkers',
          'orderWorkers_cp',
          'workerId',
          'workerIdList',
          'workerId_fz',
          'workerIdcard',
          'workerMobile',
          'workerName',
          'workerReceTime',
          'workerRemark'
        ]),
        orderWorkers: []
      })
    },
    removeFields(jsonData, fieldsToRemove) {
      if (typeof jsonData !== 'object' || jsonData === null) {
        // 如果传入的不是对象，则直接返回
        return jsonData
      } else if (Array.isArray(jsonData)) {
        // 如果是数组，则递归处理每个元素
        return jsonData.map(item => this.removeFields(item, fieldsToRemove))
      } else {
        // 如果是对象，则遍历键值对
        for (var key in jsonData) {
          if (jsonData.hasOwnProperty(key)) {
            if (fieldsToRemove.includes(key)) {
              // 如果字段名在指定的要删除的字段数组中，则删除该字段
              delete jsonData[key]
            } else {
              // 否则递归处理字段值
              jsonData[key] = this.removeFields(jsonData[key], fieldsToRemove)
            }
          }
        }
        return jsonData
      }
    }
  }
}
</script>

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

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