assignDialog.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. v-if="visible"
  6. :visible.sync="visible"
  7. title="指派"
  8. width="30%"
  9. :close-on-click-modal="false"
  10. :append-to-body="true"
  11. @close="cancel"
  12. >
  13. <el-form
  14. label-width="100px"
  15. ref="form"
  16. :model="form"
  17. :rules="rules"
  18. style="margin-top: 30px"
  19. >
  20. <el-form-item label="分管部门" prop="fgDeptId" style="margin-bottom: 22px">
  21. <ele-tree-select
  22. clearable
  23. :data="groupTreeData"
  24. v-model="form.fgDeptId"
  25. valueKey="id"
  26. labelKey="name"
  27. placeholder="请选择"
  28. @change="change_principalDep"
  29. default-expand-all
  30. />
  31. </el-form-item>
  32. <el-form-item label="业务员" prop="salesmanId">
  33. <personSelect
  34. ref="directorRef"
  35. v-model="form.salesmanId"
  36. @selfChange="salesmanChange"
  37. :init="false"
  38. />
  39. </el-form-item>
  40. </el-form>
  41. <div slot="footer" class="footer">
  42. <el-button type="primary" @click="save">保存</el-button>
  43. <el-button @click="cancel">返回</el-button>
  44. </div>
  45. </ele-modal>
  46. </template>
  47. <script>
  48. import {assign} from '@/api/saleManage/contact';
  49. import dictMixins from '@/mixins/dictMixins';
  50. import personSelect from '@/components/CommomSelect/person-select.vue';
  51. import { listOrganizations } from '@/api/system/organization';
  52. import { copyObj } from '@/utils/util';
  53. import parentList from './parentList.vue';
  54. let formDef = {
  55. contactIds: [],
  56. contactNames: [],
  57. fgDeptId: '',
  58. fgDeptName: '',
  59. salesmanId: '',
  60. salesmanName: ''
  61. };
  62. export default {
  63. mixins: [dictMixins],
  64. components: {
  65. personSelect
  66. },
  67. data() {
  68. return {
  69. visible: false,
  70. form: copyObj(formDef),
  71. rules: {
  72. fgDeptId: [{ required: true, message: '分管部门', trigger: 'change' }],
  73. salesmanId: [{ required: true, message: '业务员', trigger: 'blur' }]
  74. },
  75. // 提交状态
  76. loading: false,
  77. // 组织机构树形结构数据
  78. groupTreeData: [],
  79. // 组织机构平铺数据
  80. groupData: []
  81. };
  82. },
  83. created() {
  84. this.getGroupAll();
  85. },
  86. methods: {
  87. async open(contactIds, contactNames) {
  88. this.form.contactNames = contactNames.toString()
  89. this.form.contactIds = contactIds.toString()
  90. this.visible = true;
  91. },
  92. // 获取公司数据
  93. getGroupAll() {
  94. listOrganizations().then((list) => {
  95. this.groupData = list;
  96. this.groupTreeData = this.$util.toTreeData({
  97. data: list,
  98. idField: 'id',
  99. parentIdField: 'parentId'
  100. });
  101. });
  102. },
  103. // 选择负责人部门
  104. change_principalDep(id) {
  105. const info = this.groupData.find((e) => e.id == id);
  106. this.form.fgDeptName = info.name;
  107. this.form.salesmanId = '';
  108. this.form.salesmanName = '';
  109. // 根据部门获取人员
  110. const params = { groupId: id };
  111. this.$nextTick(() => {
  112. this.$refs.directorRef.getList(params);
  113. });
  114. },
  115. salesmanChange(val, info) {
  116. this.form.salesmanName = info.name;
  117. },
  118. getValidate() {
  119. return Promise.all([
  120. new Promise((resolve, reject) => {
  121. this.$refs.form.validate((valid) => {
  122. if (!valid) {
  123. this.activeName = 'base';
  124. reject(false);
  125. } else {
  126. resolve(true);
  127. }
  128. });
  129. })
  130. ]);
  131. },
  132. async save() {
  133. try {
  134. await this.getValidate();
  135. // 表单验证通过,执行保存操作
  136. this.loading = true;
  137. assign(this.form)
  138. .then((res) => {
  139. this.loading = false;
  140. this.$message.success('指派成功');
  141. this.$emit('done');
  142. this.cancel();
  143. })
  144. .catch((e) => {
  145. //this.loading = false;
  146. });
  147. } catch (error) {
  148. // 表单验证未通过,不执行保存操作
  149. }
  150. },
  151. cancel() {
  152. this.$nextTick(() => {
  153. this.form = copyObj(formDef)
  154. this.visible = false;
  155. });
  156. },
  157. }
  158. };
  159. </script>