FilmDialog.vue 4.88 KB
<template>
  <GLDialog v-if="dialogShow" bigTitle="选择膜卷号" mode="big" :visible.sync="dialogShow" :close-on-click-modal="false">
    <div class="detail-info">
      <div>
        已添加数量:
        <span>{{ filmRollList.length }}</span>
      </div>
      <div>
        最大可添加数量:
        <span>{{ detailInfo[maxAddNumAttr] }}</span>
      </div>
      <div class="add-btn" @click="addLineTable">
        添加一行
      </div>
    </div>
    <GLTable :tableData="filmRollList" :noDataImg="url" :tableParams="tableParams" :hasPage="false">
      <template slot="filmNum" slot-scope="scope">
        <el-form :ref="'addForm' + scope.index" :model="scope.scope" size="small" :rules="rules">
          <el-form-item style="margin-bottom: 0px" prop="filmNum">
            <el-input v-model="scope.scope.filmNum" placeholder="请输入" maxlength="50"
              @input="e => handleInputFilmNum(e, scope.index)"></el-input>
          </el-form-item>
        </el-form>
      </template>
      <div class="table-btns" slot="auth-button" slot-scope="scope">
        <el-button type="text" @click="handleDelete(scope.index)">删除</el-button>
      </div>
    </GLTable>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="dialogShow = false">取消</el-button>
      <el-button type="primary" size="small" @click="handleSave">确定</el-button>
    </span>
  </GLDialog>
</template>
<script>
import BigNumber from 'bignumber.js'
import * as dayjs from 'dayjs'
export default {
  name: 'FilmDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => { }
    },
    maxAddNumAttr: {
      type: String,
      default: 'goodsNumber'
    }
  },
  watch: {
    visible(val) {
      this.filmRollList = []
      if (val) {
        this.detailInfo = this.$common.utils.deepClone(this.info || {})
        if (val) {
          if (!this.info.filmRollList) {
            this.filmRollList = [{ filmNum: '' }]
          } else {
            this.info?.filmRollList.forEach(item => {
              this.filmRollList.push({
                filmNum: item
              })
            })
          }
        }
      }
    }
  },
  computed: {
    dialogShow: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  data() {
    return {
      dayjs: dayjs,
      filmRollList: [],
      tableParams: {
        tableOption: true,
        tableColumns: [
          {
            label: '膜卷号',
            prop: 'filmNum',
            addHtml: 'filmNum'
          }
        ]
      },
      rules: {
        filmNum: [{ required: true, message: '请输入膜卷号', trigger: 'blur' }]
      },
      detailInfo: {},
      tableData: []
    }
  },
  methods: {
    handleInputFilmNum(val, idx) {
      const reg = /^[0-9a-zA-Z]*$/
      if (!reg.test(val)) {
        this.filmRollList[idx].filmNum = val.slice(0, val.length - 1)
      }
    },
    handleDetailClose() {
      this.dialogShow = false
    },
    handleDelete(idx) {
      if (this.filmRollList.length > 1) {
        this.filmRollList.splice(idx, 1)
      }
    },
    addLineTable() {
      if (this.filmRollList.length == this.detailInfo[this.maxAddNumAttr]) {
        return true
      }
      this.filmRollList.push({
        filmNum: ''
      })
    },
    handleSave() {
      let flag = true
      for (let i = 0; i < this.filmRollList.length; i++) {
        this.$refs['addForm' + i].validate(valid => {
          flag = valid
        })
        if (!flag) {
          return true
        }
      }
      if (this.filmRollList.length != this.detailInfo[this.maxAddNumAttr]) {
        this.$message({
          message: '请添加满足最大可添加数量的膜卷号',
          type: 'error',
          customClass: 'message-Z-zinde'
        })
        return true
      }
      let list = this.filmRollList.map(item => item.filmNum)
      this.$emit('handleConfirm', list)
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #666666ff;
  font-size: 14px;
  margin-bottom: 16px;

  span {
    color: #333333ff;
  }

  .add-btn {
    font-size: 14px;
    color: #5850ff;
    cursor: pointer;
    border: 1px solid #5850ff;
    border-radius: 4px;
    padding: 6px 16px;
  }
}

.table-wrap {
  box-sizing: border-box;
  margin-top: 16px;

  ::v-deep .el-form-item__error {
    padding-top: 2px;
    z-index: 9999999;
    position: static;
  }

  ::v-deep td.el-table__cell {
    height: 64px;
  }
}

// .lookNumber {
//   font-size: 14px;
//   color: #5850ff !important;
//   cursor: pointer;
//   margin-left: 8px;
// }
.look-card-wrap {
  ::v-deep.el-table th.el-table__cell>.cell {
    padding: 0 16px;
    text-align: center;
  }

  ::v-deep.el-table__body td.el-table__cell {
    text-align: center;
  }
}
</style>