addOrUpdateDialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. <!-- <info ref="infoRef" type="view" :isPurchaseNeed="false"></info>
  189. <header-title title="方案"></header-title>
  190. <spareParts ref="sparePartsRef" :type="type"></spareParts>-->
  191. <template v-slot:footer>
  192. <el-button @click="handleClose">取消</el-button>
  193. <el-button type="primary" @click="save('')" v-if="type != 'view'"
  194. >保存</el-button
  195. >
  196. <el-button type="primary" @click="save('派单')" v-if="type == 'edit'"
  197. >派单</el-button
  198. >
  199. <el-button type="primary" @click="save('')" v-if="isDispatch"
  200. >派单</el-button
  201. >
  202. </template>
  203. </ele-modal>
  204. </template>
  205. <script>
  206. import {
  207. getSalesPlanById,
  208. updateSalesPlan,
  209. dispatchOrders
  210. } from '@/api/salesServiceManagement/index';
  211. import { contactDetail } from '@/api/saleManage/contact';
  212. import { getUserPage } from '@/api/system/organization';
  213. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  214. // import fileMain from '@/components/addDoc/index.vue';
  215. import spareParts from '@/views/salesServiceManagement/components/sparePartsList.vue';
  216. import info from '@/views/salesServiceManagement/components/info.vue';
  217. import { getCurrentUser } from '@/utils/token-util';
  218. import { mapGetters } from 'vuex';
  219. let def = {
  220. name: '',
  221. isSyncBill: 1,
  222. duration: null,
  223. executeGroupId: '',
  224. executeGroupName: '',
  225. executeUserId: '',
  226. executeUserName: '',
  227. urgent: null,
  228. remark: '',
  229. durationUnit: '2'
  230. };
  231. export default {
  232. components: {
  233. deptSelect,
  234. // fileMain,
  235. spareParts,
  236. info
  237. },
  238. props: {},
  239. data() {
  240. return {
  241. activeName: '需求信息',
  242. addForm: {
  243. ...def
  244. },
  245. executorList: [], // 业务人员列表
  246. // 表单验证规则
  247. addFormRules: {},
  248. visible: false,
  249. statusList: [
  250. { label: '草稿', value: -1 },
  251. { label: '失效', value: 0 },
  252. { label: '生效', value: 1 }
  253. ],
  254. // 提交状态
  255. loading: false,
  256. type: 'add',
  257. title: '',
  258. isDispatch: false,
  259. detailList: []
  260. };
  261. },
  262. computed: {
  263. ...mapGetters(['getDictValue']),
  264. // 是否开启响应式布局
  265. styleResponsive() {
  266. return this.$store.state.theme.styleResponsive;
  267. },
  268. // 需求信息操作状态
  269. operationalState() {
  270. if (this.title == '派单') {
  271. return false;
  272. }
  273. let flag = this.type == 'view';
  274. return flag;
  275. },
  276. // 部门下拉
  277. loginChangeGroupVOList() {
  278. return this.$store.state.user?.info?.loginChangeGroupVOList;
  279. }
  280. },
  281. watch: {},
  282. methods: {
  283. handleClose() {
  284. this.addForm = { ...def };
  285. this.visible = false;
  286. this.$refs.addFormRef.resetFields();
  287. },
  288. // 默认部门
  289. departmentAss() {
  290. let currentUser = getCurrentUser();
  291. if (
  292. this.loginChangeGroupVOList &&
  293. this.loginChangeGroupVOList.length > 0
  294. ) {
  295. let obj = this.loginChangeGroupVOList.find(
  296. (el) => el.groupId == currentUser.currentGroupId
  297. );
  298. this.addForm.executeGroupId = currentUser.currentGroupId || '';
  299. this.searchDeptNodeClick(currentUser.currentGroupId, {
  300. name: obj.groupName
  301. });
  302. }
  303. },
  304. // 初始化
  305. async init(row, type, isDispatch) {
  306. this.type = type;
  307. this.title = isDispatch ? '派单' : type == 'view' ? '详情' : '修改';
  308. this.isDispatch = isDispatch;
  309. if (row) {
  310. this.visible = true;
  311. this.getInfo(row.id);
  312. if (row.executeGroupId) {
  313. this.getUserList({ groupId: row.executeGroupId });
  314. }
  315. } else {
  316. }
  317. },
  318. formDataDurationTime(value) {
  319. if (value > 0) {
  320. this.addForm.duration = value.replace(/^[0]+/, '');
  321. } else {
  322. this.addForm.duration = 0;
  323. }
  324. },
  325. //选择部门(搜索)
  326. searchDeptNodeClick(info, data) {
  327. if (info) {
  328. // 根据部门获取人员
  329. this.addForm.executeGroupName = data.name;
  330. const params = { groupId: info };
  331. this.getUserList(params);
  332. } else {
  333. this.addForm.executeGroupId = null;
  334. }
  335. },
  336. // 获取审核人列表、巡点检人员
  337. async getUserList(params) {
  338. try {
  339. let data = { pageNum: 1, size: -1 };
  340. // 如果传了参数就是获取巡点检人员数据
  341. if (params) {
  342. data = Object.assign(data, params);
  343. }
  344. const res = await getUserPage(data);
  345. if (params) {
  346. this.executorList = res.list;
  347. }
  348. } catch (error) {}
  349. },
  350. changeUser(val) {
  351. this.executorList.map((item) => {
  352. if (item.id == val) {
  353. this.addForm.executeUserName = item.name;
  354. }
  355. });
  356. },
  357. async save(paramName) {
  358. try {
  359. let valid = await this.$refs.infoRef.getValidate();
  360. let data = this.$refs.infoRef.getValue();
  361. await this.$refs.sparePartsRef.getValidate();
  362. this.addForm.costListVOS = this.$refs.sparePartsRef.getTableValue();
  363. this.$refs.addFormRef.validate(async (valid, obj) => {
  364. if (obj) {
  365. let messages = Object.keys(obj).map((key) => obj[key][0]);
  366. if (messages.length > 0) {
  367. this.$message.warning(messages[0].message);
  368. }
  369. }
  370. if (valid) {
  371. let requestName = this.isDispatch
  372. ? dispatchOrders
  373. : updateSalesPlan;
  374. // *** 修改的时候也可以直接派单
  375. if (paramName) {
  376. requestName = dispatchOrders;
  377. }
  378. // *** 新增参数
  379. let obj = this.infoData(data);
  380. this.addForm.salesDemandUpdatePO = obj;
  381. const res = await requestName(this.addForm);
  382. if (!res) return;
  383. this.$message.success('操作成功');
  384. this.visible = false;
  385. this.$emit('reload');
  386. }
  387. });
  388. } catch (error) {}
  389. },
  390. // *** 需求信息参数
  391. infoData(data) {
  392. let obj = JSON.parse(JSON.stringify(data));
  393. obj.productDetail = obj.tableList;
  394. delete obj.tableList;
  395. obj.id = this.addForm.afterSalesDemandVO.id;
  396. obj.productDetail.map((el) => delete el.produceTime);
  397. return obj;
  398. },
  399. async getInfo(id) {
  400. const res = await getSalesPlanById(id);
  401. if (!res) return;
  402. this.addForm = res;
  403. // 不存在部门就调用
  404. if (!res.executeGroupId) {
  405. this.departmentAss();
  406. }
  407. console.log('修改数据', res);
  408. // 默认赋值 时间单位
  409. this.addForm.durationUnit = this.addForm.durationUnit
  410. ? this.addForm.durationUnit
  411. : '2';
  412. this.$nextTick(() => {
  413. this.$refs.infoRef.init(res.afterSalesDemandVO);
  414. this.$refs.sparePartsRef.setTableValue(res?.costListVOS || []);
  415. });
  416. }
  417. }
  418. };
  419. </script>
  420. <style lang="scss" scoped>
  421. .marginBto {
  422. margin-bottom: 10px;
  423. span {
  424. margin-left: 50px;
  425. }
  426. .name {
  427. font-weight: 800;
  428. color: #40a9ff;
  429. }
  430. }
  431. :deep(.el-input__suffix .el-input__inner) {
  432. border: none;
  433. background: none;
  434. }
  435. .ele-body-custom {
  436. :deep(.divider) {
  437. display: none;
  438. }
  439. }
  440. </style>