personnelAddTable.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <el-form ref="form" :model="form" :rules="rules">
  3. <ele-pro-table
  4. ref="table"
  5. :needPage="false"
  6. :columns="columns"
  7. :datasource="form.datasource"
  8. cache-key="systemRoleTable17"
  9. class="time-form"
  10. :toolkit="[]"
  11. >
  12. <!-- 表头工具栏 -->
  13. <template v-slot:toolbar>
  14. <el-button
  15. size="small"
  16. type="primary"
  17. icon="el-icon-plus"
  18. class="ele-btn-icon"
  19. @click="handlAdd"
  20. >
  21. 新增
  22. </el-button>
  23. <el-button
  24. size="small"
  25. type="primary"
  26. class="ele-btn-icon"
  27. @click="save"
  28. v-if="isDrawer"
  29. >
  30. 保存
  31. </el-button>
  32. </template>
  33. <template v-slot:linkId="scope">
  34. <el-form-item
  35. style="margin-bottom: 20px"
  36. :prop="'datasource.' + scope.$index + '.linkId'"
  37. :rules="{
  38. required: true,
  39. message: '请选择',
  40. trigger: 'change'
  41. }"
  42. >
  43. <el-select
  44. v-model="scope.row.linkId"
  45. placeholder="请选择"
  46. @change="changePersonel(scope.row, $event)"
  47. >
  48. <el-option
  49. v-for="item in linkNameOptions"
  50. :key="item.id"
  51. :label="item.linkName"
  52. :value="item.id"
  53. >
  54. </el-option>
  55. </el-select>
  56. </el-form-item>
  57. </template>
  58. <template v-slot:linkPost="scope">
  59. <el-form-item
  60. style="margin-bottom: 20px"
  61. :prop="'datasource.' + scope.$index + '.linkPost'"
  62. >
  63. <el-input
  64. v-model="scope.row.linkPost"
  65. disabled
  66. placeholder="请输入"
  67. ></el-input>
  68. </el-form-item>
  69. </template>
  70. <template v-slot:linkMobilePhone="scope">
  71. <el-form-item
  72. style="margin-bottom: 20px"
  73. :prop="'datasource.' + scope.$index + '.linkMobilePhone'"
  74. >
  75. <el-input
  76. v-model="scope.row.linkMobilePhone"
  77. disabled
  78. placeholder="请输入"
  79. ></el-input>
  80. </el-form-item>
  81. </template>
  82. <template v-slot:goal="scope">
  83. <el-form-item
  84. style="margin-bottom: 20px"
  85. :prop="'datasource.' + scope.$index + '.goal'"
  86. :rules="{
  87. required: true,
  88. message: '请输入',
  89. trigger: 'change'
  90. }"
  91. >
  92. <el-input v-model="scope.row.goal" placeholder="请输入"></el-input>
  93. </el-form-item>
  94. </template>
  95. <template v-slot:influenceCode="scope">
  96. <el-form-item
  97. style="margin-bottom: 20px"
  98. :prop="'datasource.' + scope.$index + '.influenceCode'"
  99. :rules="{
  100. required: true,
  101. message: '请选择',
  102. trigger: 'change'
  103. }"
  104. >
  105. <DictSelection
  106. dictName="影响力"
  107. clearable
  108. v-model="scope.row.influenceCode"
  109. >
  110. </DictSelection>
  111. </el-form-item>
  112. </template>
  113. <template v-slot:attitudeCode="scope">
  114. <el-form-item
  115. style="margin-bottom: 20px"
  116. :prop="'datasource.' + scope.$index + '.attitudeCode'"
  117. :rules="{
  118. required: true,
  119. message: '请选择',
  120. trigger: 'change'
  121. }"
  122. >
  123. <DictSelection
  124. dictName="态度"
  125. clearable
  126. v-model="scope.row.attitudeCode"
  127. >
  128. </DictSelection>
  129. </el-form-item>
  130. </template>
  131. <template v-slot:headerLinkId="{ column }">
  132. <span class="is-required">{{ column.label }}</span>
  133. </template>
  134. <template v-slot:headerGoal="{ column }">
  135. <span class="is-required">{{ column.label }}</span>
  136. </template>
  137. <template v-slot:headerInfluenceCode="{ column }">
  138. <span class="is-required">{{ column.label }}</span>
  139. </template>
  140. <template v-slot:headerAttitudeCode="{ column }">
  141. <span class="is-required">{{ column.label }}</span>
  142. </template>
  143. <!-- 操作列 -->
  144. <template v-slot:action="{ row }">
  145. <el-popconfirm
  146. class="ele-action"
  147. title="确定要删除吗?"
  148. @confirm="remove(row)"
  149. >
  150. <template v-slot:reference>
  151. <el-link type="danger" :underline="false" icon="el-icon-delete">
  152. 删除
  153. </el-link>
  154. </template>
  155. </el-popconfirm>
  156. </template>
  157. </ele-pro-table>
  158. </el-form>
  159. </template>
  160. <script>
  161. import { getcontactlink } from '@/api/saleManage/businessFollow';
  162. import dictMixins from '@/mixins/dictMixins';
  163. export default {
  164. props: {
  165. delDetailIds: Array,
  166. isDrawer: {
  167. type: Boolean,
  168. default: false
  169. },
  170. contactId: {
  171. type: String,
  172. default: ''
  173. }
  174. },
  175. mixins: [dictMixins],
  176. data() {
  177. const defaultForm = {
  178. key: null,
  179. linkId: '',
  180. linkPost: '',
  181. linkMobilePhone: '',
  182. goal: '',
  183. influenceCode: '',
  184. influenceName: '',
  185. attitudeCode: '',
  186. attitudeName: ''
  187. };
  188. return {
  189. newContactId: '',
  190. linkNameOptions: [],
  191. defaultForm,
  192. form: {
  193. datasource: []
  194. },
  195. rules: {},
  196. columns: [
  197. {
  198. width: 45,
  199. type: 'index',
  200. columnKey: 'index',
  201. align: 'center',
  202. fixed: 'left'
  203. },
  204. {
  205. prop: 'linkId',
  206. label: '姓名',
  207. slot: 'linkId',
  208. headerSlot: 'headerLinkId',
  209. align: 'center'
  210. },
  211. {
  212. prop: 'linkPost',
  213. label: '职位',
  214. slot: 'linkPost',
  215. align: 'center'
  216. },
  217. {
  218. prop: 'linkMobilePhone',
  219. label: '联系方式',
  220. slot: 'linkMobilePhone',
  221. align: 'center'
  222. },
  223. {
  224. prop: 'goal',
  225. label: '项目目标/期望',
  226. slot: 'goal',
  227. headerSlot: 'headerGoal',
  228. align: 'center'
  229. },
  230. {
  231. prop: 'influenceCode',
  232. label: '影响力',
  233. slot: 'influenceCode',
  234. headerSlot: 'headerInfluenceCode',
  235. align: 'center'
  236. },
  237. {
  238. prop: 'attitudeCode',
  239. label: '态度',
  240. slot: 'attitudeCode',
  241. headerSlot: 'headerAttitudeCode',
  242. align: 'center'
  243. },
  244. {
  245. width: 100,
  246. columnKey: 'action',
  247. label: '操作',
  248. align: 'center',
  249. resizable: false,
  250. slot: 'action',
  251. showOverflowTooltip: true
  252. }
  253. ]
  254. };
  255. },
  256. computed: {
  257. canHandl() {
  258. return this.form.datasource.length;
  259. }
  260. },
  261. watch: {
  262. },
  263. methods: {
  264. //初始数据
  265. async getContactIdInfo(contactId) {
  266. const data = await getcontactlink({ contactId});
  267. if (data && data?.length) {
  268. this.linkNameOptions = data;
  269. }
  270. },
  271. //修改回显
  272. putTableValue(data, contactId) {
  273. if (contactId) {
  274. this.getContactIdInfo(contactId);
  275. }
  276. if (data && data?.length) {
  277. this.form.datasource = data;
  278. }
  279. },
  280. // 返回列表数据
  281. getTableValue() {
  282. let _datasource = this.form.datasource || [];
  283. if (_datasource.length === 0) return;
  284. _datasource.forEach((v, index) => {
  285. if (_datasource[index].influenceCode) {
  286. _datasource[index].influenceName = this.getDictValue(
  287. '影响力',
  288. _datasource[index].influenceCode
  289. );
  290. }
  291. if (_datasource[index].attitudeCode) {
  292. _datasource[index].attitudeName = this.getDictValue(
  293. '态度',
  294. _datasource[index].attitudeCode
  295. );
  296. }
  297. });
  298. return _datasource;
  299. },
  300. //选择关键人
  301. changePersonel(row, val) {
  302. let selectVal = this.linkNameOptions.find((v) => v.id === val);
  303. row.linkPost = selectVal.post;
  304. row.linkMobilePhone = selectVal.mobilePhone|| selectVal.phone;
  305. },
  306. remove(row) {
  307. let index = this.form.datasource.findIndex((n) => n.key == row.key);
  308. if (index !== -1) {
  309. this.form.datasource.splice(index, 1);
  310. this.setSort();
  311. if (row.id) {
  312. this.delDetailIds.push(row.id);
  313. }
  314. }
  315. },
  316. // 清空表格
  317. restTable() {
  318. this.form.datasource = [];
  319. },
  320. // 重新排序
  321. setSort() {
  322. this.form.datasource.forEach((n, index) => {
  323. n.key = index + 1;
  324. });
  325. },
  326. // 添加
  327. handlAdd() {
  328. this.$emit('getContactId', (id) => {
  329. if (!id) {
  330. return this.$message.error('请先选择客户');
  331. }
  332. this.getContactIdInfo(id);
  333. let item = JSON.parse(JSON.stringify(this.defaultForm));
  334. item.key = this.form.datasource.length + 1;
  335. this.form.datasource.push(item);
  336. });
  337. },
  338. save() {
  339. this.$emit('save');
  340. },
  341. validateForm(callback) {
  342. //开始表单校验
  343. this.$refs.form.validate((valid) => {
  344. callback(valid);
  345. });
  346. }
  347. }
  348. };
  349. </script>
  350. <style lang="scss" scoped>
  351. .time-form .el-form-item {
  352. margin-bottom: 0 !important;
  353. }
  354. </style>