表单的增删改查

111 阅读1分钟
  <el-button type="primary" @click="handleQuery">搜索</el-button> 
  <el-input
          v-model="queryParams.eventName"
          placeholder="请输入事件名称"
          clearable
          style="width: 240px"
          @keyup.enter="handleQuery"
        />
        
        
            <el-button type="text" @click="showOther">高级查询</el-button>
             function showOther() {
          isShowOther.value = !isShowOther.value;
        }

image.png

image.png

 function handleUpdate(row) {
      reset();
      if (row) {
      //深拷贝 修改的时候页面不联动
        form.value = {...row};
        //这个是修改 deviceNat是选择下拉框是汉字 后端要数字 需要转
        if(form.value.deviceNat=="是"){
          form.value.deviceNat = 1
        }else if(form.value.deviceNat=="否"){
          form.value.deviceNat = 2
        }else{
          form.value.deviceNat = null
        }
        form.value.linkUser = { userId: Number(row.linkUserId) };
        open.value = true;
        title.value = "修改资产";
      } else {
        const assetId = ids.value[0];
        getAsset(assetId).then((response) => {
          form.value = response.data;
          form.value.linkUser = { userId: Number(response.data.linkUserId) };
          open.value = true;
          title.value = "修改资产";
        });
      }
    }

    /** 提交按钮 */
    function submitForm() {
      proxy.$refs["formRef"].validate((valid) => {
        if (valid) {
          if (form.value.linkUser && JSON.stringify(form.value.linkUSer) !== "{}") {
            form.value.linkUserId = form.value.linkUser.userId;
            form.value.linkUserName = form.value.linkUser.userName;
          }
          if (form.value.id != undefined) {
             //
        if(form.value.deviceAttributes=="台式设备"){
            form.value.deviceAttributes = 1
          }else if(form.value.deviceAttributes=="WIFI设备"){
            form.value.deviceAttributes = 2
          }else if(form.value.deviceAttributes=="移动设备"){
            form.value.deviceAttributes = 3
          }else if(form.value.deviceAttributes=="其他设备"){
            form.value.deviceAttributes = 4
          }
            updateAsset(form.value).then((response) => {
              proxy.$modal.msgSuccess("修改成功");
              open.value = false;
              getList();
            });
          } else {
            addAsset(form.value).then((response) => {
              proxy.$modal.msgSuccess("新增成功");
              open.value = false;
              getList();
            });
          }
        }
      });
    }
    
    
    /** 添加 */
    function handleAdd() {
      reset();
      open.value = true;
      title.value = "XXX";
    }
    
     /** 删除按钮操作 */
    function handleDelete(row) {
    //删除的字段和后端对 我这个是id  我之前是其他的 就不能 
      const selectIds = row.id || ids.value;
      proxy.$modal
        .confirm('是否确认删除编号为"' + selectIds + '"的数据项?')
        .then(function () {
        //delAsset这个是删除的接口
          return delAsset(selectIds);
        })
        .then(() => {
          getList();
          proxy.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    }