动态添加表格

image.png

<template>
<div>
<el-row style="margin-top: 20px">
<el-col :span="24" style="border-left: 5px solid #1d6ced;margin-bottom: 10px">
<label style="margin-left: 10px">追加审批</label>
</el-col>
<el-table :data="tableData" style="width: 100%" border>
<el-table-column prop="bizSceneId" label="场景">
<template slot-scope="scope">
<el-select v-model="scope.row.bizSceneId" clearable placeholder="请选择">
<el-option
v-for="dict in approvalScenes"
:key="dict.dictValue"
:value="dict.dictValue"
:label="dict.dictLabel"
></el-option>
</el-select>
</template>
</el-table-column>

    <el-table-column prop="price" label="超越价格的审批" align="center">
      <template slot-scope="scope" v-if="scope.row.bizSceneId == '2'">
        <el-input v-model="scope.row.price" style="width:100px"></el-input>元
      </template>
    </el-table-column>

    <el-table-column prop="empId" label="追加审批人">
      <template slot-scope="scope">
        <el-select
          v-model="scope.row.empId"
          placeholder="请选择负责人"
          filterable
          clearable
          style="width: 100%"
        >
          <el-option
            v-for="item in leaderOptions"
            :key="item.empId"
            :label="item.name"
            :value="item.empId"
          ></el-option>
        </el-select>
      </template>
    </el-table-column>

    <el-table-column prop="addtoLevel" label="追加审批级别">
      <template slot-scope="scope">
        <el-radio-group v-model="scope.row.addtoLevel" align="left">
          <el-radio label="1">原审批流程第一级之前</el-radio>
          <el-radio label="2">原审批流程最后一级之前</el-radio>
          <el-radio label="3">原审批流程最后一级之后</el-radio>
        </el-radio-group>
      </template>
    </el-table-column>

    <el-table-column prop="applyScope" label="适用范围">
      <template slot-scope="scope">
        <el-radio-group v-model="scope.row.applyScope" align="left">
          <el-radio
            label="1"
            @click.native="clickRadio($event, 1,scope.row.depts,scope.row)"
          >全公司</el-radio>
          <el-radio
            label="2"
            @click.native="clickRadio($event, 2,scope.row.depts,scope.row)"
          >指定分公司及所属部门</el-radio>
        </el-radio-group>
      </template>
    </el-table-column>
    <el-table-column label="操作" align="center">
      <template slot-scope="scope">
        <el-button
          @click="addLine"
          type="primary"
          v-if="scope.$index == tableData.length - 1"
          v-hasPermi="['crm:approveRuleAddto:add']"
        >添加</el-button>

        <el-button
          type="danger"
          v-if="tableData.length > 1"
          @click="handleDelete(scope.$index, scope.row)"
          class="del-btn"
          v-hasPermi="['crm:approveRuleAddto:remove']"
        >删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</el-row>
<el-row style="margin-top: 20px">
  <el-col :span="6" :offset="12">
    <el-button type="primary" @click="saveData" v-hasPermi="['crm:approveRuleAddto:edit']">保 存</el-button>
  </el-col>
</el-row>
<!-- 添加或修改员工基本信息对话框 -->
<el-dialog title="指定分公司及所属部门" :before-close="handleClose" :visible.sync="deptOpen" width="650px">
  <div>
    <el-row>
      <el-col :span="24">
        <treeselect
          v-model="rowSelect"
          :options="empDeptOptions"
          :normalizer="normalizer"
          placeholder="选择部门"
          :multiple="true"
        />
      </el-col>
    </el-row>
  </div>

  <div slot="footer" class="dialog-footer">
    <el-button type="primary" @click="saveTree">确 定</el-button>
    <el-button @click="deptOpen=false">取 消</el-button>
  </div>
</el-dialog>

</div>
</template>
<style lang="scss" scoped="scoped">
.treeSelect {
/deep/ .el-form-item__content {
margin-top: 1px;
height: 32px;
line-height: 30px;
}
}
</style>
<script>
import {
listApproveRuleAddto,
addApproveRuleAddto
} from "@/api/crm/approveRuleAddto";
import { listEmp } from "@/api/crm/dept";
import {
listEmployee,
getEmployee,
delEmployee,
addEmployee,
updateEmployee,
exportEmployee,
listDept,
editStatus,
editUseStatus,
delCert,
getStation
} from "@/api/crm/employee";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
name: "ApproveRule",
props: ["cId"],
components: { Treeselect },
data() {
return {
// 是否显示弹出层
open: false,
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 总条数
total: 0,
// 产品设置-审批规则表格数据
approveRuleList: [],
// 产品设置-审批规则表格数据
approveEnableds: [],
// 弹出层标题
title: "",
// 是否显示弹出层
deptOpen: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
comId: undefined,
bizSceneId: undefined,
bizSceneId: undefined,
isForce: undefined
},
// 表单参数
form: {
listData: []
},
// 表单参数
formAdd: {},
// 表单校验
rules: {},
tableData: [
{
bizSceneId: "",
price: "",
empId: "",
addtoLevel: "",
applyScope: ""
}
],
approvalScenes: [],
leaderOptions: [],
//部门
empDeptOptions: [],
rowSelect: [],
rowData: {},
comId: "",
param: {
pageNum: 1,
pageSize: 999,
comId: undefined
}
};
},
created() {
this.comId = this.props.cId; this.param.comId = this.props.cId;
this.getList();
//获取审批开关字典
this.getDicts("approve_flow_enabled").then(response => {
this.approveEnableds = response.data;
});
// 获取审批场景字典;
this.getDicts("approval_scene").then(response => {
this.approvalScenes = response.data;
});
// 获取员工
this.getEmployeeSelect();
// 获取部门
this.getEmpDeptSelect();
},
methods: {
/查询员工列表/
getEmployeeSelect() {
// let param = {
// pageNum:1,
// pageSize:999,
// comId:this.comId
// };
listEmployee(this.param).then(response => {
this.leaderOptions = response.rows;
});
},
/查询部门/
getEmpDeptSelect() {
// let param = {
// pageNum:1,
// pageSize:999,
// comId:this.comId
// };
listDept(this.param).then(response => {
this.empDeptOptions = this.handleTree(response.data, "deptId");
});
},
//审批开关码表转化
setApprovalSceneFormatter(row, column) {
return this.selectDictLabel(this.approvalScenes, row.type);
},
/** 查询产品设置-审批规则列表 /
getList() {
this.loading = true;
this.queryParams.comId = this.comId;
listApproveRuleAddto(this.queryParams).then(response => {
this.tableData = response.rows;
for (let i = 0; i < this.tableData.length; i++) {
this.tableData[i].addtoLevel = this.tableData[
i
].addtoLevel.toString();
this.tableData[i].applyScope = this.tableData[
i
].applyScope.toString();
this.tableData[i].empId = Number(this.tableData[i].empId);
}
if (this.tableData.length == 0) {
//添加行数
var newValue = {
bizSceneId: "",
price: "",
empId: "",
addtoLevel: "1",
applyScope: "1"
};
//添加新的行数
this.tableData.push(newValue);
}
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
id: undefined,
comId: undefined,
bizSceneId: undefined,
bizSceneId: undefined,
isForce: undefined,
crmApproveRules: [],
crmApproveRuleAlert: [],
createTime: undefined,
updateTime: undefined,
createBy: undefined,
updateBy: undefined
};
this.approveRuleAddtoList = this.approveRuleAddtoList;
this.resetForm("form");
},
/
* 搜索按钮操作 /
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/
* 重置按钮操作 /
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id);
this.single = selection.length != 1;
this.multiple = !selection.length;
},
/
* 新增按钮操作 /
handleAdd() {
this.reset();
this.open = true;
this.title = "添加产品设置-审批规则";
},
/
* 修改按钮操作 /
handleUpdate(row) {
this.reset();
const id = row.id || this.ids;
getApproveRule(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改产品设置-审批规则";
});
},
/
* 提交按钮 /
submitForm: function() {
this.refs["form"].validate(valid => { if (valid) { this.form.crmApproveRules = this.crmApproveRules; this.form.crmApproveRuleAlert = this.crmApproveRuleAlert; if (this.form.id != undefined) { addApproveRuleInfo(this.form).then(response => { if (response.code === 200) { this.msgSuccess("修改成功"); this.open = false; this.getList(); } else { this.msgError(response.msg); } }); } else { addApproveRuleInfo(this.form).then(response => { if (response.code === 200) { this.msgSuccess("新增成功"); this.open = false; this.getList(); } else { this.msgError(response.msg); } }); } } }); }, /** 提交按钮 */ submitFormAdd: function() { this.refs["approveRuleAddtoList"].validate(valid => {
if (valid) {
if (this.approveRuleAddtoList.id != undefined) {
addApproveRuleInfo(this.approveRuleAddtoList).then(response => {
if (response.code === 200) {
this.msgSuccess("修改成功");
// this.getList();
} else {
this.msgError(response.msg);
}
});
} else {
addApproveRuleInfo(this.approveRuleAddtoList).then(response => {
if (response.code === 200) {
this.msgSuccess("新增成功");
// this.getList();
} else {
this.msgError(response.msg);
}
});
}
}
});
},
/
* 删除按钮操作 /
handleDelete(row) {
const ids = row.id || this.ids;
this.confirm("是否确认删除此数据?", "警告", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" }) .then(function() { return delApproveRule(ids); }) .then(() => { this.getList(); this.msgSuccess("删除成功"); }) .catch(function() {}); }, /** 导出按钮操作 */ handleExport() { const queryParams = this.queryParams; this.confirm("是否确认导出所有产品设置-审批规则数据项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
})
.then(function() {
return exportApproveRule(queryParams);
})
.then(response => {
this.download(response.msg);
})
.catch(function() {});
},
/
* 追加一行 /
addJurisdiction(row, index) {
this.approveRuleAddtoList.push(this.formAdd);
},
/
* 删除一行 */
delJurisdiction(row, index) {
this.approveRuleAddtoList.splice(index, 1);
},
addLine() {
//添加行数
var newValue = {
bizSceneId: "1",
price: "",
empId: "",
addtoLevel: "1",
applyScope: "1"
};
//添加新的行数
this.tableData.push(newValue);
},
handleDelete(index) {
//删除行数
this.tableData.splice(index, 1);
},
handleClose(){

},
// 保存数据
saveData() {
  this.form.listData = this.tableData;
  this.form.comId = this.comId;
  addApproveRuleAddto(this.form).then(response => {
    if (response.code === 200) {
      this.msgSuccess("新增成功");
      this.open = false;
      this.getList();
    } else {
      this.msgError(response.msg);
    }
  });
},
/** 转换部门数据结构 */
normalizer(node) {
  if (node.children && !node.children.length) {
    delete node.children;
  }
  return {
    id: node.deptId,
    label: node.deptName,
    children: node.children
  };
},
// 打开弹出框
clickRadio(e, index, val, row) {
  //
  this.rowSelect = [];
  this.rowData = row;
  if (index == "2") {
    if (undefined != val && "" != val) {
      var arr = val.split(",");
      for (let i = 0; i < arr.length; i++) {
        this.rowSelect.push(Number(arr[i]));
      }
    }
    this.deptOpen = true;
  }
},
// saveTree
saveTree() {
  var _this = this;
  var rowData = _this.rowData;
  var treeData = _this.rowSelect;
  for (let i = 0; i < _this.tableData.length; i++) {
    if (_this.tableData[i].id == rowData.id) {
      let str = "";
      for (let k = 0; k < treeData.length; k++) {
        str += treeData[k] + ",";
      }
      // _this.tableData[i].depts = treeData;
      // str.substring(0,str.length-1);
      str = str.substring(0, str.length - 1);
      _this.tableData[i].depts = str;
    }
  }
  this.deptOpen = false;
}

}
};
</script>

<style lang="scss" scoped>
.el-row {
margin-bottom: 15px;
.requiredIcon {
color: red;
}
}
</style>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,463评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,868评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,213评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,666评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,759评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,725评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,716评论 3 415
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,484评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,928评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,233评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,393评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,073评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,718评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,308评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,538评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,338评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,260评论 2 352