<template>
  <!-- 编辑发运明细 -->
  <div id="editShipDetDrawer">
    <a-drawer title="编辑" width="89%" placement="right" :closable="true" :visible="visible" @close="handleCancel">
      <!-- 主表信息 编辑 :rules="validatorRules"-->
      <a-card :bordered="true">
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="form" :model="editShipDet">
            <!-- 主表信息 填写-->
            <a-row :gutter="24">
              <a-col :md="6" :sm="8">
                <!-- required必填项 disabled 禁用  -->
                <a-form-model-item label="单据号" prop="documentNo">
                  <a-input placeholder="请输入单据号" v-model="editShipDet.documentNo"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="单据日期" prop="documentDate">
                  <a-date-picker
                    placeholder="请选择单据日期"
                    :format="dateFormat"
                    style="width:100%;"
                    v-model="editShipDet.documentDate"
                  />
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="客户" prop="customer">
                  <a-input placeholder="请输入客户" v-model="editShipDet.customer"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="预发货日期" prop="preDeliveryDate">
                  <a-date-picker
                    placeholder="请选择预发货时间"
                    :format="dateFormat"
                    style="width:100%;"
                    v-model="editShipDet.preDeliveryDate"
                  />
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="预完工日期" prop="preCompletionDate">
                  <a-date-picker
                    placeholder="请选择预完工日期"
                    :format="dateFormat"
                    style="width:100%;"
                    v-model="editShipDet.preCompletionDate"
                  />
                </a-form-model-item>
              </a-col>

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="pack id" prop="packId">
                  <a-input placeholder="请输入pack id" v-model="editShipDet.packId"></a-input>
                </a-form-model-item>
              </a-col> -->

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="分销点" prop="distributionPoint">
                  <a-input placeholder="请输入分销点" v-model="editShipDet.distributionPoint"></a-input>
                </a-form-model-item>
              </a-col> -->

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="数量" prop="todo">
                  <a-input placeholder="合计" v-model="editShipDet.todo"></a-input>
                </a-form-model-item>
              </a-col> -->

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="单价" prop="salesUnitPrice">
                  <a-input placeholder="销售" v-model="editShipDet.salesUnitPrice"></a-input>
                </a-form-model-item>
              </a-col> -->

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="采购/委外订单号" prop="purOrSubOrder">
                  <a-input placeholder="请输入采购/委外订单号" v-model="editShipDet.purOrSubOrder"></a-input>
                </a-form-model-item>
              </a-col> -->

              <a-col :md="6" :sm="8">
                <a-form-model-item label="订单类型" prop="orderType">
                  <a-input placeholder="请输入订单类型" v-model="editShipDet.orderType"></a-input>
                </a-form-model-item>
              </a-col>

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="工厂单价" prop="factoryUnitPrice">
                  <a-input placeholder="采购/委外单价" v-model="editShipDet.factoryUnitPrice"></a-input>
                </a-form-model-item>
              </a-col> -->

              <a-col :md="6" :sm="8">
                <a-form-model-item label="HScode" prop="hsCode">
                  <a-input placeholder="HScode" v-model="editShipDet.hsCode"></a-input>
                </a-form-model-item>
              </a-col>

              <!-- <a-col :md="6" :sm="8">
                <a-form-model-item label="套装件数" prop="numberOfSets">
                  <a-input placeholder="存货自定义项" v-model="editShipDet.numberOfSets"></a-input>
                </a-form-model-item>
              </a-col> -->

              <a-col :md="6" :sm="8">
                <a-form-model-item label="中文品名" prop="chineseName">
                  <a-input placeholder="请输入中文品名" v-model="editShipDet.chineseName"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="英文品名" prop="englishProductName">
                  <a-input placeholder="请输入英文品名" v-model="editShipDet.englishProductName"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="报关品名" prop="declarationName">
                  <a-input placeholder="请输入报关品名" v-model="editShipDet.declarationName"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="成衣工厂" prop="garmentFactory">
                  <a-input placeholder="请输入成衣工厂" v-model="editShipDet.garmentFactory"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="6" :sm="8">
                <a-form-model-item label="整单合计" prop="wholeOrderTotal">
                  <a-input placeholder="请输入整单合计" v-model="editShipDet.wholeOrderTotal"></a-input>
                </a-form-model-item>
              </a-col>

              <a-col :md="18" :sm="18">
                <a-form-model-item label="备注" prop="memo">
                  <a-input placeholder="请输入备注" v-model="editShipDet.memo"></a-input>
                </a-form-model-item>
              </a-col>
            </a-row>
          </a-form-model>
        </div>
      </a-card>

      <!--  参照订单数据 増行-->
      <a-card :bordered="true" style="margin:10px 0 60px 0">
        <div class="table-operator">
          <a-button type="primary" @click="referOrderDataOpen" icon="ordered-list">参照订单数据</a-button>
          <a-button type="primary" @click="handleAddColumn" icon="plus" style="margin-left: 20px">増行</a-button>
        </div>

        <!-- 子表  :model="form" :rules="validatorRules"-->
        <a-spin :spinning="confirmLoading">
          <a-form-model ref="formRef">
            <a-table
              v-if="syShippingDetailsItemList"
              bordered
              rowKey="id"
              :columns="columns"
              :data-source="syShippingDetailsItemList"
              :loading="loading"
              :pagination="ipagination"
              :scroll="{ x: 1500 }"
              @change="handleTableChange"
            >
              <!-- 款号 输入框 :rules="rules.itemNumber" -->
              <template slot="itemNumber" slot-scope="text, record, index">
                <a-form-model-item prop="itemNumber">
                  <a-input style="width:100%" type="text" v-model="record.itemNumber" />
                </a-form-model-item>
              </template>

              <!-- 发货数量 :rules="rules.shipQuantity"-->
              <template slot="shipmentQuantity" slot-scope="text, record, index">
                <a-form-model-item prop="shipmentQuantity">
                  <a-input style="width:100%" type="text" v-model="record.shipmentQuantity" />
                </a-form-model-item>
              </template>

              <!-- 是否TC功能 :rules="rules.isTC"-->
              <!-- isTc ' 是否 tc 功能 0 否 1 是', -->
              <template slot="isTC" slot-scope="text, record, index">
                <a-form-model-item prop="isTc">
                  <a-select v-model="record.isTc">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option :value="1">是</a-select-option>
                    <a-select-option :value="0">否</a-select-option>
                  </a-select>
                </a-form-model-item>
              </template>

              <!-- 物料成分 :rules="rules.materialComposition"-->
              <template slot="materialComposition" slot-scope="text, record, index">
                <a-form-model-item prop="materialComposition">
                  <a-input style="width:100%" type="text" v-model="record.materialComposition" />
                </a-form-model-item>
              </template>

              <!-- 采购/委外订单号 :rules="rules.purOrSubOrder"-->
              <template slot="purOrSubOrder" slot-scope="text, record, index">
                <a-form-model-item prop="purOrSubOrder">
                  <a-input style="width:100%" type="text" v-model="record.purOrSubOrder" />
                </a-form-model-item>
              </template>

              <!-- 报关单价 :rules="rules.customsDeclarationUnitPrice"-->
              <template slot="customsDeclarationUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="customsDeclarationUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.customsDeclarationUnitPrice" />
                </a-form-model-item>
              </template>
              <!-- 套装件数 :rules="rules.numberOfSets"-->
              <template slot="numberOfSets" slot-scope="text, record, index">
                <a-form-model-item prop="numberOfSets">
                  <a-input style="width:100%" type="text" v-model="record.numberOfSets" />
                </a-form-model-item>
              </template>

              <!-- 工厂单价 :rules="rules.factoryUnitPrice"-->
              <template slot="factoryUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="factoryUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.factoryUnitPrice" />
                </a-form-model-item>
              </template>

              <!-- 申报要素 :rules="rules.declarationElements"-->
              <template slot="declarationElements" slot-scope="text, record, index">
                <a-form-model-item prop="declarationElements">
                  <a-input style="width:100%" type="text" v-model="record.declarationElements" />
                </a-form-model-item>
              </template>
              <!--处理方式 -->
              <template slot="treatmentMethod" slot-scope="text, record, index">
                <a-form-model-item prop="treatmentMethod">
                  <a-input style="width:100%" type="text" v-model="record.treatmentMethod" />
                </a-form-model-item>
              </template>

              <!--是否手册纱 -->
              <template slot="manualYarnFlag" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnFlag">
                  <a-select v-model="record.manualYarnFlag">
                    <a-select-option value="">请选择</a-select-option>
                    <a-select-option :value="1">是</a-select-option>
                    <a-select-option :value="0">否</a-select-option>
                  </a-select>
                </a-form-model-item>
              </template>

              <!--手册纱单价 -->
              <template slot="manualYarnUnitPrice" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnUnitPrice">
                  <a-input style="width:100%" type="text" v-model="record.manualYarnUnitPrice" />
                </a-form-model-item>
              </template>

              <!--手册纱占比 -->
              <template slot="manualYarnProportion" slot-scope="text, record, index">
                <a-form-model-item prop="manualYarnProportion">
                  <a-input style="width:100%" type="text" v-model="record.manualYarnProportion" />
                </a-form-model-item>
              </template>

              <!-- 操作 -->
              <span slot="operationSlot" slot-scope="text, record">
                <a-popconfirm title="确定删除吗?" ok-text="是" cancel-text="否" @confirm="handleDelete(record.id)">
                  <a href="javascript:void(0);" style="color:red;">删除</a>
                </a-popconfirm>
                <a-divider type="vertical" />
                <a @click="copy(record)">复制</a>
              </span>
            </a-table>
          </a-form-model>
        </a-spin>
      </a-card>
      <!-- 页面底部保存取消 -->
      <div
        :style="{
          position: 'absolute',
          right: 0,
          bottom: 0,
          width: '100%',
          borderTop: '1px solid #e9e9e9',
          padding: '10px 16px',
          background: '#fff',
          textAlign: 'right',
          zIndex: 1
        }"
      >
        <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
          <a-button :style="{ marginRight: '8px' }">取消</a-button>
        </a-popconfirm>
        <a-button type="primary" @click="editSave">
          保存
        </a-button>
      </div>
    </a-drawer>

    <!-- 参照订单数据弹框 -->
    <referOrderData-modal ref="referOrderDataModal" @bao="getSon" @ok="referOrderDataOk"></referOrderData-modal>
  </div>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JEllipsis from '@/components/jeecg/JEllipsis'
import moment from 'moment'
import ReferOrderDataModal from '@views/shipment-details/referOrderDataModal.vue'
import { editById } from '@api/document/shipmentList'

export default {
  name: 'EditShipDetDrawer', // 编辑 发运明细 抽屉
  mixins: [JeecgListMixin], //
  components: { JEllipsis, ReferOrderDataModal, moment }, // 参照订单数据 弹框
  data() {
    let ellipsis = (v, l = 20) => <j-ellipsis value={v} length={l} />
    return {
      id: '',
      // 表头
      columns: [
        {
          title: '账套',
          dataIndex: 'account',
          width: 80,
          fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '订单号',
          dataIndex: 'orderNumber',
          width: 120,
          fixed: 'left',
          className: 'replacecolor'
        },
        {
          title: '款号',
          dataIndex: 'itemNumber',
          scopedSlots: { customRender: 'itemNumber' },
          fixed: 'left',
          width: 180,
          className: 'replacecolor'
        },
        // {
        //   title: '创建时间',
        //   dataIndex: 'createTime',
        //   align: 'center',
        //   sorter: true,
        //   customRender: text => {
        //     return moment(text).format('YYYY-MM-DD')
        //   }
        // },
        {
          title: '订单日期',
          dataIndex: 'orderDate',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '业务类型',
          dataIndex: 'businessTypeText',
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '客户订单',
          dataIndex: 'customerOrder',
          width: 120,

          className: 'replacecolor'
        },
        {
          title: '小po',
          dataIndex: 'smallPo',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: 'Pack Id',
          dataIndex: 'packId',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '分销点',
          dataIndex: 'distributionPoint',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '采购/委外订单号',
          dataIndex: 'purOrSubOrder',
          scopedSlots: { customRender: 'purOrSubOrder' },
          // fixed: 'left',
          width: 180,
          className: 'replacecolor'
        },
        {
          title: ' 报关单价',
          dataIndex: 'customsDeclarationUnitPrice',
          scopedSlots: { customRender: 'customsDeclarationUnitPrice' },
          // fixed: 'left',
          width: 180,
          className: 'replacecolor'
        },

        {
          title: '订单数量',
          dataIndex: 'orderQuantity',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '订单剩余数量',
          dataIndex: 'orderRemainingQuantity',
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '发货数量',
          dataIndex: 'shipmentQuantity',
          scopedSlots: { customRender: 'shipmentQuantity' },
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '套装件数',
          dataIndex: 'numberOfSets',
          scopedSlots: { customRender: 'numberOfSets' },
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '是否TC功能',
          dataIndex: 'isTC',
          width: 90,
          scopedSlots: { customRender: 'isTC' },
          className: 'replacecolor'
        },
        {
          title: '物料成分',
          dataIndex: 'materialComposition',
          scopedSlots: { customRender: 'materialComposition' },
          width: 140,
          className: 'replacecolor'
        },

        {
          title: '销售类型',
          dataIndex: 'salesTypeText',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '客户简称',
          dataIndex: 'customerAbbreviation',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '客户名称',
          dataIndex: 'customerName',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '汇率',
          dataIndex: 'exchangeRate',
          width: 120,
          className: 'replacecolor'
        },
        // {
        //   title: '整单（合计）',
        //   dataIndex: 'wholeOrderTotal',
        //   width: 120,
        //   className: 'replacecolor'
        // },

        {
          title: '销售部门',
          dataIndex: 'salesDepartment',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '业务员',
          dataIndex: 'salesman',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '币种',
          dataIndex: 'currencyText',
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '品牌方',
          dataIndex: 'brandSide',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '第三方',
          dataIndex: 'thirdParty',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '定金比例(%)',
          dataIndex: 'depositRatio',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '定金',
          dataIndex: 'deposit',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '协同路线',
          dataIndex: 'collaborativeRoute',
          width: 120,
          className: 'replacecolor'
        },

        {
          title: '单价(销售)',
          dataIndex: 'salesUnitPrice',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '工厂单价',
          dataIndex: 'factoryUnitPrice',
          width: 120,
          scopedSlots: { customRender: 'factoryUnitPrice' },
          className: 'replacecolor'
        },
        {
          title: '付款条件',
          dataIndex: 'termOfPayment',
          width: 160,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '最终客户',
          dataIndex: 'endCustomer',
          width: 120,
          className: 'replacecolor'
        },
        {
          title: '订单备注',
          dataIndex: 'orderRemarks',
          width: 160,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },

        {
          title: '申报要素',
          dataIndex: 'declarationElements',
          width: 160,
          scopedSlots: { customRender: 'declarationElements' },
          className: 'replacecolor'
        },

        {
          title: '价格备注',
          dataIndex: 'priceRemarks',
          width: 160,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '订单变更说明',
          dataIndex: 'orderChangeDescription',
          width: 160,
          customRender: t => ellipsis(t),
          className: 'replacecolor'
        },
        {
          title: '订单子表ID',
          dataIndex: 'syOrderDataItemId',
          width: 160,
          className: 'replacecolor'
        },

        {
          title: '处理方式',
          dataIndex: 'treatmentMethod',
          width: 160,
          scopedSlots: { customRender: 'treatmentMethod' },
          className: 'replacecolor'
        },
        {
          title: '是否手册纱',
          dataIndex: 'manualYarnFlag',
          width: 100,
          scopedSlots: { customRender: 'manualYarnFlag' },
          className: 'replacecolor'
        },
        {
          title: '手册纱单价',
          dataIndex: 'manualYarnUnitPrice',
          width: 160,
          scopedSlots: { customRender: 'manualYarnUnitPrice' },
          className: 'replacecolor'
        },
        {
          title: '手册纱占比',
          dataIndex: 'manualYarnProportion',
          width: 120,
          scopedSlots: { customRender: 'manualYarnProportion' },
          className: 'replacecolor'
        },

        {
          title: '操作',
          dataIndex: 'operation',
          scopedSlots: { customRender: 'operationSlot' },
          width: 220,
          fixed: 'right',
          className: 'replacecolor'
        }
      ],
      msgFormSon: 'test', // 子组件传来数据的变量
      syShippingDetailsItemList: [], // 子表信息
      editShipDet: {}, // 编辑发运明细
      visible: false,
      confirmLoading: false,
      dateFormat: 'YYYY-MM-DD'
    }
  },
  // 接收父组件查询方法
  props: {
    fatherList: {
      type: Function,
      default: null
    }
  },
  created() {},

  methods: {
    getSon(val) {
      console.log('val', val)
      this.msgFormSon = val
      this.syShippingDetailsItemList = this.msgFormSon
      console.log('编辑页 子表信息', this.syShippingDetailsItemList)
    },
    // 编辑 保存
    editSave() {
      console.log('提交编辑、刷新发运明细列表')
      editById(this.editShipDet).then(res => {
        if (res.success) {
          this.$message.success('编辑成功')
          this.close()
          this.fatherList() // 调用父组件的查询方法
        }
      })
    },
    // 参照订单数据
    referOrderDataOpen() {
      console.log('打开参照订单数据')
      this.$refs.referOrderDataModal.referOrderDataModVis = true
    },
    // 増行
    handleAddColumn() {
      console.log('増行')
      const addrow = {
        acSetNo: '',
        orderNumber: '',
        itemNumber: '',
        orderDate: '',
        businessType: '',
        customerOrder: '',
        smallPo: '',
        packId: '',
        orderData: '',
        orderRemaQuantity: '',
        shipQuantity: '',
        isTC: '',
        materialComposition: '',
        saleType: '',
        customerShortName: '',
        customerName: '',
        exchangeRate: '',
        wholeSingleCombined: '',
        salesDepartment: '',
        salesman: '',
        currency: '',
        brand: '',
        thirdParty: '',
        depositRate: '',
        deposit: '',
        collaborativeRoute: '',
        paymentClause: '',
        finalCustomer: '',
        orderNote: '',
        priceNote: '',
        orderChangeDesc: '',
        operation: ''
      }

      this.syShippingDetailsItemList.push(addrow)
    },
    // --------------------------------------
    // 操作 删除
    handleDelete(index) {
      console.log('index', index)
      console.log('删除该项订单数据', index)
      return this.syShippingDetailsItemList.splice(index, 1)
    },
    // 操作 复制
    copy(record) {},

    // --------------------------------------
    // 抽屉 取消
    handleCancel() {
      console.log('点击抽屉取消')
      this.close()
    },

    close() {
      this.$emit('close')
      this.visible = false
      this.$refs.form.resetFields()
    },
    // --------------------------------------
    // 分页、排序、筛选变化时触发
    // handleTableChange(pagination, filters, sorter) {
    //   // console.log('当前页信息>>>>',pagination)
    //   this.queryParam.pageNo = pagination.current
    //   // this.getAnnList()
    // },
    // 参照订单数据弹框 ok-------------------------------------
    referOrderDataOk() {
      console.log('参照订单数据弹框确定')
      this.$refs.referOrderDataModal.referOrderDataModVis = false
    },
    // father
    aa() {}
  },
  computed: {},
  mounted() {}
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
/deep/ .ant-table-thead > tr > th {
  text-align: center;
  // font-weight: 700;
}
/deep/ .ant-table-tbody {
  text-align: center;
}
// /deep/ th.replacecolor {
//   background-color: #ccc;
// }

// 抽屉里的card样式
/deep/ .ant-drawer-content {
  background-color: #f0f2f5;
}
/deep/ .ant-drawer-body {
  padding: 10px;
}
</style>
