addOrUpdateDialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <ele-modal
  3. width="75%"
  4. :append-to-body="true"
  5. custom-class="ele-dialog-form"
  6. :title="title"
  7. :visible.sync="visible"
  8. :maxable="true"
  9. @close="handleClose"
  10. >
  11. <header-title title="计划基本信息"></header-title>
  12. <el-form
  13. ref="addFormRef"
  14. :model="addForm"
  15. :rules="addFormRules"
  16. label-width="120px"
  17. >
  18. <el-row>
  19. <el-col :span="6">
  20. <el-form-item label="编码" prop="code">
  21. <el-input
  22. v-model="addForm.code"
  23. size="small"
  24. placeholder="请输入"
  25. disabled
  26. ></el-input>
  27. <!-- :disabled="type == 'view'" -->
  28. </el-form-item>
  29. </el-col>
  30. <el-col :span="6">
  31. <el-form-item
  32. label="名称"
  33. prop="name"
  34. :rules="{
  35. required: true,
  36. message: '请输入名称',
  37. trigger: 'change'
  38. }"
  39. >
  40. <el-input
  41. v-model="addForm.name"
  42. size="small"
  43. placeholder="请输入"
  44. :disabled="type == 'view'"
  45. ></el-input>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :span="6">
  49. <el-form-item label="自动派单" prop="isSyncBill">
  50. <el-select
  51. v-model="addForm.isSyncBill"
  52. size="small"
  53. style="width: 100%"
  54. :disabled="type == 'view'"
  55. >
  56. <el-option :value="1" label="是"></el-option>
  57. <el-option :value="0" label="否"></el-option>
  58. </el-select>
  59. </el-form-item>
  60. </el-col>
  61. <el-col :span="6">
  62. <el-form-item label="预计售后时长" prop="duration">
  63. <div style="display: flex">
  64. <el-input
  65. type="number"
  66. v-model="addForm.duration"
  67. size="small"
  68. placeholder="请输入"
  69. @input="formDataDurationTime"
  70. :disabled="type == 'view'"
  71. >
  72. <template #suffix>
  73. <el-select
  74. v-model="addForm.durationUnit"
  75. size="small"
  76. style="width: 120px"
  77. :disabled="type == 'view'"
  78. >
  79. <el-option :value="'1'" label="分钟"></el-option>
  80. <el-option :value="'2'" label="小时"></el-option>
  81. <el-option :value="'3'" label="天"></el-option>
  82. </el-select>
  83. </template>
  84. </el-input>
  85. </div>
  86. </el-form-item>
  87. </el-col>
  88. </el-row>
  89. <el-row>
  90. <el-col :span="6">
  91. <el-form-item
  92. label="部门"
  93. prop="executeGroupId"
  94. :rules="{
  95. required: true,
  96. message: '请选择部门',
  97. trigger: 'change'
  98. }"
  99. >
  100. <deptSelect
  101. v-model="addForm.executeGroupId"
  102. @changeGroup="searchDeptNodeClick"
  103. :disabled="type == 'view' && !isDispatch"
  104. />
  105. </el-form-item>
  106. </el-col>
  107. <el-col :span="6">
  108. <el-form-item
  109. label="工单执行人"
  110. prop="executeUserId"
  111. :rules="{
  112. required: true,
  113. message: '请选择工单执行人',
  114. trigger: 'change'
  115. }"
  116. >
  117. <el-select
  118. v-model="addForm.executeUserId"
  119. size="small"
  120. style="width: 100%"
  121. filterable
  122. @change="changeUser"
  123. :disabled="type == 'view' && !isDispatch"
  124. >
  125. <el-option
  126. v-for="item in executorList"
  127. :key="item.id"
  128. :value="item.id"
  129. :label="item.name"
  130. ></el-option>
  131. </el-select>
  132. </el-form-item>
  133. </el-col>
  134. <el-col :span="6">
  135. <el-form-item label="紧急程度" prop="urgent">
  136. <DictSelection
  137. dictName="紧急程度"
  138. clearable
  139. v-model="addForm.urgent"
  140. :disabled="type == 'view'"
  141. ></DictSelection>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="6">
  145. <el-form-item label="备注" prop="remark">
  146. <el-input
  147. type="textarea"
  148. resize="none"
  149. v-model="addForm.remark"
  150. :rows="2"
  151. placeholder="请详细说明"
  152. size="small"
  153. :disabled="type == 'view'"
  154. ></el-input>
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. </el-form>
  159. <!-- ***改 -->
  160. <div class="ele-body-custom">
  161. <el-tabs v-model="activeName" style="width: 100%" type="border-card">
  162. <el-tab-pane label="需求信息" name="需求信息">
  163. <info
  164. ref="infoRef"
  165. v-if="operationalState"
  166. type="view"
  167. :isPurchaseNeed="false"
  168. ></info>
  169. <info
  170. ref="infoRef"
  171. v-else
  172. source="售后计划"
  173. type="view"
  174. state="可操作"
  175. :isPurchaseNeed="false"
  176. ></info>
  177. </el-tab-pane>
  178. <el-tab-pane label="方案" name="方案">
  179. <!-- :type="type" -->
  180. <spareParts
  181. obtain="仓库"
  182. ref="sparePartsRef"
  183. :type="title == '详情' ? 'view' : 'edit'"
  184. ></spareParts>
  185. </el-tab-pane>
  186. </el-tabs>
  187. </div>
  188. <template v-slot:footer>
  189. <el-button @click="handleClose" :loading="loading">取消</el-button>
  190. <el-button
  191. type="primary"
  192. :loading="loading"
  193. @click="save('')"
  194. v-if="type != 'view'"
  195. >保存</el-button
  196. >
  197. <el-button
  198. type="primary"
  199. :loading="loading"
  200. @click="save('派单')"
  201. v-if="type == 'edit'"
  202. >派单</el-button
  203. >
  204. <el-button
  205. type="primary"
  206. :loading="loading"
  207. @click="save('')"
  208. v-if="isDispatch"
  209. >派单</el-button
  210. >
  211. </template>
  212. </ele-modal>
  213. </template>
  214. <script>
  215. import {
  216. getSalesPlanById,
  217. updateSalesPlan,
  218. dispatchOrders
  219. } from '@/api/salesServiceManagement/index';
  220. import { contactDetail } from '@/api/saleManage/contact';
  221. import { getUserPage } from '@/api/system/organization';
  222. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  223. // import fileMain from '@/components/addDoc/index.vue';
  224. import spareParts from '@/views/salesServiceManagement/components/sparePartsList.vue';
  225. import info from '@/views/salesServiceManagement/components/info.vue';
  226. import { getCurrentUser } from '@/utils/token-util';
  227. import { mapGetters } from 'vuex';
  228. let def = {
  229. name: '',
  230. isSyncBill: 1,
  231. duration: null,
  232. executeGroupId: '',
  233. executeGroupName: '',
  234. executeUserId: '',
  235. executeUserName: '',
  236. urgent: null,
  237. remark: '',
  238. durationUnit: '2'
  239. };
  240. export default {
  241. components: {
  242. deptSelect,
  243. // fileMain,
  244. spareParts,
  245. info
  246. },
  247. props: {},
  248. data() {
  249. return {
  250. activeName: '需求信息',
  251. addForm: {
  252. ...def
  253. },
  254. executorList: [], // 业务人员列表
  255. // 表单验证规则
  256. addFormRules: {},
  257. visible: false,
  258. statusList: [
  259. { label: '草稿', value: -1 },
  260. { label: '失效', value: 0 },
  261. { label: '生效', value: 1 }
  262. ],
  263. // 提交状态
  264. loading: false,
  265. type: 'add',
  266. title: '',
  267. isDispatch: false,
  268. detailList: []
  269. };
  270. },
  271. computed: {
  272. ...mapGetters(['getDictValue']),
  273. // 是否开启响应式布局
  274. styleResponsive() {
  275. return this.$store.state.theme.styleResponsive;
  276. },
  277. // 需求信息操作状态
  278. operationalState() {
  279. if (this.title == '派单') {
  280. return false;
  281. }
  282. let flag = this.type == 'view';
  283. return flag;
  284. },
  285. // 部门下拉
  286. loginChangeGroupVOList() {
  287. return this.$store.state.user?.info?.loginChangeGroupVOList;
  288. }
  289. },
  290. watch: {},
  291. methods: {
  292. handleClose() {
  293. this.addForm = { ...def };
  294. this.visible = false;
  295. this.$refs.addFormRef.resetFields();
  296. },
  297. // 默认部门
  298. departmentAss() {
  299. let currentUser = getCurrentUser();
  300. if (
  301. this.loginChangeGroupVOList &&
  302. this.loginChangeGroupVOList.length > 0
  303. ) {
  304. let obj = this.loginChangeGroupVOList.find(
  305. (el) => el.groupId == currentUser.currentGroupId
  306. );
  307. this.addForm.executeGroupId = currentUser.currentGroupId || '';
  308. this.searchDeptNodeClick(currentUser.currentGroupId, {
  309. name: obj.groupName
  310. });
  311. }
  312. },
  313. // 初始化
  314. async init(row, type, isDispatch) {
  315. this.type = type;
  316. this.title = isDispatch ? '派单' : type == 'view' ? '详情' : '修改';
  317. this.isDispatch = isDispatch;
  318. if (row) {
  319. this.visible = true;
  320. this.getInfo(row.id);
  321. if (row.executeGroupId) {
  322. this.getUserList({ groupId: row.executeGroupId });
  323. }
  324. } else {
  325. }
  326. },
  327. formDataDurationTime(value) {
  328. if (value > 0) {
  329. this.addForm.duration = value.replace(/^[0]+/, '');
  330. } else {
  331. this.addForm.duration = 0;
  332. }
  333. },
  334. //选择部门(搜索)
  335. searchDeptNodeClick(info, data) {
  336. if (info) {
  337. // 根据部门获取人员
  338. this.addForm.executeGroupName = data.name;
  339. const params = { groupId: info };
  340. this.getUserList(params);
  341. } else {
  342. this.addForm.executeGroupId = null;
  343. }
  344. },
  345. // 获取审核人列表、巡点检人员
  346. async getUserList(params) {
  347. try {
  348. let data = { pageNum: 1, size: -1 };
  349. // 如果传了参数就是获取巡点检人员数据
  350. if (params) {
  351. data = Object.assign(data, params);
  352. }
  353. const res = await getUserPage(data);
  354. if (params) {
  355. this.executorList = res.list;
  356. }
  357. } catch (error) {}
  358. },
  359. changeUser(val) {
  360. this.executorList.map((item) => {
  361. if (item.id == val) {
  362. this.addForm.executeUserName = item.name;
  363. }
  364. });
  365. },
  366. async save(paramName) {
  367. try {
  368. let valid = await this.$refs.infoRef.getValidate();
  369. let data = this.$refs.infoRef.getValue();
  370. await this.$refs.sparePartsRef.getValidate();
  371. this.addForm.costListVOS = this.$refs.sparePartsRef.getTableValue();
  372. this.$refs.addFormRef.validate(async (valid, obj) => {
  373. if (obj) {
  374. let messages = Object.keys(obj).map((key) => obj[key][0]);
  375. if (messages.length > 0) {
  376. this.$message.warning(messages[0].message);
  377. }
  378. }
  379. if (valid) {
  380. let requestName = this.isDispatch
  381. ? dispatchOrders
  382. : updateSalesPlan;
  383. // *** 修改的时候也可以直接派单
  384. if (paramName) {
  385. requestName = dispatchOrders;
  386. }
  387. // *** 新增参数
  388. let obj = this.infoData(data);
  389. this.addForm.salesDemandUpdatePO = obj;
  390. this.loading = true;
  391. const res = await requestName(this.addForm);
  392. this.loading = false;
  393. if (!res) return;
  394. this.$message.success('操作成功');
  395. this.visible = false;
  396. this.$emit('reload');
  397. }
  398. });
  399. } catch (error) {
  400. this.loading = false;
  401. }
  402. },
  403. // *** 需求信息参数
  404. infoData(data) {
  405. let obj = JSON.parse(JSON.stringify(data));
  406. obj.productDetail = obj.tableList;
  407. delete obj.tableList;
  408. obj.id = this.addForm.afterSalesDemandVO.id;
  409. obj.productDetail.map((el) => delete el.produceTime);
  410. return obj;
  411. },
  412. async getInfo(id) {
  413. const res = await getSalesPlanById(id);
  414. if (!res) return;
  415. this.addForm = res;
  416. // 不存在部门就调用
  417. if (!res.executeGroupId) {
  418. this.departmentAss();
  419. }
  420. // 默认赋值 时间单位
  421. this.addForm.durationUnit = this.addForm.durationUnit
  422. ? this.addForm.durationUnit
  423. : '2';
  424. this.$nextTick(() => {
  425. this.$refs.infoRef.init(res.afterSalesDemandVO);
  426. this.$refs.sparePartsRef.setTableValue(res?.costListVOS || []);
  427. });
  428. }
  429. }
  430. };
  431. </script>
  432. <style lang="scss" scoped>
  433. .marginBto {
  434. margin-bottom: 10px;
  435. span {
  436. margin-left: 50px;
  437. }
  438. .name {
  439. font-weight: 800;
  440. color: #40a9ff;
  441. }
  442. }
  443. :deep(.el-input__suffix .el-input__inner) {
  444. border: none;
  445. background: none;
  446. }
  447. .ele-body-custom {
  448. :deep(.divider) {
  449. display: none;
  450. }
  451. }
  452. </style>