<template>
  <div id="addOder">
    <el-form :model="basicForm" :rules="basicRules" ref="basic" label-width="auto">
      <el-row :gutter="10">
        <el-col :span="1.5">
            <el-form-item label="订单类型">
              <el-select v-model="basicForm.billType" size="small" style="width: 200px" clearable>
                <el-option v-for="dict in dict.type.sys_order_type" :key="dict.value" :label="dict.label" :value="dict.value">
                </el-option>
              </el-select>
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="单据号">
              <el-input
                v-model="basicForm.code"
                size="small"
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="单据日期">
              <el-date-picker
                v-model="basicForm.billDate"
                size="small"
                type="date"
                clearable
                value-format="yyyy-MM-dd"
                style="width: 200px">
              </el-date-picker>
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调拨方式">
              <el-input
                v-model="basicForm.allotType"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调拨出库单号">
              <el-input
                v-model="basicForm.deliveryCode"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调拨入库单号">
              <el-input
                v-model="basicForm.storageCode"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调入库存组织">
              <el-input
                v-model="basicForm.storageInventoryOrg"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调出业务员">
              <el-input
                v-model="basicForm.businessPersonal"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调出部门">
              <el-input
                v-model="basicForm.deliveryDept"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="币种">
              <el-input
                v-model="basicForm.currency"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="折本汇率">
              <el-input
                v-model="basicForm.rate"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="在途归属">
              <el-input
                v-model="basicForm.onRouteAffilliation"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="总数量">
              <el-input
                v-model="basicForm.qty"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="结算路径">
              <el-input
                v-model="basicForm.accountPath"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="客户">
              <el-input
                v-model="basicForm.customer"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调入仓库">
              <el-input
                v-model="basicForm.storageWarehouse"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="调出仓库">
              <el-input
                v-model="basicForm.deliveryWarehouse"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="物料项目组">
              <el-input
                v-model="basicForm.materialProject"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
         </el-col>
        <el-col :span="1.5">
            <el-form-item label="利润中心">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
        </el-col>
        <el-col :span="1.5">
            <el-form-item label="是否已同步WMS">
              <el-input
                v-model="basicForm.isSendWms"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
        </el-col>
        <el-col :span="1.5">
            <el-form-item label="备注">
              <el-input
                v-model="basicForm.remark"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
        </el-col>
        <el-col :span="1.5">
            <el-form-item label="单据状态">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
        </el-col>
      </el-row>

      <el-tabs style="margin-top: 10px;" type="border-card">
        <el-tab-pane label="物料信息">
          <div class="btn_grooup">
            <el-button type="primary" size="small" @click="addLine">增行</el-button>
          </div>
          <el-table
          :data="materialInfo" 
          fit
          max-height="480"
          >
          <el-table-column label="行号" align="center" prop="rowno"/>
          <el-table-column label="物料编码" align="center" prop="material"/>
          <el-table-column label="物料名称" align="center" prop="materialName"/>
          <el-table-column label="调拨出库单号" align="center" prop="code"/>
          <el-table-column label="调拨入库单号" align="center" prop="code"/>
          <el-table-column label="规格" align="center" prop="code"/>
          <el-table-column label="生产厂家/代理人" align="center" prop="manufacturer"/>
          <el-table-column label="产地" align="center" prop="originPlace"/>
          <el-table-column label="型号" align="center" prop="model"/>
          <el-table-column label="单位" align="center" prop="unit"/>
          <el-table-column label="调出仓库" align="center" prop="deliveryWarehouseName"/>
          <el-table-column label="数量" align="center" prop="qty"/>
          <el-table-column label="主单位" align="center" prop="mainUnit"/>
          <el-table-column label="换算率" align="center" prop="equation"/>
          <el-table-column label="主数量" align="center" prop="mainQty"/>
          <el-table-column label="税率" align="center" prop="rate"/>
          <el-table-column label="调入仓库" align="center" prop="storageWarehouseName"/>
          <el-table-column label="批次号" align="center" prop="patchNo"/>
          <el-table-column label="产品批号" align="center" prop="producBatch"/>
          <el-table-column label="生产日期" align="center" prop="manufactureDate"/>
          <el-table-column label="有效期至/失效日期" align="center" prop="periodEndDate"/>
          <el-table-column label="批准文号" align="center" prop="ratifyCode"/>
          <el-table-column label="注册证号" align="center" prop="registration"/>
          <el-table-column label="商品名" align="center" prop="productCode"/>
          <el-table-column label="通用名" align="center" prop="commonCode"/>
          <el-table-column label="剂型" align="center" prop="drug"/>
          <el-table-column label="调入调出结算规则明细" align="center" prop="ruleDetail"/>
          <el-table-column label="上市许可持有人" align="center" prop="marketingApprovalPersonal"/>
          <el-table-column label="生产许可证号/经营许可证号/备案凭证号" align="center" prop="production"/>
          <el-table-column label="pi码" align="center" prop="pi"/>
          <!-- <el-table-column label="无税金额" align="center" prop="code"/> -->
          <!-- <el-table-column label="备注" align="center" prop="code"/> -->
          <el-table-column label="客户物料码" align="center" prop="customerLogistic"/>
          <el-table-column label="客户物料名称" align="center" prop="customerLogisticName"/>
          </el-table>
        </el-tab-pane>

        <el-tab-pane label="收发货信息">
          <el-table
          :data="receiveInfo" 
          fit
          max-height="480"
          >
          <el-table-column label="行号" align="center" prop="rowno"/>
          <el-table-column label="调拨出库单号" align="center" prop="deliveryCode"/>
          <el-table-column label="调拨入库单号" align="center" prop="storageCode"/>
          <el-table-column label="生产厂家/代理人" align="center" prop="manufacturer"/>
          <el-table-column label="产地" align="center" prop="originPlace"/>
          <el-table-column label="类别" align="center" prop="classify"/>
          <el-table-column label="调出仓库" align="center" prop="deliveryWarehouseName"/>
          <el-table-column label="调入仓库" align="center" prop="storageWarehouseName"/>
          <!-- <el-table-column label="收货利润中心" align="center" prop="code"/>
          <el-table-column label="发货利润中心" align="center" prop="code"/> -->
          <el-table-column label="调入业务员" align="center" prop="businessPersonalName"/>
          <el-table-column label="产品批号" align="center" prop="productBatch"/>
          <el-table-column label="生产日期" align="center" prop="manufactureDate"/>
          <el-table-column label="有效期至/失效日期" align="center" prop="periodEndDate"/>
          <el-table-column label="批准文号" align="center" prop="ratifyCode"/>
          <el-table-column label="注册证号" align="center" prop="registration"/>
          <el-table-column label="商品名" align="center" prop="productCode"/>
          <el-table-column label="通用名" align="center" prop="commonCode"/>
          <el-table-column label="剂型" align="center" prop="drug"/>
          <el-table-column label="收货客户" align="center" prop="customerName"/>
          <el-table-column label="收货地址" align="center" prop="addressaddress"/>
          <el-table-column label="收货地区" align="center" prop="area"/>
          <el-table-column label="收货地点" align="center" prop="place"/>
          <el-table-column label="计划发货日期" align="center" prop="deliveryDate"/>
          <el-table-column label="计划到货日期" align="center" prop="strageDate"/>
          <el-table-column label="运输方式" align="center" prop="transportation"/>
          <el-table-column label="备注" align="center" prop="remark"/>
          <el-table-column label="客户物料编码" align="center" prop="customerLogistic"/>
          <el-table-column label="客户物料名称" align="center" prop="customerLogisticName"/>
          </el-table>
        </el-tab-pane>

        <el-tab-pane label="价格费用">
          <el-table
          :data="priceList" 
          fit
          max-height="480"
          >
          <el-table-column label="行号" align="center" prop="rowno"/>
          <el-table-column label="调拨出库单号" align="center" prop="deliveryCode"/>
          <el-table-column label="调拨入库单号" align="center" prop="storageCode"/>
          <el-table-column label="生产厂家/代理人" align="center" prop="manufacturer"/>
          <el-table-column label="产地" align="center" prop="originPlace"/>
          <el-table-column label="类别" align="center" prop="classify"/>
          <!-- <el-table-column label="税率" align="center" prop="code"/> -->
          <!-- <el-table-column label="无税单价" align="center" prop="code"/> -->
          <!-- <el-table-column label="含税单价" align="center" prop="code"/> -->
          <el-table-column label="产品批号" align="center" prop="productBatch"/>
          <el-table-column label="生产日期" align="center" prop="manufactureDate"/>
          <el-table-column label="有效期至/失效日期" align="center" prop="periodEndDate"/>
          <el-table-column label="批准文号" align="center" prop="ratifyCode"/>
          <el-table-column label="注册证号" align="center" prop="registration"/>
          <el-table-column label="商品名" align="center" prop="productCode"/>
          <el-table-column label="通用名" align="center" prop="commonCode"/>
          <el-table-column label="剂型" align="center" prop="drug"/>
          <!-- <el-table-column label="询价无税价" align="center" prop="code"/> -->
          <!-- <el-table-column label="询价含税价" align="center" prop="code"/> -->
          <!-- <el-table-column label="税额" align="center" prop="code"/> -->
          <!-- <el-table-column label="加价率" align="center" prop="code"/> -->
          <!-- <el-table-column label="无税金额" align="center" prop="code"/> -->
          <!-- <el-table-column label="价税合计" align="center" prop="code"/> -->
          <el-table-column label="客户物料码" align="center" prop="customerLogistic"/>
          <el-table-column label="客户物料名称" align="center" prop="customerLogisticName"/>
          </el-table>
        </el-tab-pane>

        <el-tab-pane label="执行结果">
          <el-table
          :data="resultList" 
          fit
          max-height="480"
          >
          <el-table-column label="行号" align="center" prop="rowno"/>
          <el-table-column label="调拨出库单号" align="center" prop="deliveryCode"/>
          <el-table-column label="调拨入库单号" align="center" prop="storageCode"/>
          <el-table-column label="生产厂家/代理人" align="center" prop="manufacturer"/>
          <el-table-column label="产地" align="center" prop="originPlace"/>
          <el-table-column label="类别" align="center" prop="classify"/>
          <el-table-column label="产品批号" align="center" prop="productBatch	"/>
          <el-table-column label="生产日期" align="center" prop="manufactureDate"/>
          <el-table-column label="有效期至/失效日期" align="center" prop="periodEndDate"/>
          <el-table-column label="批准文号" align="center" prop="ratifyCode"/>
          <el-table-column label="注册证号" align="center" prop="registration"/>
          <el-table-column label="商品名" align="center" prop="productCode"/>
          <el-table-column label="通用名" align="center" prop="commonCode"/>
          <el-table-column label="剂型" align="center" prop="drug"/>
          <!-- <el-table-column label="已调出主数量" align="center" prop="code"/>
          <el-table-column label="已调入主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="调拨在途主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="已发货主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="途损主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="累计退货主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="调出与调入已结算主数量" align="center" prop="code"/> -->
          <!-- <el-table-column label="调出与调入已结算金额" align="center" prop="code"/> -->
          <el-table-column label="客户物料码" align="center" prop="customerLogistic"/>
          <el-table-column label="客户物料名称" align="center" prop="customerLogisticName"/>
          </el-table>
        </el-tab-pane>
      </el-tabs>

      <el-divider content-position="left">表尾信息</el-divider>
      <el-row :gutter="10">
        <el-col :span="1.5">
            <el-form-item label="制单人">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="制单日期">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="审批人">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="审批日期">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
      </el-row>

      <el-divider content-position="left">审计信息</el-divider>
      <el-row :gutter="10">
        <el-col :span="1.5">
            <el-form-item label="创建人">
              <el-input
                v-model="basicForm.createByName"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="创建时间">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="最后修改人">
              <el-input
                v-model="basicForm.updateByName"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
        <el-col :span="1.5">
            <el-form-item label="最后修改时间">
              <el-input
                v-model="basicForm.code"
                size="small"
                placeholder=""
                clearable
                style="width: 200px"
              />
            </el-form-item>
          </el-col>
      </el-row>
    </el-form>

    <div class="btn_group">
      <el-col :span="1.5" style="margin: 0 10px;">
        <el-button type="primary" size="small" plain @click="save" v-if="pageStu == 'add' || pageStu == 'edit'">保存</el-button>
      </el-col>
      <!-- <el-col :span="1.5" style="margin: 0 10px;">
        <el-button type="primary" size="small" plain @click="submit" v-if="pageStu == 'edit'">提交</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button size="small" plain @click="back">返回</el-button>
      </el-col>
    </div>
  </div>
</template>

<script>
import {addOrder, getOrderDetail, editOrder} from '@/api/purchase/transferOrder.js'
export default {
  name: 'addOder',
  dicts: ['sys_order_type'],
  props: ['pageStu','row', 'disable'],
  model: {
    prop: 'isList',
    event: 'jugislist'
  },
  data() {
    return {
      basicForm: {},
      options: [{
        value: '1', label: '是',
      }, {
        value: '0', label: '否'
      }],
      basicRules: {
        billType: '',
        code: '',
        billDate	: '',
        allotType: '',
        deliveryCode: '',
        storageCode: '',
        storageInventoryOrg: '',
        storageInventoryOrgName: '',
        businessPersonal: '',
        businessPersonalName: '',
        deliveryDept: '',
        deliveryDeptName: '',
        currency: '',
        currencyName: '',
        rate: '',
        onRouteAffilliation: '',
        qty: '',
        accountPath: '',
        customer: '',
        customerName: '',
        deliveryWarehouse: '',
        deliveryWarehouseName: '',
        storageWarehouse: '',
        storageWarehouseName: '',
        materialProject: '',
        sourceIdentification: '',
        isSendWms: '',
        status: '',
        tenantId: '',
        revision: '',
        createByName: '',
        updateByName: '',
        delFlag: '',
      },
      materialInfo: [],
      receiveInfo: [],
      priceList: [],
      resultList: [],
    }
  },
  created() {
    if(this.pageStu == 'check') {
      console.log('数据', this.row)
      this.getDetails(this.row)
    } else if(this.pageStu == 'edit') {
      this.getDetails(this.row)
    }
  },
  methods: {
    save() {
      if(this.pageStu == 'add') {
        this.basicForm.stAllotMaterialList = this.materialInfo
        this.basicForm.stAllotReceiveDeliverList = this.receiveInfo
        this.basicForm.stAllotReceiveExecuteList = this.priceList
        this.basicForm.stAllotReceiveExpenseList = this.resultList
        addOrder(this.basicForm).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("保存成功");
            this.back()
          }
        })
      } else if (this.pageStu == 'edit') {
        this.basicForm.stAllotMaterialList = this.materialInfo
        this.basicForm.stAllotReceiveDeliverList = this.receiveInfo
        this.basicForm.stAllotReceiveExecuteList = this.priceList
        this.basicForm.stAllotReceiveExpenseList = this.resultList
        editOrder(this.basicForm).then(res => {
          if (res.code === 200) {
            this.$modal.msgSuccess("编辑成功");
            this.back()
          }
        })
      }
    },
    back() {
      this.$emit('jugislist', true)
      let queryParams = {
        pageNum: 1,
        pageSize: 10
      }
      this.$emit('refresh', queryParams)
    },
    // 如果需要回显则调用详情接口
    getDetails(row) {
      getOrderDetail(row.id).then(res => {
        if (res.code === 200) {
          this.basicForm = res.data
          // this.materialInfo = res.data.stAllotMaterialList
          // this.receiveInfo = res.data.stAllotReceiveDeliverList
          // this.priceList = res.data.stAllotReceiveExecuteList
          // this.resultList = res.data.stAllotReceiveExpenseList
        }
      })
    },
    addLine() {},
    delLine(index) {
      // console.log('删除行:', index)
      // this.basicForm.puDemandItemList.splice(index, 1)
    },
  }
}
</script>

<style lang="scss" scoped>
.btn_group {
  width: 100%;
  margin: 20px 0;
  display: flex;
  justify-content: center;
} 
.btn_grooup {
  margin-bottom: 10px;
  display: flex;
  justify-content: flex-end;
}  
</style>