<template>
  <el-dialog
    v-dialogDrag
    title="交期确认"
    :visible.sync="open"
    width="1200px"
    append-to-body
    @close="dialogClose"
  >
    <!-- 操作 -->
    <!-- <el-row :gutter="10" class="mb10">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['wms:purchase-order-detail:update']"
          v-loading="ensureLoading"
          type="primary"
          size="small"
          plain
          @click="handleEnsure"
        >确认</el-button>
      </el-col>
    </el-row> -->
    <!-- 列表 -->
    <el-table
      v-loading="loading"
      :data="currentRows"
      border
      size="mini"
    >
      <el-table-column
        label="物料编号"
        align="center"
        prop="materialNo"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="materialName"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column label="物料数量" align="center" prop="materialQty" />
      <el-table-column
        label="物料单位名称"
        align="center"
        prop="unitName"
        width="120"
        show-overflow-tooltip
      />
      <el-table-column
        label="应收货数量"
        align="center"
        prop="shouldReceiveQty"
        width="120"
      />
      <el-table-column
        label="已收货数量"
        align="center"
        prop="receiveQty"
        width="120"
      />
      <el-table-column label="已退数量" align="center" prop="returnQty" />
      <el-table-column
        label="物料状态"
        align="center"
        prop="materialStatus"
        width="120"
      >
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.WMS_MATERIALS_STATUS" :value="scope.row.materialStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="确认交货日期"
        align="center"
        prop="confirmDeliveryTime"
        width="220"
      >
        <template slot-scope="scope">
          <el-date-picker
            v-model="scope.row.confirmDeliveryTime"
            style="width: 190px"
            type="date"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            placeholder="请选择确认交货日期"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="确认交货数量"
        align="center"
        prop="confirmQty"
        width="100"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.confirmQty" placeholder="请输入确认交货数量" />
        </template>
      </el-table-column>
      <el-table-column
        label="确认意见"
        align="center"
        prop="confirmComment"
        width="160"
      >
        <template slot-scope="scope">
          <el-input v-model="scope.row.confirmComment" placeholder="请输入确认意见" />
        </template>
      </el-table-column>
      <el-table-column
        label="要求送货时间"
        align="center"
        prop="deliveryTime"
        width="180"
      />
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel">取消</el-button>
      <el-button
        v-hasPermi="['wms:purchase-order-detail:update']"
        v-loading="ensureLoading"
        type="primary"
        size="small"
        @click="handleEnsure"
      >确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { purchaseConfirmTime } from '@/api/wms/orders/purchase'

export default {
  name: 'DeliveryConfimation',
  components: {
  },
  props: {
    currentRows: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      ensureLoading: false,
      // 总条数
      total: 0,
      // ERP采购订单明细列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        detailErpId: null,
        inStockId: null,
        erpInStockOrderId: null,
        erpInStockOrderNo: null,
        detailNumber: null,
        materialNo: null,
        materialName: null,
        materialQty: null,
        materialModels: null,
        unitName: null,
        shouldReceiveAmount: null,
        receiveQty: null,
        returnQty: null,
        materialStatus: null,
        supplierCode: null,
        supplierName: null,
        batch: null,
        price: null,
        taxPrice: null,
        allAmount: null,
        taxRate: null,
        comment: null,
        deliveryTime: [],
        createTime: [],
        erpMark: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        detailErpId: undefined,
        inStockId: undefined,
        erpInStockOrderId: undefined,
        erpInStockOrderNo: undefined,
        detailNumber: undefined,
        materialNo: undefined,
        materialName: undefined,
        materialQty: undefined,
        materialModels: undefined,
        unitName: undefined,
        shouldReceiveAmount: undefined,
        receiveQty: undefined,
        returnQty: undefined,
        materialStatus: undefined,
        supplierCode: undefined,
        supplierName: undefined,
        batch: undefined,
        price: undefined,
        taxPrice: undefined,
        allAmount: undefined,
        taxRate: undefined,
        comment: undefined,
        deliveryTime: undefined,
        erpMark: undefined
      }
      this.resetForm('form')
    },
    dialogClose() {
      // this.currentRows = []
    },
    handleEnsure() {
      const params = this.currentRows.map(item => {
        const { wmsPurchaseOrderDetailId, confirmQty, confirmComment, confirmDeliveryTime } = item
        return {
          id: wmsPurchaseOrderDetailId,
          confirmQty,
          confirmComment,
          confirmDeliveryTime
        }
      })
      this.ensureLoading = true
      purchaseConfirmTime(params).then(res => {
        this.$modal.msgSuccess('确认成功!')
        this.open = false
        this.$emit('ensureComplete')
      }).finally(() => {
        this.ensureLoading = false
      })
    }
  }
}
</script>

