AddPersonnelPool.vue 2.78 KB
<template>
  <a-modal
      title="添加人员库"
      v-if='isVisible'
      v-model:visible="isVisible"
      width="520px"
      height='50%'
      class="detail-modal"
  >
    <a-form :model="formData">
      <a-form-item label="人员类型">
        <a-select v-model:value="formData.personType" showSearch placeholder="请选择">
          <a-select-option
              v-for="(item,index) in showDataList"
              :key="index"
              :value="item.id"
          >{{item.name}}</a-select-option>
        </a-select>
      </a-form-item>
    </a-form>

    <template #footer>
      <a-button type="primary" @click="onSave">保存</a-button>
      <a-button @click="onCancel">关闭</a-button>
    </template>
  </a-modal>
</template>

<script>
import { ref } from "vue";
import { ElMessage } from "element-plus";
import clusterResultApi from './ClusterResultApi'
import moment from 'moment'
export default {
  name: 'PersonGroupEditor',
  props: {
    dataParams: {
      type: Object,
      default: null,
    },
  },
  setup(props, { emit }) {
    const isVisible = ref(false);
    // 表单
    function getInitialFormData() {
      return {
        personType: '',
				countdate:'',
				unids:[],
      }
    }
    const formData = ref(getInitialFormData())

    const initDialog = (selectedList) => {
      // console.log('initDialog', selectedList)
      formData.value = getInitialFormData()
      formData.value.unids = selectedList.map(item => item.unid)
      formData.value.countdate = selectedList.length > 0 ? moment(selectedList[0].counttime).format('YYYY-MM-DD 00:00:00') : ''
      isVisible.value = true;
      getDataList()
    };

    const showDataList = ref([])
    const getDataList = () => {
			clusterResultApi.getPersonPoolType(props.dataParams).then(r => {
				// console.log('getPersonPoolType', r)
				showDataList.value = r.data
			})
    }
    const onCancel = () => {
      isVisible.value = false;
    };
    const onSave = () => {
      const params = {
        unids: formData.value.unids,
        personType: formData.value.personType,
        countdate: formData.value.countdate,
        mallId: props.dataParams.plaza_id,
      }
      clusterResultApi.addPerson(params).then(
          (r) => {
            if(r.msg_code==200){
              ElMessage({
                message: `保存成功`,
                type: 'success'
              })
              // 刷新列表
              emit('refresh')
              onCancel()
            } else {
              ElMessage({
                message: `保存失败`,
                type: 'error'
              })
            }
          }
      )
    };

    return {
      isVisible,
      formData,
      onSave,
      onCancel,
      initDialog,
      showDataList,
    };
  },
};
</script>

<style lang="less" scoped>
</style>