addDialog.vue 9.73 KB
<template>
  <el-form ref="ruleForm" :model="ruleForm" label-width="100px" :rules="rules">
    <el-row>
      <el-col :span="12">
        <el-form-item label="入库编号:" prop="batchno">
          <el-input v-model="ruleForm.batchno" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="登记机构:" prop="djjg">
          <el-select v-model="ruleForm.djjg" class="width100" placeholder="请选择" :disabled="!readOnly">
            <el-option v-for="item in DJJGLIST" :key="item.dname" :label="item.dname" :value="item.dname">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="入库人员:">
          <el-input v-model="ruleForm.operator" :disabled="true"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="入库时间:" prop="operationtime">
          <el-date-picker v-model="ruleForm.operationtime" class="width100" type="datetime" :disabled="!readOnly"
            value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
      </el-col>
    </el-row>
    <el-table :data="ruleForm.tableForm" border style="width: 100%"
      :header-cell-style="{ 'text-align': 'center', background: 'rgb(236, 245, 255)' }"
      :cell-style="{ 'text-align': 'center' }">
      <el-table-column prop="name" label="纸质证书类型" width="200"></el-table-column>
      <el-table-column prop="ksysxlh" label="开始印刷序列号" width="200">
        <template slot-scope="scope">
          <el-form-item
            :prop="'tableForm.' + scope.$index + '.ksysxlh'"
            :rules="rules.ksysxlh">
            <el-input v-model="scope.row.ksysxlh" @blur="ysxlhDeal(scope.row)" maxlength="11"
              oninput="value=value.replace(/[^\d.]/g,'')" :disabled="!readOnly"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column prop="jsysxlh" label="结束印刷序列号" width="200">
        <template slot-scope="scope">
          <el-form-item
            :prop="'tableForm.' + scope.$index + '.jsysxlh'"
            :rules="rules.jsysxlh">
            <el-input v-model="scope.row.jsysxlh" @blur="ysxlhDeal(scope.row)" maxlength="11"
              oninput="value=value.replace(/[^\d.]/g,'')" :disabled="!readOnly"></el-input>
          </el-form-item>
        </template>
      </el-table-column>
      <el-table-column prop="bs" label="本数">
        <template slot-scope="scope">
          <span v-if="scope.row.bs == 0" class="font-red">系统计算</span>
          <span v-else-if="scope.row.bs < 0" class="font-red">印刷序列号有误</span>
          <span v-else>{{ scope.row.bs }}</span>
        </template>
      </el-table-column>
    </el-table>
    <el-form-item label="备注" class="middle-margin-bottom">
      <el-input type="textarea" v-model="ruleForm.bz" :rows="4" :disabled="!readOnly"></el-input>
    </el-form-item>
    <el-form-item v-if="readOnly" style="text-align:center">
      <el-button type="primary" @click="submitForm">保存</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import store from '@/store/index.js'
  import { zsrk, getZsglInfo } from "@/api/zsgl.js"
  import { getSysSerialSingle } from "@/api/sysSerial.js"
  export default {
    props: {
      formData: {
        type: Object,
        default: () => { },
      },
    },
    data () {
      return {
        DJJGLIST: store.getters.dictData['ywly'],
        readOnly: false,
        //表单提交数据
        ruleForm: {
          batchno: '',
          djjg: '',
          operator: '超级管理员',
          operationtime: '',
          bz: '',
          zsstarno: '',
          zsendno: '',
          zsnum: '',
          zmstarno: '',
          zmendno: '',
          zmnum: '',
          //表格数据
          tableForm: [
            {
              name: '不动产权证书',
              ksysxlh: '',
              jsysxlh: '',
              bs: 0,
              zslx: 1
            },
            {
              name: '不动产登记证明',
              ksysxlh: '',
              jsysxlh: '',
              bs: 0,
              zslx: 2
            }
          ]
        },
        //证书入库业务号参数
        ywhQueryForm: {
          serialtype: 'zsrkbh',
          serialname: '证书入库编号',
          serialcode: 'zsrk',
          digit: '5'
        },
        rules: {
          batchNo: [
            { required: true, message: '入库编号不能为空', trigger: 'blur' }
          ],
          djjg: [
            { required: true, message: '请选择登记机构', trigger: 'change' }
          ],
          rksj: [
            { required: true, message: '请选择入库时间', trigger: 'change' }
          ],
          ksysxlh: [
            { required: true, message: '开始印刷序列号不能为空', trigger: 'blur' }
          ],
          jsysxlh: [
            { required: true, message: '结束印刷序列号不能为空', trigger: 'blur' }
          ]
        },
      }
    },
    mounted () {
      if (this.formData.bsmBatch) {
        this.ruleForm.tableForm[0].bs = null;
        this.ruleForm.tableForm[1].bs = null;
        this.getDetailInfo(this.formData.bsmBatch);
      } else {
        this.ywhSerial();
      }
    },
    methods: {
      /**
       * @description: 表单提交
       * @author: renchao
       */
      submitForm () {
        let that = this
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
            let arr = this.ruleForm.tableForm.filter(item => item.bs > 0)
            if (arr.length < 2) {
              that.$message.error('本书必须大于0,请检查印刷序列号');
              return
            }
            store.dispatch("user/refreshPage", false);
            zsrk(this.ruleForm).then(res => {
              if (res.code == 200) {
                that.$message.success('保存成功')
                that.$popupCacel()
                that.$refs['ruleForm'].resetFields()
                that.resetTableFields()
                store.dispatch("user/refreshPage", true);
              } else {
                that.$message.error(res.message);
              }
            })
          } else {
            return false;
          }
        })
      },
      /**
       * @description: 序列号获取
       * @author: renchao
       */
      ywhSerial () {
        getSysSerialSingle(this.ywhQueryForm).then(res => {
          if (res.code == 200) {
            this.ruleForm.batchno = res.message;
            this.readOnly = true;
          }
        })
      },
      /**
       * @description: 获取详情信息
       * @param {*} bsmBatch
       * @author: renchao
       */
      getDetailInfo (bsmBatch) {
        getZsglInfo({ "bsmBatch": bsmBatch }).then(res => {
          if (res.code == 200) {
            this.ruleForm = res.result;
            this.$refs.ruleForm.resetFields()
            this.readOnly = false;
            this.ruleForm.tableForm[0].ksysxlh = res.result.zsstarno;
            this.ruleForm.tableForm[0].jsysxlh = res.result.zsendno;
            this.ruleForm.tableForm[0].bs = res.result.zsnum;
            this.ruleForm.tableForm[1].ksysxlh = res.result.zmstarno;
            this.ruleForm.tableForm[1].jsysxlh = res.result.zmendno;
            this.ruleForm.tableForm[1].bs = res.result.zmnum;
          }
        })
      },
      /**
       * @description: 印刷序列号处理
       * @param {*} item
       * @author: renchao
       */
      ysxlhDeal (item) {
        if (item.ksysxlh && item.jsysxlh) {
          if (item.ksysxlh.length == item.jsysxlh.length) {
            if (item.ksysxlh.length != 11) {
              item.bs = -1;
              return;
            }
            if (item.ksysxlh > item.jsysxlh) {
              item.bs = -1;
              return;
            }
            item.bs = item.jsysxlh - item.ksysxlh + 1;
            if (item.zslx == 1) {
              this.ruleForm.zsstarno = item.ksysxlh;
              this.ruleForm.zsendno = item.jsysxlh;
              this.ruleForm.zsnum = item.bs
            } else if (item.zslx == 2) {
              this.ruleForm.zmstarno = item.ksysxlh;
              this.ruleForm.zmendno = item.jsysxlh;
              this.ruleForm.zmnum = item.bs
            }
          } else {
            item.bs = -1;
          }
        } else {
          item.bs = 0;
          if (item.zslx == 1) {
            this.ruleForm.zsstarno = '';
            this.ruleForm.zsendno = '';
            this.ruleForm.zsnum = item.bs
          } else if (item.zslx == 2) {
            this.ruleForm.zmstarno = '';
            this.ruleForm.zmendno = '';
            this.ruleForm.zmnum = item.bs
          }
        }
      },
      /**
       * @description: resetTableFields
       * @author: renchao
       */
      resetTableFields () {
        this.ruleForm.tableForm = [
          {
            name: '不动产权证书',
            ksysxlh: '',
            jsysxlh: '',
            bs: 0,
            zslx: 1
          },
          {
            name: '不动产权登记证明',
            ksysxlh: '',
            jsysxlh: '',
            bs: 0,
            zslx: 2
          }
        ]
      },
      /**
       * @description: closeDialog
       * @author: renchao
       */
      closeDialog () {
        this.$popupCacel()
        this.$refs['ruleForm'].resetFields();
        this.resetTableFields();
      }
    }
  }
</script>
<style scoped lang="scss">
  @import "~@/styles/mixin.scss";
  @import "~@/styles/dialogBoxheader.scss";
  /deep/.cell .el-form-item {
    margin-bottom: 0;
  }
  .font-red {
    color: red;
  }

  .middle-margin-bottom {
    margin-top: 20px;
  }
</style>