<template>
  <el-dialog
    title="新增盘点"
    width="70%"
    :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 :span="8">
          <el-form-item label="盘点编码" prop="inventoryCode">
            <el-input v-model="dataForm.inventoryCode" :disabled="true" placeholder="系统自动生成"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="padding-left: 20px">
          <el-form-item label="盘点员" prop="checkerId">
            <user-component v-model="dataForm.checkerId" :user-id="dataForm.checkerId"/>
          </el-form-item>
        </el-col>
        <el-col :span="8" style="padding-left: 20px">
          <el-form-item label="复核员" prop="dcheckerId">
            <user-component v-model="dataForm.dcheckerId" :user-id="dataForm.dcheckerId"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row class="my-row">
        <el-form-item label="备注说明">
            <el-input v-model="dataForm.notes"  placeholder="备注说明"></el-input>
          </el-form-item>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import UserComponent from '../common/user-component'
  import DictSelect from '../sys/dict-select'
  export default {
    name: 'inventory-add',
    components: {DictSelect, UserComponent},
    data () {
      return {
        visible: false,
        dataForm: { },
        dataRule: {
          checkerId: [{ required: true, message: '盘点员不能为空', trigger: 'change' }],
          dcheckerId: [{ required: true, message: '复核员不能为空', trigger: 'change' }]
        }
      }
    },
    methods: {
      init () {
        this.visible = true
        this.dataForm = {}
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/biz-service/inventory-checking-ctl/save`),
              method: 'post',
              data: this.$http.adornData({
                'checkerId': this.dataForm.checkerId,
                'dcheckerId': this.dataForm.dcheckerId,
                'notes': this.dataForm.notes,
                'creatorId': this.$store.state.user.id,
                'orgId': this.$store.state.user.orgId
              })
            }).then(({data}) => {
              if (data && data.code === '200') {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      },
      validateField (type) {
        this.$refs.dataForm.validateField(type)
      }
    }
  }
</script>

<style scoped>
.my-line{
  border-bottom: 1px solid #c0c4cc;
  margin-bottom: 10px;
}
</style>
