mark-person-modal.vue 5.12 KB
<template>
  <el-dialog
    :title="$t('button.markPerson')"
    :visible.sync="show"
    class="manage-dialog"
    :before-close="onClose"
    :close-on-click-modal="false"
  >
    <el-form :model="addForm" status-icon :rules="rules" ref="addForm">
      <el-form-item :label="$t('table.name')" prop="name">
        <el-input v-model="addForm.name"></el-input>
        <i class="error-tip">*</i>
      </el-form-item>
      <el-form-item :label="$t('table.gender')" prop="gender">
        <el-select
          class="manage-sel"
          v-model="addForm.gender"
          :placeholder="$t('pholder.select')"
          :no-data-text="$t('pholder.nodata')"
        >
          <el-option :label="$t('head.man')" :value="1"></el-option>
          <el-option :label="$t('head.woman')" :value="0"></el-option>
        </el-select>
        <i class="error-tip">*</i>
      </el-form-item>
      <el-form-item :label="$t('table.age')" prop="age">
        <el-input v-model.number="addForm.age"></el-input>
        <i class="error-tip">*</i>
      </el-form-item>
      <el-form-item :label="$t('asisTab.manType')" prop="type">
        <el-select
          class="manage-sel"
          v-model="addForm.type"
          :placeholder="$t('asisTab.manType')"
          :no-data-text="$t('pholder.nodata')"
        >
          <el-option
            v-for="item in personTypeList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
        <i class="error-tip">*</i>
      </el-form-item>
      <el-form-item :label="$t('table.square')" prop="mallId">
        <el-select
          class="manage-sel"
          v-model="addForm.mallId"
          disabled
          :placeholder="$t('pholder.select')"
          :no-data-text="$t('pholder.nodata')"
        >
          <el-option v-for="item in mallList" :key="item.id" :label="item.name" :value="item.id"></el-option>
        </el-select>
        <i class="error-tip">*</i>
      </el-form-item>
      <el-form-item :label="$t('dialog.description')">
        <el-input type="textarea" v-model="addForm.detail"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        :loading="creating"
        @click="onConfirm"
        class="mark-btn"
      >{{ $t('dialog.confirm') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  props: {
    modalRow: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    const validateAge = (rule, value, callback) => {
      if (!value) {
        return callback(new Error(this.$t('rules.emptyAge')))
      } else {
        callback()
      }
    }
    return {
      show: true,
      mallList: [],
      personTypeList: [],
      addForm: {},
      creating: false,
      rules: {
        name: [{ required: true, message: this.$t('rules.userName'), trigger: "change" }],
        gender: [{ required: true, message: this.$t('rules.emptyGender'), trigger: "change" }],
        age: [{ validator: validateAge, trigger: "change" }],
        type: [{ required: true, message: this.$t('message.enterPersonType'), trigger: "change" }],
        mallId: [
          { required: true, message: this.$t('rules.orgIdMall'), trigger: "change" }
        ]
      }
    }
  },
  async mounted() {
    await this.getMallList()
    await this.getPersonTypeList()
    this.addForm = Object.assign({}, this.addForm, this.modalRow)
  },
  methods: {
    getMallList() {
      return new Promise((resolve, reject) => {
        this.getCommonMalls().then(
          resolveData => {
            let { mallData, localMallId } = resolveData
            this.mallList = mallData
            // this.listQuery.mallValue = localMallId
            resolve()
          },
          rejectData => {}
        )
      })
    },
    getPersonTypeList() {
      return new Promise(resolve => {
        this.$api.management.personTypeList({
          accountId: this.$cookie.get('accountId'),
          mallId: this.modalRow.mallId
        }).then(res => {
          const { code, data } = res.data
          if (code === 200) {
            this.personTypeList = data.reduce((arr, curr, index) => {
              arr.push(curr)
              return arr
            }, [])
            resolve()
          }
        })
      })
    },
    onConfirm() {
      this.$refs.addForm.validate(async valid => {
        if (valid) {
          this.creating = true
          try {
            this.addForm.createType = 1
            await this.$api.management.markPerson(this.addForm).then(res => {
              const { code } = res.data
              this.creating = false
              if (code === 200) {
                this.onClose()
              }
            })
          } catch (error) {
            this.creating = false
            this.catchErrorHandle(error)
          } 
        }
      })
    },
    onClose() {
      this.$refs.addForm.resetFields()
      this.$emit('onCancel')
    },
  }
}
</script>

<style scoped>
.mark-btn {
  padding: 10px 21px 9px 20px;
  border: none;
  border-radius: 3px;
  font-size: 13px;
  border: none;
  background: #0069FF;
  color: #fff;
}
</style>