dislogSet.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <template>
  2. <div>
  3. <BaseDialog
  4. width="1400px"
  5. :isShow.sync="isShow"
  6. :title="title"
  7. @close="close"
  8. @submit="submitForm"
  9. >
  10. <div class="bop-tip">
  11. <div><i class="el-icon-warning-outline"></i>说明</div>
  12. <div>
  13. 如果提成方式是按阶梯价计算,则需设置阶梯价格区间(最高价无穷大,则填写
  14. “ * ” )。如果无需按阶梯价计算提成,留空即可。
  15. </div>
  16. </div>
  17. <el-form
  18. inline
  19. hide-required-asterisk
  20. :model="form"
  21. :rules="rules"
  22. ref="form"
  23. >
  24. <div>
  25. <el-form-item prop="tpName" label="模板名称:" label-width="100px">
  26. <el-input
  27. placeholder="请输入模板名称"
  28. v-model="form.tpName"
  29. ></el-input>
  30. </el-form-item>
  31. <el-form-item prop="tenantId" label="">
  32. <el-select v-model="form.tenantId" placeholder="请选择关联机构">
  33. <el-option
  34. v-for="item in companyList"
  35. :key="item.tenantId"
  36. :label="item.tenantName"
  37. :value="item.tenantId"
  38. ></el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="">
  42. <el-checkbox
  43. :true-label="1"
  44. :false-label="0"
  45. v-model="form.defaultStatus"
  46. >默认</el-checkbox
  47. >
  48. </el-form-item>
  49. </div>
  50. <div v-for="(item, index) in form.itemList" :key="index">
  51. <el-form-item
  52. :prop="'itemList.' + index + '.itemName'"
  53. :label="index == 0 ? '成本设置:' : ' '"
  54. :rules="rules['itemName']"
  55. label-width="100px"
  56. >
  57. <el-input
  58. placeholder="请输入成本项名称"
  59. v-model="item.itemName"
  60. ></el-input>
  61. </el-form-item>
  62. <el-form-item
  63. label=""
  64. :prop="'itemList.' + index + '.itemCategory'"
  65. :rules="rules['itemCategory']"
  66. >
  67. <el-select v-model="item.itemCategory" placeholder="请选择成本类型">
  68. <el-option label="业务类型" :value="1"></el-option>
  69. <el-option label="非分成" :value="2"></el-option>
  70. </el-select>
  71. </el-form-item>
  72. <template v-if="item.itemCategory == 1">
  73. <el-form-item
  74. label=""
  75. :prop="'itemList.' + index + '.educationTypeId'"
  76. :rules="rules['educationTypeId']"
  77. >
  78. <el-select
  79. @change="changeEdu(item)"
  80. v-model="item.educationTypeId"
  81. placeholder="请选择教育类型"
  82. >
  83. <el-option
  84. v-for="item in eduList"
  85. :key="item.id"
  86. :label="
  87. item.schemeName +
  88. (item.schemeName ? '-' : '') +
  89. item.educationName
  90. "
  91. :value="item.id"
  92. >
  93. </el-option>
  94. </el-select>
  95. </el-form-item>
  96. <el-form-item
  97. label=""
  98. :prop="'itemList.' + index + '.businessId'"
  99. :rules="rules['businessId']"
  100. >
  101. <el-select v-model="item.businessId" placeholder="请选择业务层次">
  102. <el-option
  103. v-for="level in backbusinessList(item.educationTypeId)"
  104. :key="level.businessId"
  105. :label="level.aliasName"
  106. :value="level.businessId"
  107. @click.native="changeBus(item, level.projectId)"
  108. >
  109. </el-option>
  110. </el-select>
  111. </el-form-item>
  112. </template>
  113. <el-form-item
  114. label=""
  115. :prop="'itemList.' + index + '.itemType'"
  116. :rules="rules['itemType']"
  117. >
  118. <el-select v-model="item.itemType" placeholder="请选择成本类型">
  119. <el-option label="百分比成本" :value="1"></el-option>
  120. <el-option label="固定成本" :value="2"></el-option>
  121. </el-select>
  122. </el-form-item>
  123. <el-form-item
  124. label=""
  125. :prop="'itemList.' + index + '.minValue'"
  126. :rules="rules['minValue']"
  127. class="range"
  128. >
  129. <el-col :span="11">
  130. <el-input
  131. v-int
  132. placeholder="最低价"
  133. v-model.number="item.minValue"
  134. ></el-input>
  135. </el-col>
  136. <el-col class="line" :span="2" style="magrin: 10px">-</el-col>
  137. <el-col :span="11">
  138. <el-input
  139. v-int
  140. placeholder="最高价"
  141. @change="changeMaxValue('itemList.' + index + '.minValue')"
  142. v-model.number="item.maxValue"
  143. ></el-input>
  144. </el-col>
  145. </el-form-item>
  146. <!-- <el-form-item
  147. label=""
  148. :prop="'itemList.' + index + '.minValue'"
  149. :rules="rules['minValue']"
  150. class="range"
  151. >
  152. <el-input placeholder="最低价" v-model="item.minValue"></el-input>
  153. </el-form-item>
  154. <div class="line">-</div>
  155. <el-form-item
  156. label=""
  157. :prop="'itemList.' + index + '.maxValue'"
  158. :rules="rules['maxValue']"
  159. class="range"
  160. >
  161. <el-input placeholder="最高价" v-model="item.maxValue"></el-input>
  162. </el-form-item> -->
  163. <el-form-item
  164. v-if="item.itemType"
  165. class="ddd"
  166. label-width="0"
  167. :prop="'itemList.' + index + '.typeValue'"
  168. label=" "
  169. :rules="rules['typeValue']"
  170. >
  171. <el-input
  172. :placeholder="item.itemType == 1 ? '百分比成本' : '固定成本'"
  173. v-model="item.typeValue"
  174. v-int
  175. >
  176. <template slot="append">
  177. {{ item.itemType == 1 ? "%" : "元" }}
  178. </template>
  179. </el-input>
  180. </el-form-item>
  181. <el-form-item label-width="0" label=" ">
  182. <div class="btns">
  183. <!-- <el-button type="text">复制</el-button> -->
  184. <i @click="add(index, item)" class="el-icon-connection"></i>
  185. <i @click="add(index)" class="el-icon-circle-plus-outline"></i>
  186. <i
  187. v-if="index != 0"
  188. @click="del(index)"
  189. class="el-icon-remove-outline"
  190. ></i>
  191. </div>
  192. </el-form-item>
  193. </div>
  194. </el-form>
  195. </BaseDialog>
  196. </div>
  197. </template>
  198. <script>
  199. import { eduList, addCost, costDetail, editCost } from "@/api/financed/index";
  200. export default {
  201. name: "DislogSet",
  202. props: {
  203. dialogVisible: {
  204. type: Boolean,
  205. default: false,
  206. },
  207. // 0 新增 1修改 2复制
  208. type: {
  209. type: [String, Number],
  210. default: 0,
  211. },
  212. tpId: {
  213. type: [String, Number],
  214. default: "",
  215. },
  216. },
  217. data() {
  218. var checkMinValue = (rule, value, callback) => {
  219. const list = this.itemList[rule.field.split(".")[1]];
  220. const { maxValue, businessId } = list;
  221. if (maxValue || value) {
  222. if (!value) {
  223. callback(new Error("请输入最低价"));
  224. } else if (!maxValue) {
  225. callback(new Error("请输入最高价"));
  226. } else if (maxValue <= value) {
  227. callback(new Error("最低价不能小于最高价"));
  228. }
  229. }
  230. if (!businessId) {
  231. callback();
  232. }
  233. const levelList = this.itemList.filter(
  234. (e) => e.businessId == list.businessId
  235. );
  236. if (levelList.length > 1) {
  237. const isEmpty = levelList.some((e) => !e.minValue && !e.maxValue);
  238. if (isEmpty) {
  239. callback(new Error("同层级成本设置不是阶梯计价只能存在一个"));
  240. } else {
  241. this.isHaveIntersect(levelList) &&
  242. callback(new Error("阶梯计价存在范围冲突"));
  243. }
  244. }
  245. callback();
  246. };
  247. return {
  248. form: {},
  249. rules: {
  250. tpName: [
  251. { required: true, message: "请输入模板名称", trigger: "blur" },
  252. ],
  253. tenantId: [
  254. { required: true, message: "请选择关联机构", trigger: "change" },
  255. ],
  256. itemName: [
  257. { required: true, message: "请输入成本项名称", trigger: "blur" },
  258. ],
  259. businessId: [
  260. { required: true, message: "请选择业务层次", trigger: "blur" },
  261. ],
  262. educationTypeId: [
  263. { required: true, message: "请选择教育类型", trigger: "change" },
  264. ],
  265. itemCategory: [
  266. { required: true, message: "请选择业务类型", trigger: "change" },
  267. ],
  268. itemType: [
  269. { required: true, message: "请选择成本类型", trigger: "change" },
  270. ],
  271. typeValue: [
  272. { required: true, message: "请输入百分比成本", trigger: "blur" },
  273. ],
  274. minValue: [{ validator: checkMinValue, trigger: "blur" }],
  275. },
  276. companyList: [],
  277. eduList: [],
  278. };
  279. },
  280. methods: {
  281. init() {
  282. this.resetForm();
  283. this.tpId && this.getCostDetail();
  284. this.getCompanyList();
  285. this.getEduList();
  286. },
  287. getCostDetail() {
  288. costDetail(this.tpId).then((res) => {
  289. if (this.type == 2) delete this.form["tpId"];
  290. Object.keys(this.form).map((key) => {
  291. this.form[key] = res.data[key];
  292. });
  293. });
  294. },
  295. getEduList() {
  296. if (this.eduList.length) return;
  297. eduList({}).then((res) => {
  298. this.eduList = res.rows;
  299. });
  300. },
  301. backbusinessList(eduId) {
  302. if (!eduId || !this.eduList.length) return [];
  303. let data = this.eduList.find((e) => e.id == eduId);
  304. return data.businessList || [];
  305. },
  306. getCompanyList() {
  307. if (this.companyList.length) return;
  308. this.$api.systemtenantlist(this.formData).then((res) => {
  309. this.companyList = res.rows;
  310. });
  311. },
  312. changeEdu(data) {
  313. data.businessId = undefined;
  314. data.projectId = undefined;
  315. },
  316. changeBus(data, projectId) {
  317. data.projectId = projectId;
  318. },
  319. add(index, data) {
  320. data = data || {
  321. projectId: undefined,
  322. itemName: 456,
  323. itemCategory: 1,
  324. businessId: undefined,
  325. educationTypeId: 21,
  326. itemType: 1,
  327. typeValue: undefined,
  328. minValue: undefined,
  329. maxValue: undefined,
  330. };
  331. this.itemList.splice(index + 1, 0, data);
  332. },
  333. del(index) {
  334. this.itemList.splice(index, 1);
  335. },
  336. close() {
  337. this.$refs["form"].resetFields();
  338. },
  339. changeEduType() {},
  340. resetForm() {
  341. this.form = {
  342. itemList: [
  343. {
  344. projectId: undefined,
  345. itemName: 456,
  346. itemCategory: 1,
  347. businessId: 151,
  348. educationTypeId: 21,
  349. itemType: 1,
  350. typeValue: undefined,
  351. minValue: undefined,
  352. maxValue: undefined,
  353. },
  354. {
  355. projectId: undefined,
  356. itemName: 456,
  357. itemCategory: 1,
  358. businessId: 151,
  359. educationTypeId: 21,
  360. itemType: 1,
  361. typeValue: undefined,
  362. minValue: undefined,
  363. maxValue: undefined,
  364. },
  365. ],
  366. tpId: undefined,
  367. tpName: 123,
  368. defaultStatus: 0,
  369. tenantId: "1",
  370. };
  371. },
  372. cb() {
  373. this.$message.success(this.title + "成功");
  374. this.isShow = false;
  375. this.$emit("search");
  376. },
  377. submitForm() {
  378. this.$refs["form"].validate((valid) => {
  379. if (valid) {
  380. console.log(valid, 666);
  381. return;
  382. if (this.type !== 1) {
  383. addCost(this.form).then(this.cb);
  384. } else {
  385. editCost(this.form).then(this.cb);
  386. }
  387. } else {
  388. return false;
  389. }
  390. });
  391. },
  392. changeMaxValue(prop) {
  393. this.$refs.form.validateField(prop);
  394. },
  395. isHaveIntersect(list) {
  396. list = list.sort((a, b) => a.minValue - b.minValue);
  397. for (let i = 0, len = list.length - 1; i < len; i++) {
  398. if (list[i].maxValue >= list[i + 1].minValue) {
  399. return true;
  400. }
  401. }
  402. return false;
  403. },
  404. },
  405. computed: {
  406. isShow: {
  407. get() {
  408. if (this.dialogVisible) {
  409. this.init();
  410. }
  411. return this.dialogVisible;
  412. },
  413. set(val) {
  414. this.$emit("update:dialogVisible", false);
  415. },
  416. },
  417. title() {
  418. return ["新增", "修改", "复制"][this.type];
  419. },
  420. itemList() {
  421. return this.form.itemList;
  422. },
  423. },
  424. };
  425. </script>
  426. <style lang="scss" scoped>
  427. /deep/.el-input--medium .el-input__inner {
  428. width: 144px;
  429. }
  430. /deep/ .range {
  431. .el-form-item__content {
  432. width: 170px;
  433. }
  434. .el-input--medium .el-input__inner {
  435. width: 76px;
  436. }
  437. }
  438. /deep/ .ddd {
  439. margin-left: -10px;
  440. .el-input--medium .el-input__inner {
  441. width: 105px;
  442. }
  443. }
  444. .line {
  445. text-align: center;
  446. }
  447. .btns {
  448. height: 36px;
  449. display: flex;
  450. align-items: center;
  451. i {
  452. font-size: 24px;
  453. cursor: pointer;
  454. margin-left: 5px;
  455. }
  456. }
  457. .bop-tip {
  458. background: #fff6f7;
  459. margin: 0 0 20px 10px;
  460. padding: 8px 10px;
  461. i {
  462. font-size: 16px;
  463. color: #e6a23c;
  464. }
  465. }
  466. </style>