earlyWarning.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <div class="m-container">
  3. <h2>课酬预警设置</h2>
  4. <div class="m-core">
  5. <!-- 搜索标题 -->
  6. <save-form
  7. :inline="true"
  8. ref="searchForm"
  9. class="searchForm"
  10. :model.sync="searchForm"
  11. >
  12. <el-form-item prop="organId">
  13. <el-select
  14. v-model.trim="searchForm.organId"
  15. placeholder="请选择分部"
  16. clearable
  17. filterable
  18. size="mini"
  19. >
  20. <el-option
  21. v-for="item in selects.branchs"
  22. :key="item.id"
  23. :value="item.id"
  24. :label="item.name"
  25. >
  26. </el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button @click="search" type="danger" size="mini">搜索</el-button>
  31. </el-form-item>
  32. </save-form>
  33. <auth auths="sysConfig/update/insert" style="margin-bottom: 20px">
  34. <el-button
  35. size="mini"
  36. icon="el-icon-plus"
  37. type="primary"
  38. @click="openTypes('create')"
  39. >添加</el-button
  40. >
  41. </auth>
  42. <!-- 列表 -->
  43. <div class="tableWrap">
  44. <el-table
  45. :data="tableList"
  46. size="mini"
  47. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  48. >
  49. <el-table-column align="center" prop="branchName" label="分部">
  50. </el-table-column>
  51. <el-table-column align="center" prop="money" label="预警课酬">
  52. <template slot-scope="scope">
  53. {{ scope.row.money | moneyFormat }}元
  54. </template>
  55. </el-table-column>
  56. <!-- <el-table-column align='center'
  57. prop="name"
  58. label="修改日期">
  59. </el-table-column> -->
  60. <el-table-column align="center" label="操作">
  61. <template slot-scope="scope">
  62. <auth auths="sysConfig/update/update">
  63. <el-button @click="openTypes('update', scope.row)" type="text"
  64. >修改</el-button
  65. >
  66. </auth>
  67. <auth auths="sysConfig/update/del">
  68. <el-button @click="onTypesDel(scope.row)" type="text"
  69. >删除</el-button
  70. >
  71. </auth>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. </div>
  76. </div>
  77. <el-dialog
  78. :title="formTitle[formActionTitle]"
  79. :visible.sync="typeStatus"
  80. @close="onFormClose('ruleForm')"
  81. width="600px"
  82. >
  83. <el-form :model="form" :rules="rules" ref="ruleForm">
  84. <el-form-item
  85. label="预警课酬(元)"
  86. prop="money"
  87. :label-width="formLabelWidth"
  88. >
  89. <!-- <el-input-number v-model="form.money" controls-position="right" style="width: 100%;" :precision='2' :min="1" :max="10"></el-input-number> -->
  90. <el-input
  91. v-model.trim="form.money"
  92. type="number"
  93. @input="checkNumber(form.money)"
  94. placeholder="请输入预警课酬"
  95. autocomplete="off"
  96. ></el-input>
  97. </el-form-item>
  98. <el-form-item
  99. label="适用分部"
  100. prop="branchId"
  101. :label-width="formLabelWidth"
  102. >
  103. <el-select
  104. v-model="form.branchId"
  105. clearable
  106. filterable
  107. placeholder="请选择适用分部"
  108. >
  109. <el-option
  110. v-for="item in selects.branchs"
  111. :value="item.id"
  112. :label="item.name"
  113. :key="item.id"
  114. ></el-option>
  115. </el-select>
  116. </el-form-item>
  117. </el-form>
  118. <span slot="footer" class="dialog-footer">
  119. <el-button @click="typeStatus = false">取 消</el-button>
  120. <el-button type="primary" @click="onTypesSubmit('ruleForm')"
  121. >确 定</el-button
  122. >
  123. </span>
  124. </el-dialog>
  125. </div>
  126. </template>
  127. <script>
  128. import { sysConfigUpdate, queryByParamName } from "@/api/generalSettings";
  129. export default {
  130. name: "earlyWarning",
  131. data() {
  132. return {
  133. searchForm: {
  134. organId: null,
  135. },
  136. tableList: [],
  137. tempTableList: [],
  138. formActionTitle: "create",
  139. formTitle: {
  140. create: "添加预警课酬设置",
  141. update: "修改预警课酬设置",
  142. },
  143. typeStatus: false,
  144. formLabelWidth: "120px",
  145. form: {
  146. id: null,
  147. money: null,
  148. branchId: null,
  149. },
  150. formRow: null,
  151. rules: {
  152. money: [{ required: true, message: "请输入预警课酬", trigger: "blur" }],
  153. branchId: [
  154. { required: true, message: "请选择适用分部", trigger: "blur" },
  155. ],
  156. },
  157. };
  158. },
  159. async mounted() {
  160. await this.$store.dispatch("setBranchs");
  161. this.getList();
  162. },
  163. methods: {
  164. //方法一:
  165. checkNumber(withdrawAmount) {
  166. this.form.money = withdrawAmount.match(/^\d*(\.?\d{0,2})/g)[0] || null;
  167. },
  168. onTypesSubmit(formName) {
  169. // 添加数据
  170. this.$refs[formName].validate(async (valid) => {
  171. if (valid) {
  172. const form = this.form;
  173. let status = false;
  174. let statusName = null;
  175. let object = {};
  176. this.tempTableList.forEach((branch) => {
  177. if (this.formActionTitle == "update") {
  178. if (
  179. branch.branchId == form.branchId &&
  180. this.formRow.branchId != form.branchId
  181. ) {
  182. status = true;
  183. statusName = branch.branchName;
  184. }
  185. } else {
  186. if (branch.branchId == form.branchId) {
  187. status = true;
  188. statusName = branch.branchName;
  189. }
  190. }
  191. object[branch.branchId] = branch.money;
  192. });
  193. if (status) {
  194. this.$message.error(`[${statusName}]分部已设置预警课酬`);
  195. return;
  196. }
  197. object[form.branchId] = form.money;
  198. let params = {
  199. id: form.id,
  200. paranValue: JSON.stringify(object),
  201. paramName: "warning_min_course_salary",
  202. };
  203. await sysConfigUpdate(params).then((res) => {
  204. let title = this.formActionTitle == "create" ? "添加" : "修改";
  205. this.messageTips(title, res);
  206. });
  207. } else {
  208. return false;
  209. }
  210. });
  211. },
  212. search() {
  213. // this.getList()
  214. let organId = this.searchForm.organId;
  215. let tempList = [];
  216. this.tempTableList.forEach((item) => {
  217. if (item.branchId == organId || !organId) {
  218. tempList.push(item);
  219. }
  220. });
  221. this.tableList = tempList;
  222. },
  223. async onTypesDel(row) {
  224. let object = {};
  225. this.tempTableList.forEach((item) => {
  226. if (row.branchId != item.branchId) {
  227. object[item.branchId] = item.money;
  228. }
  229. });
  230. let params = {
  231. id: this.form.id,
  232. paranValue: JSON.stringify(object),
  233. paramName: "warning_min_course_salary",
  234. };
  235. this.$confirm("是否删除预警课酬", "提示", {
  236. confirmButtonText: "确定",
  237. cancelButtonText: "取消",
  238. type: "warning",
  239. })
  240. .then(async () => {
  241. await sysConfigUpdate(params).then((res) => {
  242. this.messageTips("删除", res);
  243. });
  244. })
  245. .catch(() => {});
  246. },
  247. async messageTips(title, res) {
  248. if (res.code == 200) {
  249. this.$message.success(title + "成功");
  250. this.typeStatus = false;
  251. await this.getList();
  252. await this.search();
  253. } else {
  254. this.$message.error(res.msg);
  255. }
  256. },
  257. async getList() {
  258. await queryByParamName({
  259. paramName: "warning_min_course_salary",
  260. }).then((res) => {
  261. let result = res.data;
  262. if (res.code == 200) {
  263. const paranValue = result.paranValue
  264. ? JSON.parse(result.paranValue)
  265. : {};
  266. this.form.id = result.id;
  267. const branchs = this.selects.branchs;
  268. const tempValue = [];
  269. for (let i in paranValue) {
  270. let branchName = [];
  271. branchs.forEach((branch) => {
  272. if (i == branch.id) {
  273. branchName = branch.name;
  274. tempValue.push({
  275. branchId: i,
  276. branchName: branchName,
  277. money: paranValue[i],
  278. });
  279. }
  280. });
  281. }
  282. this.tableList = tempValue;
  283. this.tempTableList = tempValue;
  284. }
  285. });
  286. },
  287. openTypes(type, row) {
  288. this.typeStatus = true;
  289. this.formActionTitle = type;
  290. // 修改的时候赋值
  291. if (type == "update") {
  292. this.formRow = row;
  293. this.$nextTick(() => {
  294. (this.form.money = row.money),
  295. (this.form.branchId = parseInt(row.branchId));
  296. });
  297. }
  298. },
  299. onFormClose(formName) {
  300. // 关闭弹窗重置验证
  301. this.$refs[formName].resetFields();
  302. },
  303. },
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. .el-button--primary {
  308. background: #14928a;
  309. border-color: #14928a;
  310. color: #fff;
  311. &:hover,
  312. &:active,
  313. &:focus {
  314. background: #14928a;
  315. border-color: #14928a;
  316. color: #fff;
  317. }
  318. }
  319. /deep/.el-date-editor.el-input {
  320. width: 100% !important;
  321. }
  322. /deep/.el-select {
  323. width: 100% !important;
  324. }
  325. </style>