<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, syncSapData } from '@/api/mes/od/salesOrder'
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) {
        getSapInfo(id).then(res => {
          this.sapInfo = JSON.parse(res.data)[0]
          this.sapInfo.id = id
          console.log(this.sapInfo)
        })
        getOrder(id).then(res => {

          this.$nextTick(() => this.$refs.sapForm.init(3, id, res.data))
          this.sapInfo = res.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>
