zenglf
2023-09-18 92ff846fb659c62037a32b1d8c15eae9df9d9b54
src/views/eam/modules/equipmentCategory/EquipmentCategoryModel.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,558 @@
<template>
  <a-modal
    :title="title"
    :width="1250"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ props: {disabled: disableSubmit} }"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
<!--        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item
              label="上级设备分类编号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                allow-clear
                :disabled="true"
                :placeholder="disableSubmit?'':'请输入上级设备分类编号'"
                v-decorator="['parentNum', validatorRules.parentNum ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              label="上级设备分类名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                allow-clear
                :disabled="true"
                :placeholder="disableSubmit?'':'请输入上级设备分类名称'"
                v-decorator="['parentName', validatorRules.parentName ]"
              />
            </a-form-item>
          </a-col>
        </a-row>-->
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item
              label="设备分类编号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请输入设备分类编号'"
                v-decorator="['num', validatorRules.num ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12" v-if="parentId!='-1'">
            <a-form-item
              label="设备分类名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
              <a-input
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请输入设备分类名称'"
                v-decorator="['name', validatorRules.name ]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12" v-if="parentId=='-1'">
            <a-form-item
              label="设备分类名称"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
            >
            <j-dict-select-tag
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请选择分类名称'"
                :triggerChange="true"
                dictCode="sys_dict_item,item_text,item_text,dict_id ='1695985281980776449'"
                v-decorator="['name', validatorRules.name ]"
              />
            </a-form-item>
          </a-col>
        </a-row>
          <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="分类标识"
            >
              <j-dict-select-tag
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请选择分类标识'"
                :triggerChange="true"
                dictCode="equipment_category"
                v-decorator="['equipmentCategoryUda1', validatorRules.equipmentCategoryUda1]"
              />
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="技术状态鉴定周期"
            >
            <j-dict-select-tag
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请选择技术状态鉴定周期'"
                :triggerChange="true"
                dictCode="appraisal_cycle"
                v-decorator="['equipmentCategoryUda2', validatorRules.equipmentCategoryUda2]"
              />
            </a-form-item>
          </a-col>
        </a-row>
          <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item
              :labelCol="labelCol"
              :wrapperCol="wrapperCol"
              label="备注"
            >
              <a-textarea
                allow-clear
                :disabled="disableSubmit"
                :placeholder="disableSubmit?'':'请输入备注'"
                v-decorator="['remark', validatorRules.remark]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <a-divider  v-if="title!='新增'" orientation="center" style="font-size: large;font-style: italic;color: #66aeed;"> é€‰æ‹©å­è®¾å¤‡åˆ†ç±»ä½¿å…¶è·Ÿéšçˆ¶è®¾å¤‡åˆ†ç±»å±žæ€§ </a-divider>
      <a-tabs
        type="card"
        defaultActiveKey="1"
        v-if="title!='新增'"
      >
      <a-tab-pane
          tab='子设备分类'
          key='1'
        >
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> å·²é€‰æ‹© <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <a-table
      ref="table"
      bordered
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change="handleTableChange"
      :scroll="{ x: true}"
     >
        <template slot="num" slot-scope="text" >
          <a-tooltip placement="top" :title="text" trigger="hover">
            <div>
              <template slot="title"> </template>
              <p style="cusor:pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; width: 130px;">{{ text }}</p>
            </div>
          </a-tooltip>
        </template>
      </a-table>
    </a-tab-pane>
    </a-tabs>
    </a-spin>
    <template slot="footer">
      <a-button
        :style="{marginRight: '8px'}"
        @click="handleCancel"
      >
        å…³é—­
      </a-button>
<!--      <a-button
        v-if="!this.model.id"
        :disabled="disableSubmit || confirmLoading"
        :loading="confirmLoading"
        @click="handleOkAndAdd"
        type="primary"
      >保存并继续新增</a-button>-->
      <a-button
        :disabled="disableSubmit || confirmLoading"
        :loading="confirmLoading"
        @click="handleOk"
        type="primary"
      >确定</a-button>
      <!-- icon="save" -->
    </template>
  </a-modal>
</template>
<script>
import pick from 'lodash.pick'
import { postAction, requestPut } from '@/api/manage'
import { duplicateCheck } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
export default {
  name: 'EquipmentCategoryModel',
  mixins:[JeecgListMixin],
  props:{
    mainId:{
        type:String,
        default:'',
        required:false
    },
  },
  data() {
    return {
      title: "操作",
      visible: false,
      codeDisable: true,
      disableSubmit: false,
      parentId: '',
      model: {},
      labelCol: {
        span:7
      },
      wrapperCol: {
        span:17
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        num: {
          rules: [
            { required: true, message: '请输入设备分类编号!' },
            { min: 2, max: 30, message: '长度在 2 åˆ° 30 ä¸ªå­—符', trigger: 'blur' },
            { validator: this.validateNum },
          ]
        },
        name: {
          rules: [
            { required: true, message: '请输入设备分类名称!' },
            { min: 2, max: 30, message: '长度在 2 åˆ° 30 ä¸ªå­—符', trigger: 'blur' },
            { validator: this.validateName },
          ]
        },
        equipmentCategoryUda1:{
          rules: [
            { required: true, message: '请选择类别标识!' },
          ]
        },
        remark: {
          rules: [
            { min: 0, max: 100, message: '长度不超过 100 ä¸ªå­—符', trigger: 'blur' },
          ]
        },
        equipmentCategoryUda2:{
          rules: [
            { required: true, message: '请选择技术状态鉴定周期!' },
          ]
        }
      },
      url: {
        add: "/eam/equipmentCategory/add",
        edit: "/eam/equipmentCategory/edit",
        list:"/eam/equipmentCategory/getAllChildren"
      },
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          width: 50,
        },
      /*   {
          title: '上级设备分类编码',
          align: "center",
          dataIndex: 'parentNum',
          customRender:function(text, record){
              return record.parentName+text;
            }
          },
        {
          title: '上级设备分类名称',
          align: "center",
          dataIndex: 'parentName',
        }, */
        {
          title: '分类编码',
          align: "center",
          dataIndex: 'num',
          scopedSlots: { customRender: 'num' },
          width: 100,
          ellipsis: true,
          // scopedSlots: {
          //   customRender: 'num',
          // },
          // sorter: true,
        },
        {
          title: '分类名称',
          align: "center",
          dataIndex: 'name',
          // scopedSlots: {
          //   customRender: 'name',
          // },
          // sorter: true,
        },
        {
          title: '分类标识',
          align: "center",
          dataIndex: 'equipmentCategoryUda1_dictText',
          // scopedSlots: {
          //   customRender: 'name',
          // },
          // sorter: true,
        },
        {
          title: '创建人',
          align: "center",
          dataIndex: 'createBy',
        },
        {
          title: '修改人',
          align: "center",
          dataIndex: 'updateBy',
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
        },
        {
          title: '修改时间',
          align: "center",
          dataIndex: 'updateTime',
        },
      ],
      //新增、编辑、删除、批量删除操作改变数据后刷新关联的组件的监听属性
      alterFlag: ""
    }
  },
  created() {
  },
  methods: {
    add(record) {
      this.edit(record);
    },
    edit(record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
      this.disableSubmit = false;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, 'parentNum','equipmentCategoryUda1','equipmentCategoryUda2', 'parentName', 'num', 'name', 'remark'))
      });
      if (record.id) {
        this.codeDisable = true;
      } else {
        this.codeDisable = false;
      }
    },
    close() {
      this.$emit('close');
      this.visible = false;
      this.onClearSelected();
    },
    onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
    },
    onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
    },
    //保存并新增按钮触发
    handleOkAndAdd() {
      const that = this
      // è§¦å‘表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          formData.parentId = this.parentId
          postAction(this.url.add, formData).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
              that.alterFlag = new Date();
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            this.confirmLoading = false
            this.form.setFieldsValue(pick(this.model, 'parentNum', 'parentName'))
            this.form.setFieldsValue({ "num": null, "name": null, "remark": null })
          })
        } else {
          return false
        }
      })
    },
    handleOk() {
      const that = this;
      // è§¦å‘表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let formData = Object.assign(this.model, values);
          let obj;
          if (!this.model.id) {
            formData.parentId = this.parentId
            obj = postAction(this.url.add, formData);
          } else {
            formData.equipmentCategoryDtlList = this.selectionRows;
            obj = requestPut(this.url.edit, formData, { id: this.model.id });
          }
          obj.then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
              that.alterFlag = new Date();
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.$bus.$emit('loadData')
            that.close();
            that.onClearSelected();
          })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    //验证 ç¼–号
    validateNum(rule, value, callback) {
      var params = {
        tableName: 'mom_eam_equipment_category',
        fieldName: 'num',
        fieldVal: value,
        dataId: this.model.id,
        //数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false å‡åˆ é™¤ï¼štrue
        delFlag: 'true',
      };
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback();
        } else {
          callback("编号已存在!");
        }
      })
    },
    //验证 åç§°
    validateName(rule, value, callback) {
      var params = {
        tableName: 'mom_eam_equipment_category',
        fieldName: 'name',
        fieldVal: value,
        dataId: this.model.id,
        //数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false å‡åˆ é™¤ï¼štrue
        delFlag: 'true',
      };
      duplicateCheck(params).then((res) => {
        if (res.success) {
          callback();
        } else {
          callback("名称已存在!");
        }
      })
    },
    clearList(){
        this.dataSource=[]
        this.selectedRowKeys=[]
        this.ipagination.current = 1
    }
  },
  watch: {
    alterFlag() {
      this.$bus.$emit('queryTreeData');
    },
    mainId:{
       immediate:true,
       handler(val) {
          if(!this.mainId){
            this.clearList()
          }else{
            this.queryParam['parentId'] = val
            this.loadData(1);
          }
        }
     },
  }
}
</script>
<style scoped>
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}
.ant-form-item-control {
  line-height: 0px;
}
/** ä¸»è¡¨å•行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}
/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>