<template>
  <el-dialog
    v-dialogDrag
    title="签收"
    :visible.sync="open"
    width="30%"
    append-to-body
    @open="dialogOpen"
  >
    <el-form
      :model="form"
      size="mini"
      label-width="88px"
      @submit.native.prevent
    >
      <el-form-item prop="encodedEmployeeId" label="签收人">
        <el-input v-model="form.encodedEmployeeId" placeholder="请扫入签收人" @keyup.enter.native="handleFinish" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="open= false">取消</el-button>
      <el-button
        v-hasPermi="['wms:sale-return-master:update']"
        :loading="buttonLoading"
        type="primary"
        size="mini"
        @click="handleFinish"
      >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { signSaleReturn } from '@/api/wms/output/salesReturn'
export default {
  name: 'PurchaseReturnOrderDetail',
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // wms来料退货单明细列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        masterId: null
      },
      buttonLoading: false,
      // 表单参数
      form: {
        encodedEmployeeId: null
      },
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    // this.getList()
  },
  methods: {
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        masterId: undefined,
        purchaseOrderNo: undefined,
        wmsIncomingReceiptId: undefined,
        materialNo: undefined,
        returnQty: undefined,
        returnStatus: undefined,
        remark: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    async handleFinish() {
      if (!this.form.encodedEmployeeId) {
        this.$modal.msgWarning('请先扫入签收人')
        return
      }
      this.buttonLoading = true
      const params = {
        id: this.queryParams.masterId,
        encodedEmployeeId: this.form?.encodedEmployeeId
      }
      await signSaleReturn(params)
      this.$modal.msgSuccess('签收成功!')
      this.open = false
      this.buttonLoading = false
      this.$emit('signComplete')
      // signSaleReturn(params).then(res => {
      //   this.$modal.msgSuccess('签收成功!')
      //   this.open = false
      //   this.$emit('signComplete')
      // }).finally(() => {
      //   this.buttonLoading = false
      // })
    },
    dialogOpen() {
      this.$nextTick(() => {
        this.form.encodedEmployeeId = undefined
      })
    }
  }
}
</script>

