動(dòng)態(tài)添加表格

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="超越價(jià)格的審批" 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="請選擇負(fù)責(zé)人"
          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,
// 選中數(shù)組
ids: [],
// 非單個(gè)禁用
single: true,
// 非多個(gè)禁用
multiple: true,
// 總條數(shù)
total: 0,
// 產(chǎn)品設(shè)置-審批規(guī)則表格數(shù)據(jù)
approveRuleList: [],
// 產(chǎn)品設(shè)置-審批規(guī)則表格數(shù)據(jù)
approveEnableds: [],
// 彈出層標(biāo)題
title: "",
// 是否顯示彈出層
deptOpen: false,
// 查詢參數(shù)
queryParams: {
pageNum: 1,
pageSize: 10,
comId: undefined,
bizSceneId: undefined,
bizSceneId: undefined,
isForce: undefined
},
// 表單參數(shù)
form: {
listData: []
},
// 表單參數(shù)
formAdd: {},
// 表單校驗(yàn)
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();
//獲取審批開關(guān)字典
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");
});
},
//審批開關(guān)碼表轉(zhuǎn)化
setApprovalSceneFormatter(row, column) {
return this.selectDictLabel(this.approvalScenes, row.type);
},
/** 查詢產(chǎn)品設(shè)置-審批規(guī)則列表 /
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) {
//添加行數(shù)
var newValue = {
bizSceneId: "",
price: "",
empId: "",
addtoLevel: "1",
applyScope: "1"
};
//添加新的行數(shù)
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();
},
// 多選框選中數(shù)據(jù)
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 = "添加產(chǎn)品設(shè)置-審批規(guī)則";
},
/
* 修改按鈕操作 /
handleUpdate(row) {
this.reset();
const id = row.id || this.ids;
getApproveRule(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改產(chǎn)品設(shè)置-審批規(guī)則";
});
},
/
* 提交按鈕 /
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("是否確認(rèn)刪除此數(shù)據(jù)?", "警告", { confirmButtonText: "確定", cancelButtonText: "取消", type: "warning" }) .then(function() { return delApproveRule(ids); }) .then(() => { this.getList(); this.msgSuccess("刪除成功"); }) .catch(function() {}); }, /** 導(dǎo)出按鈕操作 */ handleExport() { const queryParams = this.queryParams; this.confirm("是否確認(rèn)導(dǎo)出所有產(chǎn)品設(shè)置-審批規(guī)則數(shù)據(jù)項(xiàng)?", "警告", {
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() {
//添加行數(shù)
var newValue = {
bizSceneId: "1",
price: "",
empId: "",
addtoLevel: "1",
applyScope: "1"
};
//添加新的行數(shù)
this.tableData.push(newValue);
},
handleDelete(index) {
//刪除行數(shù)
this.tableData.splice(index, 1);
},
handleClose(){

},
// 保存數(shù)據(jù)
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);
    }
  });
},
/** 轉(zhuǎn)換部門數(shù)據(jù)結(jié)構(gòu) */
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>

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市氓癌,隨后出現(xiàn)的幾起案子才顿,更是在濱河造成了極大的恐慌尾组,老刑警劉巖奏属,帶你破解...
    沈念sama閱讀 211,290評論 6 491
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡椭盏,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,107評論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來今野,“玉大人蒲凶,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 156,872評論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長步清。 經(jīng)常有香客問我,道長藻雌,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,415評論 1 283
  • 正文 為了忘掉前任居暖,我火速辦了婚禮最住,結(jié)果婚禮上轧拄,老公的妹妹穿的比我還像新娘讽膏。我一直安慰自己烹卒,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,453評論 6 385
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著泥从,像睡著了一般和敬。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,784評論 1 290
  • 那天切厘,我揣著相機(jī)與錄音遗座,去河邊找鬼舀凛。 笑死,一個(gè)胖子當(dāng)著我的面吹牛途蒋,可吹牛的內(nèi)容都是我干的腾降。 我是一名探鬼主播,決...
    沈念sama閱讀 38,927評論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼碎绎,長吁一口氣:“原來是場噩夢啊……” “哼螃壤!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起筋帖,我...
    開封第一講書人閱讀 37,691評論 0 266
  • 序言:老撾萬榮一對情侶失蹤奸晴,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后日麸,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體寄啼,經(jīng)...
    沈念sama閱讀 44,137評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡逮光,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,472評論 2 326
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了墩划。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片涕刚。...
    茶點(diǎn)故事閱讀 38,622評論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖乙帮,靈堂內(nèi)的尸體忽然破棺而出杜漠,到底是詐尸還是另有隱情,我是刑警寧澤察净,帶...
    沈念sama閱讀 34,289評論 4 329
  • 正文 年R本政府宣布驾茴,位于F島的核電站,受9級特大地震影響氢卡,放射性物質(zhì)發(fā)生泄漏锈至。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,887評論 3 312
  • 文/蒙蒙 一译秦、第九天 我趴在偏房一處隱蔽的房頂上張望峡捡。 院中可真熱鬧,春花似錦筑悴、人聲如沸们拙。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,741評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽睛竣。三九已至,卻和暖如春求摇,著一層夾襖步出監(jiān)牢的瞬間射沟,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,977評論 1 265
  • 我被黑心中介騙來泰國打工与境, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留验夯,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,316評論 2 360
  • 正文 我出身青樓摔刁,卻偏偏與公主長得像挥转,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子共屈,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,490評論 2 348