<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">
      <el-form :model="sapInfo" ref="sapInfo" label-width="120px" size="mini">
        <el-row :gutter="10">
          <el-col :span="6">
            <el-form-item label="销售凭证" prop="VBELN">
              <el-input v-model="sapInfo.VBELN" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="销售凭证类型" prop="AUART" required>
              <el-select v-model="sapInfo.AUART" clearable>
                <el-option label="ZDO-国内标准订单" value="ZDO"/>
                <el-option label="ZEO-出口标准订单" value="ZEO"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="销售组织" prop="VKORG" required>
              <el-select v-model="sapInfo.VKORG" clearable>
                <el-option label="1000-广州宝绅科技销售组织" value="1000"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="分销渠道" prop="VTWEG" required>
              <el-select v-model="sapInfo.VTWEG" clearable>
                <el-option label="10-内销" value="10"/>
                <el-option label="20-外销" value="20"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="产品组" required prop="SPART">
              <el-select v-model="sapInfo.SPART" clearable>
                <el-option label="00-通用产品组" value="00"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="订单原因" prop="AUGRU">
              <el-input v-model="sapInfo.AUGRU" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="销售办事处" prop="VKBUR">
              <el-select v-model="sapInfo.VKBUR" clearable>
                <el-option label="A10-业务一课" value="A10"/>
                <el-option label="A20-业务二课" value="A20"/>
                <el-option label="A90-外贸课" value="A90"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="销售组" prop="VKGRP">
              <el-select v-model="sapInfo.VKGRP" clearable>
                <template v-if="sapInfo.VKBUR == 'A10'">
                  <el-option label="A11-业务一课A组" value="A11"/>
                  <el-option label="A12-业务一课B组" value="A12"/>
                </template>
                <template v-if="sapInfo.VKBUR == 'A20'">
                  <el-option label="A21-业务二课A组" value="A21"/>
                  <el-option label="A22-业务二课B组" value="A22"/>
                </template>
                <template v-if="sapInfo.VKBUR == 'A90'">
                  <el-option label="A91-外贸A组" value="A91"/>
                  <el-option label="A92-外贸B组" value="A92"/>
                </template>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户编号" prop="KUNNR" required>
              <el-input v-model="sapInfo.KUNNR" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户参考" prop="BSTNK" required>
              <el-input v-model="sapInfo.BSTNK" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="要求的交货日期" prop="VDATU">
              <el-input v-model="sapInfo.VDATU" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户参考日期" prop="BSTDK">
              <el-input v-model="sapInfo.BSTDK" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="国际贸易条款" prop="INCO1">
              <el-select v-model="sapInfo.INCO1" placeholder="" clearable>
                <el-option label="FOB-离岸价" value="FOB"/>
                <el-option label="CIF-成本, 保险 & 运费" value="CIF"/>
                <el-option label="EXW-工厂交货" value="EXW"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="国际贸易位置" prop="INCO2" :required="!!sapInfo.INCO2">
              <el-input v-model="sapInfo.INCO2" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="付款条件代码" prop="ZTERM" required>
              <el-select v-model="sapInfo.ZTERM" placeholder="" clearable>
                <el-option value="Z009" label="月结15天"/>
                <el-option value="Z010" label="月结30天"/>
                <el-option value="Z011" label="月结45天"/>
                <el-option value="Z012" label="月结60天"/>
                <el-option value="Z013" label="月结90天"/>
                <el-option value="Z014" label="月结20天"/>
                <el-option value="Z015" label="月结75天"/>
                <el-option value="Z016" label="月结50天"/>
                <el-option value="Z018" label="月结35天"/>
                <el-option value="Z019" label="月结55天"/>
                <el-option value="Z020" label="月结25天"/>
                <el-option value="Z021" label="月结68天"/>
                <el-option value="Z022" label="月结105天"/>
                <el-option value="Z023" label="月结120天"/>
                <el-option value="Z024" label="月结180天"/>
                <el-option value="Z025" label="次月20号前付款"/>
                <el-option value="Z026" label="当月底结账"/>
                <el-option value="Z027" label="款到发货"/>
                <el-option value="Z028" label="隔月付现"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="记录创建日期" prop="ERDAT">
              <el-input v-model="sapInfo.ERDAT" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="备注" prop="LTEXT">
              <el-input v-model="sapInfo.LTEXT" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="跟单员" prop="ZKUNR">
              <el-input v-model="sapInfo.ZKUNR" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="生产发货方式" prop="ZF14">
              <el-select v-model="sapInfo.ZF14" placeholder="" clearable>
                <el-option value="01" label="01款到发货"/>
                <el-option value="02" label="02款到生产"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="条码" prop="ZBARDE">
              <el-input v-model="sapInfo.ZBARDE" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="申购号" prop="ZPONUM">
              <el-input v-model="sapInfo.ZPONUM" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="款式" prop="ZSTYLE">
              <el-input v-model="sapInfo.ZSTYLE" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="OSP订单号" prop="ZOSP">
              <el-input v-model="sapInfo.ZOSP" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="交货冻结" prop="LIFSK">
              <el-input v-model="sapInfo.LIFSK" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="开票冻结" prop="FAKSK">
              <el-input v-model="sapInfo.FAKSK" placeholder="" clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6" v-show="false">
            <el-form-item label="更新标识" prop="UPDKZ" required>
              <el-select v-model="sapInfo.UPDKZ" placeholder="" clearable>
                <el-option value="I" label="新增"/>
                <el-option value="U" label="修改"/>
              </el-select>
            </el-form-item>
           </el-col>
        </el-row>
      </el-form>

      <el-table :data="sapInfo.ITEM" max-height="800px" size="mini">
        <el-table-column min-width="150" label="销售凭证项目" prop="POSNR"><template slot-scope="{row}"><el-input v-model=row.POSNR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 物料编号" prop="MATNR"><template slot-scope="{row}"><el-input v-model=row.MATNR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 工厂" prop="WERKS">
          <template slot-scope="{row}">
            <el-select v-model="row.WERKS" placeholder="">
              <el-option label="1000-广州市宝绅科技印刷工厂" value="1000"/>
              <el-option label="1010-广州市宝绅科技RFID工厂" value="1010"/>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column min-width="150" label="总数量" title="以销售单位表示的累计订购数量" prop="KWMENG"><template slot-scope="{row}"><el-input type="number" v-model=row.KWMENG placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="客户物料编号" prop="KDMAT"><template slot-scope="{row}"><el-input v-model=row.KDMAT placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="客户物料名称" prop="ARKTX"><template slot-scope="{row}"><el-input v-model=row.ARKTX placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="折扣率（Z001的金额）" prop="NETPR"><template slot-scope="{row}"><el-input v-model=row.NETPR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 装运点/收货点" prop="VSTEL"><template slot-scope="{row}">
          <el-select v-model=row.VSTEL placeholder="">
            <el-option label="1000-广州宝绅科技工厂装运点" value="1000"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="存储地点" prop="LGORT"><template slot-scope="{row}">
          <el-select v-model=row.LGORT placeholder="" clearable>
            <el-option label="8001-成品一库" value="8001"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="批次编号" prop="CHARG"><template slot-scope="{row}"><el-input v-model=row.CHARG placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 计划行日期" prop="EDATU"><template slot-scope="{row}">
          <el-input v-model=row.EDATU placeholder=""/>
        </template></el-table-column>
        <el-table-column min-width="150" label="拒绝原因" prop="ABGRU"><template slot-scope="{row}">
          <el-select v-model=row.ABGRU placeholder="">
            <el-option value="Z1" label="Z1-订单已生产完成，客户取消订单，转为库存，申请完结"/>
            <el-option value="Z2" label="Z2-订单已生产完成，客户取消订单，订单挪用完毕，申请完结"/>
            <el-option value="Z3" label="Z3-客户取消或更新订单，生产开立领料单实际未生产，申请完结"/>
            <el-option value="Z4" label="Z4-异常开错订单，申请完结"/>
            <el-option value="Z5" label="Z5-现场找不到货，重新生产出货，申请完结"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="工厂单价（PR01的金额）" prop="NETWR"><template slot-scope="{row}"><el-input v-model=row.NETWR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="订单行折前总金额（Z002的定价值）" prop="KWERT"><template slot-scope="{row}"><el-input v-model=row.KWERT placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="定价单位" prop="KPEIN"><template slot-scope="{row}"><el-input v-model=row.KPEIN placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="货币" prop="KOEIN"><template slot-scope="{row}"><el-input v-model=row.KOEIN placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="尺码组" prop="ZSIZEGROUP"><template slot-scope="{row}"><el-input v-model=row.ZSIZEGROUP placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="尺码单位（客户）" prop="ZSIZEUNITC"><template slot-scope="{row}"><el-input v-model=row.ZSIZEUNITC placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="指令号" prop="ZINSTNUM"><template slot-scope="{row}"><el-input v-model=row.ZINSTNUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="型体号" prop="ZMOLD"><template slot-scope="{row}"><el-input v-model=row.ZMOLD placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="配色号" prop="ZMAPCOLOR"><template slot-scope="{row}"><el-input v-model=row.ZMAPCOLOR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="颜色" prop="ZCLOLOR"><template slot-scope="{row}"><el-input v-model=row.ZCLOLOR placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="销线" prop="ZSALEAREA"><template slot-scope="{row}"><el-input v-model=row.ZSALEAREA placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="段别" prop="ZDUANBIE"><template slot-scope="{row}"><el-input v-model=row.ZDUANBIE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="季度" prop="ZSEASON"><template slot-scope="{row}"><el-input v-model=row.ZSEASON placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="整/半码" prop="ZTOTALSIZE"><template slot-scope="{row}">
          <el-select v-model=row.ZTOTALSIZE placeholder="">
            <el-option value="01" label="01-整码"/>
            <el-option value="02" label="02-整半码"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="特殊SIZE" prop="ZSPECSIZE"><template slot-scope="{row}">
          <el-select v-model=row.ZSPECSIZE placeholder="">
            <el-option value="是" label="是"/>
            <el-option value="否" label="否"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="PO#" prop="ZCPONUM"><template slot-scope="{row}"><el-input v-model=row.ZCPONUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="WIP#" prop="ZWIPNUM"><template slot-scope="{row}"><el-input v-model=row.ZWIPNUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="装箱数" prop="ZBOXQUAN"><template slot-scope="{row}"><el-input v-model=row.ZBOXQUAN placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="产地" prop="ZORIGIN"><template slot-scope="{row}"><el-input v-model=row.ZORIGIN placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="周期" prop="ZCYCLE"><template slot-scope="{row}"><el-input v-model=row.ZCYCLE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="SK编号" prop="ZSKCODE"><template slot-scope="{row}"><el-input v-model=row.ZSKCODE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="专利号" prop="ZPATENTCODE"><template slot-scope="{row}"><el-input v-model=row.ZPATENTCODE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="材质描述" prop="ZMATERIALDES"><template slot-scope="{row}"><el-input v-model=row.ZMATERIALDES placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="签收人" prop="ZSIGNPERSON"><template slot-scope="{row}"><el-input v-model=row.ZSIGNPERSON placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="SHIP TO ID" prop="ZSHIPID"><template slot-scope="{row}"><el-input v-model=row.ZSHIPID placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="产品规格" prop="ZPRODSPEC"><template slot-scope="{row}"><el-input v-model=row.ZPRODSPEC placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="产品用途" prop="ZPRODUSAGE"><template slot-scope="{row}">
          <el-select v-model=row.ZPRODUSAGE placeholder="">
            <el-option value="01" label="01-网布"/>
            <el-option value="02" label="02-普通"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="厚度（丝）" prop="ZTHICK"><template slot-scope="{row}">
          <el-input v-model.number=row.ZTHICK max="10" min="1" placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="包装方式" prop="ZPACKINGMOT"><template slot-scope="{row}"><el-input v-model=row.ZPACKINGMOT placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="印刷方向" prop="ZPRINTDIRECT"><template slot-scope="{row}">
          <el-select v-model=row.ZPRINTDIRECT placeholder="">
            <el-option label="01-字体倒立" value="01"/>
          </el-select>
        </template></el-table-column>
        <el-table-column min-width="150" label="工厂代号" prop="ZPLANTCODE"><template slot-scope="{row}"><el-input v-model=row.ZPLANTCODE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 指令数(客户)汇总" prop="ZINCSUM"><template slot-scope="{row}"><el-input v-model=row.ZINCSUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* LOSS数(客户)汇总" prop="ZLOSSUM"><template slot-scope="{row}"><el-input v-model=row.ZLOSSUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* SIZE 序号" prop="SIZE.0.ZSIZE_NUM"><template slot-scope="{row}"><el-input v-model=row.SIZE[0].ZSIZE_NUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 尺码" prop="SIZE.0.ZSIZE"><template slot-scope="{row}"><el-input v-model=row.SIZE[0].ZSIZE placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="* 指令数(客户)" prop="SIZE.0.ZINSNUM"><template slot-scope="{row}"><el-input v-model=row.SIZE[0].ZINSNUM placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="LOSS数(客户)" prop="SIZE.0.ZLOSSC"><template slot-scope="{row}"><el-input v-model=row.SIZE[0].ZLOSSC placeholder=""/></template></el-table-column>
        <el-table-column min-width="150" label="尺码备注" prop="SIZE.0.ZSIZECOM"><template slot-scope="{row}"><el-input v-model=row.SIZE[0].ZSIZECOM placeholder=""/></template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>

import { getSapInfo, syncSapData } from '@/api/mes/od/salesOrder'

export default {
  data() {
    return {
      loading: false,
      sapInfo: {
        ITEM: []
      }
    }
  },
  methods: {
    onEdit() {
      this.$confirm("确定同步该条数据记录").then(() => {
        if (this.loading) return
        this.loading = true
        this.sapInfo.ITEM.forEach(item => {
          if (!item.MATNR) this.$message.error("物料编号不能为空")
          if (!item.WERKS) this.$message.error("工厂不能为空 不能为空")
          if (!item.VSTEL) this.$message.error("装运点/收货点 不能为空")
          if (!item.EDATU) this.$message.error("计划行日期 不能为空")
          if (!item.ZINCSUM) this.$message.error("指令数(客户)汇总 不能为空")
          if (!item.SIZE[0].ZSIZE_NUM) this.$message.error("SIZE 序号 不能为空")
          if (!item.SIZE[0].ZSIZE) this.$message.error("SIZE 序号 尺码")
          if (!item.SIZE[0].ZINSNUM) this.$message.error("指令数(客户) 尺码")
        })
        this.$refs.sapInfo.validate(valid => {
          if (valid) {
            syncSapData(this.sapInfo).then(() => {
              this.onGoBack()
              this.$message.error("操作成功")
            }).finally(() => this.loading = false)
          } else {
            this.loading = false
            this.$message.error("请检查表单")
          }
        })
      })
    },


    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)
        })
      }
    },
  },
  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>
