<template>
  <div>
    <el-dialog
      title="确定发货"
      width="50%"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <!-- 表单 -->
      <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="auto">
        <el-row class="my-row">
          <el-col>
            <el-form-item label="发货数量" prop="cnt">
              <el-input-number v-model="dataForm.cnt" :min="0" :max="Number(max)"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" >
          <el-button @click="onChose">取消</el-button>
          <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'dispatching',
    data () {
      return {
        visible: false,
        max: 0,
        dataForm: {},
        dataRule: {
          cnt: [{ required: true, message: '发货数量不能为空', trigger: 'change' }]
        }
      }
    },
    methods: {
      onChose () {
        this.visible = false
        this.$emit('onChose')
      },
      async init (deliverId, max) {
        if (!deliverId) return
        this.max = max
        this.dataForm = {
          deliverId: deliverId
        }
        this.visible = true
      },
      validateField (type) {
        this.$refs.dataForm.validateField(type)
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/biz-service/deliver/deliver`),
              method: 'post',
              data: this.$http.adornData({...this.dataForm})
            }).then(({data}) => {
              if (data && data.code === '200') {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.onChose()
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>

<style scoped>

</style>
