<template>
  <div class="OrderSync">
    <div class="page-head">
      <div class="page-title">同步销售订单</div>
      <div class="head-btn">
        <el-button size="mini" @click="onGoBack">返回</el-button>
        <el-button type="primary" size="mini" :loading="loading" @click="onEdit">提交</el-button>
      </div>
    </div>
    <div class="page-body">
      <SapForm ref="sapForm"/>
    </div>
  </div>
</template>

<script>

import { getOrder, getSapInfo } from '@/api/mes/od/salesOrder'
import { get as getSapData } from '@/api/mes/md/sapFieldData'
import SapForm from '@/views/mes/md/sapField/components/SapForm'
export default {
  components: {
    SapForm
  },
  data() {
    return {
      loading: false,
      sapInfo: {
        ITEM: []
      }
    }
  },
  methods: {
    onEdit() {
      this.$confirm("确定同步该条数据记录").then(() => {
        if (this.loading) return
        this.loading = true
        let sapForm = this.$refs.sapForm.sapForm
          syncSapData(sapForm).then(() => {
            this.onGoBack()
            this.$message.success("操作成功")
          }).finally(() => this.loading = false)
      })
    },


    onGoBack() {
      this.$store.dispatch('tagsView/delView', this.$router.currentRoute)
      this.$router.push('/order/sales')
    },
    onGetSapInfo() {
      let id = this.$route.query.id
      if (id) {
        getSapData({type: 3, relationId: id}).then(res => {
          let sapData = res.data
          getOrder(id).then(resp => {
            this.$refs.sapForm.init(3, id, sapData, resp.data)
          })
        })

      }
    },
  },
  created() {
    this.onGetSapInfo()
  }
}
</script>

<style scoped>
.page-head {
  border-bottom: 1px solid #dddddd;
  box-shadow: 0 2px 2px #dddddd;
}

.page-title {
  line-height: 50px;
  text-align: center;
  font-size: 18px;
  font-weight: bold;
}

.head-btn {
  margin: 0 20px 20px;
}

.page-body {
  margin: 20px 20px 100px;
}
</style>
