<template>
  <el-dialog
    :title="!dataForm.site ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="${column.comments}" prop="rollno">
      <el-input v-model="dataForm.rollno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="rollqty">
      <el-input v-model="dataForm.rollqty" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="partno">
      <el-input v-model="dataForm.partno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="supplierid">
      <el-input v-model="dataForm.supplierid" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderref1">
      <el-input v-model="dataForm.orderref1" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderref2">
      <el-input v-model="dataForm.orderref2" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderref3">
      <el-input v-model="dataForm.orderref3" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderref4">
      <el-input v-model="dataForm.orderref4" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="suppdeliverynote">
      <el-input v-model="dataForm.suppdeliverynote" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="rolldate">
      <el-input v-model="dataForm.rolldate" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createddate">
      <el-input v-model="dataForm.createddate" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="createdby">
      <el-input v-model="dataForm.createdby" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="statusDb">
      <el-input v-model="dataForm.statusDb" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="status">
      <el-input v-model="dataForm.status" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="supprollno">
      <el-input v-model="dataForm.supprollno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="rollseqno">
      <el-input v-model="dataForm.rollseqno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="supprollnoflag">
      <el-input v-model="dataForm.supprollnoflag" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="sourcetype">
      <el-input v-model="dataForm.sourcetype" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="originalrollno">
      <el-input v-model="dataForm.originalrollno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="orderref5">
      <el-input v-model="dataForm.orderref5" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="rolltype">
      <el-input v-model="dataForm.rolltype" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="rolltypeDb">
      <el-input v-model="dataForm.rolltypeDb" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="firstlevelrollno">
      <el-input v-model="dataForm.firstlevelrollno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="remark">
      <el-input v-model="dataForm.remark" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="parttypeFlag">
      <el-input v-model="dataForm.parttypeFlag" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="warehouseid">
      <el-input v-model="dataForm.warehouseid" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="synchronizedflag">
      <el-input v-model="dataForm.synchronizedflag" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="consumeorderno">
      <el-input v-model="dataForm.consumeorderno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="consumeseqno">
      <el-input v-model="dataForm.consumeseqno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="customerid">
      <el-input v-model="dataForm.customerid" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="fgpartno">
      <el-input v-model="dataForm.fgpartno" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="refSupplierid">
      <el-input v-model="dataForm.refSupplierid" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="refPartdesc">
      <el-input v-model="dataForm.refPartdesc" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="needsynchronizeflag">
      <el-input v-model="dataForm.needsynchronizeflag" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="opslog">
      <el-input v-model="dataForm.opslog" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="frozenflag">
      <el-input v-model="dataForm.frozenflag" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="frozendate">
      <el-input v-model="dataForm.frozendate" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="${column.comments}" prop="frozenby">
      <el-input v-model="dataForm.frozenby" placeholder="${column.comments}"></el-input>
    </el-form-item>
    <el-form-item label="失效日期" prop="expireddate">
      <el-input v-model="dataForm.expireddate" placeholder="失效日期"></el-input>
    </el-form-item>
    <el-form-item label="制造日期" prop="manufacturedate">
      <el-input v-model="dataForm.manufacturedate" placeholder="制造日期"></el-input>
    </el-form-item>
    </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>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          site: 0,
          rollno: '',
          rollqty: '',
          partno: '',
          supplierid: '',
          orderref1: '',
          orderref2: '',
          orderref3: '',
          orderref4: '',
          suppdeliverynote: '',
          rolldate: '',
          createddate: '',
          createdby: '',
          statusDb: '',
          status: '',
          supprollno: '',
          rollseqno: '',
          supprollnoflag: '',
          sourcetype: '',
          originalrollno: '',
          orderref5: '',
          rolltype: '',
          rolltypeDb: '',
          firstlevelrollno: '',
          remark: '',
          parttypeFlag: '',
          warehouseid: '',
          synchronizedflag: '',
          consumeorderno: '',
          consumeseqno: '',
          customerid: '',
          fgpartno: '',
          refSupplierid: '',
          refPartdesc: '',
          needsynchronizeflag: '',
          opslog: '',
          frozenflag: '',
          frozendate: '',
          frozenby: '',
          expireddate: '',
          manufacturedate: ''
        },
        dataRule: {
          rollno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          rollqty: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          partno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          supplierid: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderref1: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderref2: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderref3: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderref4: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          suppdeliverynote: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          rolldate: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createddate: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          createdby: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          statusDb: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          supprollno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          rollseqno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          supprollnoflag: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          sourcetype: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          originalrollno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          orderref5: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          rolltype: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          rolltypeDb: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          firstlevelrollno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          remark: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          parttypeFlag: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          warehouseid: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          synchronizedflag: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          consumeorderno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          consumeseqno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          customerid: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          fgpartno: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          refSupplierid: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          refPartdesc: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          needsynchronizeflag: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          opslog: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          frozenflag: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          frozendate: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          frozenby: [
            { required: true, message: '${column.comments}不能为空', trigger: 'blur' }
          ],
          expireddate: [
            { required: true, message: '失效日期不能为空', trigger: 'blur' }
          ],
          manufacturedate: [
            { required: true, message: '制造日期不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.site = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.site) {
            this.$http({
              url: this.$http.adornUrl(`/finishedProduct/crollinfo/info/${this.dataForm.site}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.rollno = data.cRollinfo.rollno
                this.dataForm.rollqty = data.cRollinfo.rollqty
                this.dataForm.partno = data.cRollinfo.partno
                this.dataForm.supplierid = data.cRollinfo.supplierid
                this.dataForm.orderref1 = data.cRollinfo.orderref1
                this.dataForm.orderref2 = data.cRollinfo.orderref2
                this.dataForm.orderref3 = data.cRollinfo.orderref3
                this.dataForm.orderref4 = data.cRollinfo.orderref4
                this.dataForm.suppdeliverynote = data.cRollinfo.suppdeliverynote
                this.dataForm.rolldate = data.cRollinfo.rolldate
                this.dataForm.createddate = data.cRollinfo.createddate
                this.dataForm.createdby = data.cRollinfo.createdby
                this.dataForm.statusDb = data.cRollinfo.statusDb
                this.dataForm.status = data.cRollinfo.status
                this.dataForm.supprollno = data.cRollinfo.supprollno
                this.dataForm.rollseqno = data.cRollinfo.rollseqno
                this.dataForm.supprollnoflag = data.cRollinfo.supprollnoflag
                this.dataForm.sourcetype = data.cRollinfo.sourcetype
                this.dataForm.originalrollno = data.cRollinfo.originalrollno
                this.dataForm.orderref5 = data.cRollinfo.orderref5
                this.dataForm.rolltype = data.cRollinfo.rolltype
                this.dataForm.rolltypeDb = data.cRollinfo.rolltypeDb
                this.dataForm.firstlevelrollno = data.cRollinfo.firstlevelrollno
                this.dataForm.remark = data.cRollinfo.remark
                this.dataForm.parttypeFlag = data.cRollinfo.parttypeFlag
                this.dataForm.warehouseid = data.cRollinfo.warehouseid
                this.dataForm.synchronizedflag = data.cRollinfo.synchronizedflag
                this.dataForm.consumeorderno = data.cRollinfo.consumeorderno
                this.dataForm.consumeseqno = data.cRollinfo.consumeseqno
                this.dataForm.customerid = data.cRollinfo.customerid
                this.dataForm.fgpartno = data.cRollinfo.fgpartno
                this.dataForm.refSupplierid = data.cRollinfo.refSupplierid
                this.dataForm.refPartdesc = data.cRollinfo.refPartdesc
                this.dataForm.needsynchronizeflag = data.cRollinfo.needsynchronizeflag
                this.dataForm.opslog = data.cRollinfo.opslog
                this.dataForm.frozenflag = data.cRollinfo.frozenflag
                this.dataForm.frozendate = data.cRollinfo.frozendate
                this.dataForm.frozenby = data.cRollinfo.frozenby
                this.dataForm.expireddate = data.cRollinfo.expireddate
                this.dataForm.manufacturedate = data.cRollinfo.manufacturedate
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/finishedProduct/crollinfo/${!this.dataForm.site ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'site': this.dataForm.site || undefined,
                'rollno': this.dataForm.rollno,
                'rollqty': this.dataForm.rollqty,
                'partno': this.dataForm.partno,
                'supplierid': this.dataForm.supplierid,
                'orderref1': this.dataForm.orderref1,
                'orderref2': this.dataForm.orderref2,
                'orderref3': this.dataForm.orderref3,
                'orderref4': this.dataForm.orderref4,
                'suppdeliverynote': this.dataForm.suppdeliverynote,
                'rolldate': this.dataForm.rolldate,
                'createddate': this.dataForm.createddate,
                'createdby': this.dataForm.createdby,
                'statusDb': this.dataForm.statusDb,
                'status': this.dataForm.status,
                'supprollno': this.dataForm.supprollno,
                'rollseqno': this.dataForm.rollseqno,
                'supprollnoflag': this.dataForm.supprollnoflag,
                'sourcetype': this.dataForm.sourcetype,
                'originalrollno': this.dataForm.originalrollno,
                'orderref5': this.dataForm.orderref5,
                'rolltype': this.dataForm.rolltype,
                'rolltypeDb': this.dataForm.rolltypeDb,
                'firstlevelrollno': this.dataForm.firstlevelrollno,
                'remark': this.dataForm.remark,
                'parttypeFlag': this.dataForm.parttypeFlag,
                'warehouseid': this.dataForm.warehouseid,
                'synchronizedflag': this.dataForm.synchronizedflag,
                'consumeorderno': this.dataForm.consumeorderno,
                'consumeseqno': this.dataForm.consumeseqno,
                'customerid': this.dataForm.customerid,
                'fgpartno': this.dataForm.fgpartno,
                'refSupplierid': this.dataForm.refSupplierid,
                'refPartdesc': this.dataForm.refPartdesc,
                'needsynchronizeflag': this.dataForm.needsynchronizeflag,
                'opslog': this.dataForm.opslog,
                'frozenflag': this.dataForm.frozenflag,
                'frozendate': this.dataForm.frozendate,
                'frozenby': this.dataForm.frozenby,
                'expireddate': this.dataForm.expireddate,
                'manufacturedate': this.dataForm.manufacturedate
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
