itemAddOrEdit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. <!--
  2. * @Author: zwy
  3. * @Date: 2021-02-01 11:46:07
  4. * @LastEditors: zwy
  5. * @LastEditTime: 2021-05-19 15:45:27
  6. * @Descripttion: 考评项设置-编辑弹框
  7. -->
  8. <template>
  9. <div class="levelModal">
  10. <div class="tree-style" v-if="params.todo == 'add'">
  11. <el-tree
  12. :data="organList"
  13. ref="tree"
  14. node-key="id"
  15. :highlight-current="true"
  16. :props="defaultProps"
  17. :expand-on-click-node="false"
  18. default-expand-all
  19. :check-strictly="true"
  20. @check="changeOrgan"
  21. :show-checkbox="true"
  22. >
  23. <span class="ellipsis" slot-scope="{ node }">
  24. <span :title="node.label">{{ node.label }}</span>
  25. </span>
  26. </el-tree>
  27. </div>
  28. <zz-form class="form" :cols="formCols" :data="formData" :rules="formRules" labelWidth="110" ref="form">
  29. <template slot="type">
  30. <el-select v-model="formData.type" placeholder="请选择考评项">
  31. <!-- <el-option v-for="(item, index) in itemList" :key="index" :label="item.dictValue" :value="+item.dictCode">{{
  32. item.dictValue
  33. }}</el-option> -->
  34. <el-option label="任务完成数" :value="0"></el-option>
  35. <el-option label="任务按时完成率" :value="1"></el-option>
  36. <el-option label="用户评价" :value="3"></el-option>
  37. <el-option label="自定义" :value="2"></el-option>
  38. </el-select>
  39. </template>
  40. <!-- 条件 -->
  41. <template slot="valueCondition">
  42. <div style="display: flex">
  43. <span>任务延迟完成时间小于</span>
  44. <el-input v-model="formData.valueCondition" v-number-input style="width: 250px; margin: 0 10px" max="10"></el-input>
  45. <span>分钟</span>
  46. </div>
  47. </template>
  48. <!-- 分值条件设置 -->
  49. <template slot="itemValues">
  50. <div class="conditionTitle" v-if="formData.type == 1">
  51. <span>得分</span>
  52. <span>按时完成率</span>
  53. <span>百分比(%)</span>
  54. </div>
  55. <div class="conditionTitle" v-if="formData.type == 0 || formData.type == 3">
  56. <span>得分</span>
  57. <span>任务数</span>
  58. <span>数值</span>
  59. </div>
  60. <div class="conditionContent" v-for="(item, index) in formData.itemValues" :key="index">
  61. <el-form-item class="item" :prop="'itemValues.' + index + '.value'">
  62. <el-input v-model="item.value" v-number-input></el-input>
  63. </el-form-item>
  64. <el-form-item
  65. class="item"
  66. :prop="'itemValues.' + index + '.type'"
  67. :rules="[
  68. {
  69. validator: (rule, value, callback) => {
  70. checkType(rule, value, callback, index);
  71. }
  72. }
  73. ]"
  74. >
  75. <el-select placeholder="请选择" v-model="item.type">
  76. <el-option
  77. v-for="(item, index) in gradeList"
  78. :key="index"
  79. :value="+item.dictCode"
  80. :label="item.dictValue"
  81. ></el-option>
  82. </el-select>
  83. </el-form-item>
  84. <div class="item">
  85. <el-form-item style="width: 100px" :prop="'itemValues.' + index + '.valueOne'">
  86. <el-input v-model="item.valueOne" v-number-input></el-input>
  87. </el-form-item>
  88. <span style="margin: 0 5px">-</span>
  89. <el-form-item
  90. style="width: 100px"
  91. :prop="'itemValues.' + index + '.valueTwo'"
  92. :rules="[
  93. {
  94. validator: (rule, value, callback) => {
  95. checkValueTwo(rule, value, callback, index);
  96. }
  97. }
  98. ]"
  99. >
  100. <el-input v-model="item.valueTwo" :disabled="item.type !== 1" v-number-input></el-input>
  101. </el-form-item>
  102. </div>
  103. <div>
  104. <i class="iconfont" v-if="index == formData.itemValues.length - 1" @click="add">&#xe67c;</i>
  105. <i class="iconfont" v-else @click="deleteOne(index)">&#xe682;</i>
  106. </div>
  107. </div>
  108. </template>
  109. <template slot="cycle">
  110. <el-checkbox-group v-model="formData.cycle">
  111. <el-checkbox v-for="(item, index) in cycleList" :key="index" :label="item.dictCode">{{ item.dictValue }}</el-checkbox>
  112. </el-checkbox-group>
  113. </template>
  114. <template slot="remarks">
  115. <el-input class="textarea" type="textarea" maxlength="100" v-model="formData.remarks"></el-input>
  116. </template>
  117. </zz-form>
  118. </div>
  119. </template>
  120. <script>
  121. export default {
  122. props: ['params'],
  123. data() {
  124. return {
  125. checkList: [],
  126. organList: [],
  127. defaultProps: {
  128. children: 'orgs',
  129. label: 'orgName'
  130. },
  131. formData: {
  132. id: '',
  133. deptOrgIds: [], //所属公司
  134. type: 2, //考评项
  135. name: '', //名称
  136. value: '', //分值
  137. valueCondition: '', //条件值
  138. itemValues: [
  139. //考评项分值
  140. {
  141. value: '', //得分
  142. type: '', //符号
  143. valueOne: '', //值1
  144. valueTwo: '' //值2
  145. }
  146. ],
  147. cycle: [], //考评周期
  148. remarks: '' //评分标准
  149. },
  150. itemList: [], //考评项列表
  151. cycleList: [], //考评周期列表
  152. gradeList: [], //符号
  153. formCols: [],
  154. formCols1: [
  155. //任务按时完成率
  156. [
  157. {
  158. label: '考评项',
  159. prop: 'type',
  160. slot: 'type'
  161. },
  162. {
  163. label: '分值',
  164. prop: 'value',
  165. input: true
  166. },
  167. {
  168. label: '条件',
  169. prop: 'valueCondition',
  170. slot: 'valueCondition'
  171. },
  172. {
  173. label: '得分规则设置',
  174. prop: 'itemValues',
  175. slot: 'itemValues'
  176. },
  177. {
  178. label: '考评周期',
  179. prop: 'cycle',
  180. slot: 'cycle'
  181. },
  182. {
  183. label: '评分标准',
  184. prop: 'remarks',
  185. slot: 'remarks'
  186. }
  187. ]
  188. ],
  189. formCols2: [
  190. //任务
  191. [
  192. {
  193. label: '考评项',
  194. prop: 'type',
  195. slot: 'type'
  196. },
  197. {
  198. label: '分值',
  199. prop: 'value',
  200. input: true
  201. },
  202. {
  203. label: '得分规则设置',
  204. prop: 'itemValues',
  205. slot: 'itemValues'
  206. },
  207. {
  208. label: '考评周期',
  209. prop: 'cycle',
  210. slot: 'cycle'
  211. },
  212. {
  213. label: '评分标准',
  214. prop: 'remarks',
  215. slot: 'remarks'
  216. }
  217. ]
  218. ],
  219. formCols3: [
  220. //自定义列
  221. [
  222. {
  223. label: '考评项',
  224. prop: 'type',
  225. slot: 'type'
  226. },
  227. {
  228. label: '名称',
  229. prop: 'name',
  230. maxlength: 20,
  231. input: true
  232. },
  233. {
  234. label: '分值',
  235. prop: 'value',
  236. maxlength: 10,
  237. input: true
  238. },
  239. {
  240. label: '考评周期',
  241. prop: 'cycle',
  242. slot: 'cycle'
  243. },
  244. {
  245. label: '评分标准',
  246. prop: 'remarks',
  247. slot: 'remarks'
  248. }
  249. ]
  250. ],
  251. formRules: {
  252. type: [this.$valid.selectRequired('考评项')],
  253. name: [this.$valid.inputRequired('名称')],
  254. value: [this.$valid.inputRequired('分值'), this.$valid.pattern(/^(?:[1-9]?\d|100)$/)],
  255. valueCondition: [this.$valid.inputRequired('条件')],
  256. itemValues: [this.$valid.inputRequired('得分规则设置')],
  257. cycle: [this.$valid.selectRequired('考评周期')],
  258. remarks: [this.$valid.inputRequired('评分标准')]
  259. }
  260. };
  261. },
  262. watch: {
  263. 'formData.type'(val) {
  264. this.$refs.form.$refs.form.clearValidate();
  265. if (val == 1) {
  266. //任务按时完成率
  267. this.formData.name = '任务按时完成率';
  268. this.formCols = this.formCols1;
  269. } else if (val == 2) {
  270. //自定义
  271. this.formCols = this.formCols3;
  272. } else {
  273. //任务完成数
  274. this.formData.name = '任务完成数';
  275. this.formCols = this.formCols2;
  276. }
  277. }
  278. },
  279. methods: {
  280. // 校验
  281. checkType(rule, value, callback, index) {
  282. if (this.formData.itemValues[index].type !== 1) {
  283. this.formData.itemValues[index].valueTwo = '';
  284. }
  285. callback();
  286. },
  287. checkValueTwo(rule, value, callback, index) {
  288. if (
  289. this.formData.itemValues[index].type == 1 &&
  290. this.formData.itemValues[index].valueOne > this.formData.itemValues[index].valueTwo
  291. ) {
  292. callback('前一个分值必须小于等于后一个分值');
  293. }
  294. callback();
  295. },
  296. //获取考评项
  297. getEvalutionItem() {
  298. this.$api.common.getDictionaryData('SC_EVALUATION_ITEM').then(({ msg, status, data }) => {
  299. if (status == 0) {
  300. this.itemList = data;
  301. }
  302. });
  303. },
  304. //获取考评周期
  305. getEvalutionCycle() {
  306. this.$api.common.getDictionaryData('SC_EVALUATION_CYCLE').then(({ msg, status, data }) => {
  307. if (status == 0) {
  308. this.cycleList = data;
  309. }
  310. });
  311. },
  312. getGradeType() {
  313. this.$api.common.getDictionaryData('SC_EVALUATION_GRADE_TYPE').then(({ msg, status, data }) => {
  314. if (status == 0) {
  315. this.gradeList = data;
  316. }
  317. });
  318. },
  319. changeOrgan() {
  320. var data = this.$refs.tree.getCheckedNodes();
  321. let arr = [];
  322. data.map((item, index) => {
  323. arr.push(item.id);
  324. });
  325. this.formData.deptOrgIds = arr;
  326. },
  327. getOrgTreeList() {
  328. this.$http.postForm('/sc-user-center/org/getOrgTree', { orgType: 1 }).then(({ status, data, msg }) => {
  329. if (status === 0 && data) {
  330. this.organList = data;
  331. }
  332. });
  333. },
  334. deleteOne(index) {
  335. this.formData.itemValues.splice(index, 1);
  336. },
  337. add() {
  338. let arr = {
  339. value: '', //得分
  340. type: '', //符号
  341. valueOne: '', //值1
  342. valueTwo: '' //值2
  343. };
  344. this.formData.itemValues.push(arr);
  345. },
  346. submit() {
  347. new Promise((resolve) => {
  348. this.$refs.form.validate(resolve);
  349. }).then(() => {
  350. var posturl = '',
  351. method = 'post';
  352. if (this.params.todo === 'edit') {
  353. posturl = '/sc-community/evaluation/item/edit';
  354. delete this.formData.deptOrgIds;
  355. } else {
  356. posturl = '/sc-community/evaluation/item/add';
  357. if (!this.formData.deptOrgIds.length) {
  358. this.$message.error('请勾选所属公司');
  359. loading.close();
  360. return;
  361. }
  362. }
  363. var loading = this.$loading();
  364. this.formData.cycle = this.formData.cycle.join(',');
  365. this.$http[method](posturl, this.formData)
  366. .then(({ status, data, msg }) => {
  367. loading.close();
  368. if (0 == status) {
  369. this.$message.success(msg);
  370. this.params.callback && this.params.callback();
  371. this.$emit('close');
  372. } else {
  373. this.$message.error(msg);
  374. }
  375. })
  376. .catch((err) => {
  377. loading.close();
  378. });
  379. });
  380. }
  381. },
  382. created() {
  383. this.getEvalutionItem();
  384. this.getEvalutionCycle();
  385. this.getGradeType();
  386. this.getOrgTreeList();
  387. this.formCols = this.formCols3;
  388. if (this.params.todo == 'edit') {
  389. this.params.data.cycle = this.params.data.cycle.split(',');
  390. this.__setValue('formData');
  391. }
  392. }
  393. };
  394. </script>
  395. <style lang="scss" scoped>
  396. .levelModal {
  397. display: flex;
  398. min-height: 100%;
  399. .tree-style {
  400. width: 300px;
  401. border: 1px solid #d8d8d8;
  402. border-radius: 4px;
  403. overflow: auto;
  404. padding: 20px;
  405. }
  406. .form {
  407. width: 100%;
  408. margin-left: 20px;
  409. border: 1px solid #d8d8d8;
  410. padding: 20px;
  411. .conditionTitle {
  412. display: flex;
  413. span:nth-child(1) {
  414. width: 17%;
  415. }
  416. span:nth-child(2) {
  417. width: 35%;
  418. }
  419. span:nth-child(3) {
  420. width: 50%;
  421. }
  422. }
  423. .conditionContent {
  424. display: flex;
  425. .item:nth-child(1) {
  426. width: 15%;
  427. margin-right: 10px;
  428. }
  429. .item:nth-child(2) {
  430. width: 30%;
  431. margin-right: 20px;
  432. }
  433. .item:nth-child(3) {
  434. width: 50%;
  435. display: flex;
  436. }
  437. }
  438. .textarea {
  439. /deep/.el-textarea__inner {
  440. width: 100%;
  441. height: 200px;
  442. }
  443. }
  444. }
  445. }
  446. </style>