addDialog.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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="title"
  8. :close-on-click-modal="false"
  9. width="60%"
  10. @close="cancel"
  11. >
  12. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  13. <headerTitle title="基本信息"></headerTitle>
  14. <el-row>
  15. <el-col :span="12">
  16. <el-form-item
  17. label="采购需求"
  18. prop="requirementCode"
  19. style="margin-bottom: 22px"
  20. >
  21. <el-input
  22. @click.native="handParent"
  23. v-model="form.requirementCode"
  24. placeholder="请选择"
  25. ></el-input>
  26. </el-form-item>
  27. </el-col>
  28. <el-col :span="12">
  29. <el-form-item
  30. label="责任人"
  31. prop="responsibleName"
  32. style="margin-bottom: 22px"
  33. >
  34. <el-input
  35. @click.native="openStaffSelection"
  36. v-model="form.responsibleName"
  37. placeholder="请选择"
  38. ></el-input>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="12">
  42. <el-form-item
  43. label="需求类型"
  44. prop="sourceType"
  45. style="margin-bottom: 22px"
  46. >
  47. <DictSelection
  48. dictName="需求来源类型"
  49. clearable
  50. v-model="form.sourceType"
  51. :disabled="!!form.requirementCode"
  52. :listFormatte="listFormatte"
  53. v-if="form.sourceType != 1"
  54. >
  55. </DictSelection>
  56. <el-input
  57. v-if="form.sourceType == 1"
  58. v-model="form.sourceTypeName"
  59. disabled
  60. ></el-input>
  61. </el-form-item>
  62. </el-col>
  63. <el-col :span="12">
  64. <el-form-item
  65. label="需求部门"
  66. prop="requireDeptId"
  67. style="margin-bottom: 22px"
  68. >
  69. <ele-tree-select
  70. :disabled="!!form.requirementCode"
  71. clearable
  72. :data="groupTreeData"
  73. v-model="form.requireDeptId"
  74. valueKey="id"
  75. labelKey="name"
  76. placeholder="请选择"
  77. @change="change_principalDep"
  78. default-expand-all
  79. />
  80. </el-form-item>
  81. </el-col>
  82. <el-col :span="12">
  83. <el-form-item
  84. label="需求人"
  85. prop="requireUserId"
  86. style="margin-bottom: 22px"
  87. >
  88. <personSelect
  89. :disabled="!!form.requirementCode"
  90. ref="directorRef"
  91. v-model="form.requireUserId"
  92. @selfChange="salesmanChange"
  93. :init="false"
  94. />
  95. </el-form-item>
  96. </el-col>
  97. <el-col :span="12">
  98. <el-form-item prop="remark" label="是否接受拆单" label-width="120px">
  99. <el-select
  100. v-model="form.acceptUnpack"
  101. clearable
  102. style="width: 100%"
  103. :disabled="!!form.requirementCode"
  104. >
  105. <el-option
  106. v-for="item in acceptUnpackList"
  107. :key="item.value"
  108. :label="item.label"
  109. :value="item.value"
  110. >
  111. </el-option>
  112. </el-select>
  113. </el-form-item>
  114. </el-col>
  115. <!-- <el-col :span="12">
  116. <el-form-item label="用途" prop="useTo" style="margin-bottom: 22px">
  117. <el-input
  118. type="textarea"
  119. resize="none"
  120. v-model="form.useTo"
  121. :disabled="!!form.requirementCode"
  122. :rows="2"
  123. placeholder="请输入"
  124. size="small"
  125. maxlength="200"
  126. ></el-input>
  127. </el-form-item>
  128. </el-col> -->
  129. <el-col :span="12">
  130. <el-form-item prop="files" label="附件">
  131. <fileUpload
  132. v-model="form.files"
  133. module="main"
  134. :showLib="false"
  135. :limit="1"
  136. />
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="12">
  140. <el-form-item prop="remark" label="备注">
  141. <el-input
  142. type="textarea"
  143. resize="none"
  144. v-model="form.remark"
  145. :rows="2"
  146. placeholder="请输入"
  147. size="small"
  148. maxlength="200"
  149. ></el-input>
  150. </el-form-item>
  151. </el-col>
  152. </el-row>
  153. </el-form>
  154. <div slot="footer" class="footer">
  155. <el-button type="primary" @click="save">保存</el-button>
  156. <el-button @click="cancel">返回</el-button>
  157. </div>
  158. <headerTitle title="计划清单" style="margin-top: 15px"></headerTitle>
  159. <inventoryTable
  160. ref="inventoryTable"
  161. :delDetailIds="delDetailIds"
  162. ></inventoryTable>
  163. <purchaseNeedList
  164. ref="purchaseNeedList"
  165. @changeParent="changeParent"
  166. ></purchaseNeedList>
  167. <staffSelection
  168. ref="staffSelection"
  169. @confirm="confirmStaffSelection"
  170. ></staffSelection>
  171. </ele-modal>
  172. </template>
  173. <script>
  174. import inventoryTable from '@/views/purchasingManage/purchaseNeedManage/components/inventoryTable.vue';
  175. import purchaseNeedList from './purchaseNeed-list.vue';
  176. import staffSelection from './staffSelection.vue';
  177. import fileUpload from '@/components/upload/fileUpload';
  178. import dictMixins from '@/mixins/dictMixins';
  179. import personSelect from '@/components/CommomSelect/person-select.vue';
  180. import { getDetail } from '@/api/purchasingManage/purchaseNeedManage';
  181. import {
  182. getplanDetail,
  183. UpdateInformation,
  184. addPurchaseplanManage
  185. } from '@/api/purchasingManage/purchasePlanManage';
  186. import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
  187. import { copyObj } from '@/utils/util';
  188. import { listOrganizations } from '@/api/system/organization';
  189. import { getFile } from '@/api/system/file';
  190. export default {
  191. props: {
  192. categoryTreeList: Array
  193. },
  194. mixins: [dictMixins],
  195. components: {
  196. fileUpload,
  197. headList,
  198. inventoryTable,
  199. purchaseNeedList,
  200. personSelect,
  201. staffSelection
  202. },
  203. data() {
  204. let formDef = {
  205. id: '',
  206. expectReceiveDate: null,
  207. remark: null,
  208. requireDeptId: '',
  209. requireUserId: '',
  210. sourceCode: '',
  211. sourceId: '',
  212. sourceType: '',
  213. files: [],
  214. responsibleName: '',
  215. responsibleId: '',
  216. requirementId: '',
  217. acceptUnpack: 1
  218. };
  219. return {
  220. visible: false,
  221. title: '',
  222. detailList: [],
  223. delDetailIds: [],
  224. formDef,
  225. form: copyObj(formDef),
  226. selectList: [],
  227. acceptUnpackList: [
  228. {
  229. label: '接受',
  230. value: 1
  231. },
  232. {
  233. label: '不接受',
  234. value: 0
  235. }
  236. ],
  237. columns: [
  238. {
  239. width: 45,
  240. type: 'index',
  241. columnKey: 'index',
  242. align: 'center',
  243. fixed: 'left'
  244. },
  245. {
  246. width: 150,
  247. prop: 'productCategoryName',
  248. label: '分类',
  249. slot: 'productCategoryName'
  250. },
  251. {
  252. width: 140,
  253. prop: 'productCode',
  254. label: '编码',
  255. slot: 'productCode'
  256. },
  257. {
  258. width: 240,
  259. prop: 'productName',
  260. label: '名称',
  261. slot: 'productName'
  262. },
  263. {
  264. width: 150,
  265. prop: 'productBrand',
  266. label: '牌号',
  267. slot: 'productBrand'
  268. },
  269. {
  270. width: 80,
  271. prop: 'totalCount',
  272. label: '数量',
  273. slot: 'totalCount'
  274. },
  275. {
  276. width: 100,
  277. prop: 'measuringUnit',
  278. label: '单位',
  279. slot: 'measuringUnit'
  280. },
  281. {
  282. width: 130,
  283. prop: 'modelType',
  284. label: '型号',
  285. slot: 'modelType'
  286. },
  287. {
  288. width: 120,
  289. prop: 'specification',
  290. label: '规格',
  291. slot: 'specification'
  292. },
  293. {
  294. width: 130,
  295. prop: 'brand',
  296. label: '品牌',
  297. slot: 'brand'
  298. },
  299. {
  300. width: 170,
  301. prop: 'expectReceiveDate',
  302. label: '到货日期',
  303. slot: 'expectReceiveDate'
  304. },
  305. {
  306. width: 140,
  307. prop: 'files',
  308. label: '附件',
  309. slot: 'files'
  310. },
  311. {
  312. width: 220,
  313. prop: 'remark',
  314. label: '备注',
  315. slot: 'remark'
  316. }
  317. ],
  318. rules: {
  319. responsibleName: [
  320. { required: true, message: '请选择责任人', trigger: 'change' }
  321. ],
  322. requireDeptId: [
  323. { required: true, message: '请选择需求部门', trigger: 'change' }
  324. ],
  325. requireUserId: [
  326. { required: true, message: '请选择需求人', trigger: 'change' }
  327. ],
  328. expectReceiveDate: [
  329. { required: true, message: '请选择到货日期', trigger: 'change' }
  330. ],
  331. sourceId: [
  332. { required: true, message: '请选择需求来源类型', trigger: 'change' }
  333. ]
  334. },
  335. // 提交状态
  336. loading: false,
  337. // 是否是修改
  338. isUpdate: false,
  339. // 组织机构树形结构数据
  340. groupTreeData: [],
  341. // 组织机构平铺数据
  342. groupData: []
  343. };
  344. },
  345. created() {},
  346. methods: {
  347. listFormatte(data) {
  348. return data.filter((item) => item.dictCode != 1);
  349. },
  350. // 获取公司数据
  351. getGroupAll() {
  352. listOrganizations().then((list) => {
  353. this.groupData = list;
  354. this.groupTreeData = this.$util.toTreeData({
  355. data: list,
  356. idField: 'id',
  357. parentIdField: 'parentId'
  358. });
  359. });
  360. },
  361. // 选择负责人部门
  362. change_principalDep(id) {
  363. const info = this.groupData.find((e) => e.id == id);
  364. this.form.requireDeptName = info.name;
  365. this.form.requireUserId = '';
  366. this.form.requireUserName = '';
  367. // 根据部门获取人员
  368. this.$nextTick(() => {});
  369. this.getrequireUser(id);
  370. },
  371. getrequireUser(groupId) {
  372. if (groupId) {
  373. this.$refs.directorRef.getList({ groupId });
  374. }
  375. },
  376. salesmanChange(val, info) {
  377. this.form.requireUserName = info.name;
  378. },
  379. openStaffSelection() {
  380. this.$refs.staffSelection.open(
  381. this.form.responsibleName
  382. ? [{ name: this.form.responsibleName, id: this.form.responsibleId }]
  383. : []
  384. );
  385. },
  386. confirmStaffSelection(data) {
  387. this.form.responsibleName = (data && data[0].name) || '';
  388. this.form.responsibleId = (data && data[0].id) || '';
  389. },
  390. //获取计划详情
  391. async getplanData(id) {
  392. this.loading = true;
  393. let data = await getplanDetail(id);
  394. this.loading = false;
  395. if (data) {
  396. this.$nextTick(() => {
  397. this.form = data;
  398. this.$refs.inventoryTable &&
  399. this.$refs.inventoryTable.putTableValue(data.detailList);
  400. // 根据部门获取人员
  401. this.getrequireUser(this.form.requireDeptId);
  402. });
  403. }
  404. },
  405. //获取需求详情
  406. async getDetailData(id, type = '') {
  407. this.loading = true;
  408. let data = await getDetail(id);
  409. this.loading = false;
  410. if (data) {
  411. this.$nextTick(() => {
  412. for (let key in data) {
  413. if (key != 'id') {
  414. this.form[key] = data[key];
  415. } else {
  416. this.form.requirementId = data[key];
  417. }
  418. }
  419. this.$refs.inventoryTable &&
  420. this.$refs.inventoryTable.putTableValue(data.detailList);
  421. // 根据部门获取人员
  422. this.getrequireUser(this.form.requireDeptId);
  423. });
  424. }
  425. },
  426. async open(type, row, contactCategoryId) {
  427. this.title = type === 'add' ? '新增' : '修改';
  428. this.row = row;
  429. this.visible = true;
  430. if (type == 'add') {
  431. this.isUpdate = false;
  432. if (row.id) {
  433. this.getDetailData(row.id);
  434. }
  435. } else {
  436. this.isUpdate = true;
  437. }
  438. this.init(row.id);
  439. },
  440. getValidate() {
  441. return Promise.all([
  442. new Promise((resolve, reject) => {
  443. this.$refs.form.validate((valid) => {
  444. if (!valid) {
  445. reject(false);
  446. } else {
  447. resolve(true);
  448. }
  449. });
  450. }),
  451. new Promise((resolve, reject) => {
  452. this.$refs.inventoryTable.validateForm((valid) => {
  453. if (!valid) {
  454. reject(false);
  455. } else {
  456. resolve(true);
  457. }
  458. });
  459. })
  460. ]);
  461. },
  462. //选择产品
  463. handParent() {
  464. this.$refs.purchaseNeedList.open(this.form.requirementCode);
  465. },
  466. changeParent(data) {
  467. this.getDetailData(data.id);
  468. },
  469. async save() {
  470. try {
  471. await this.getValidate();
  472. // 表单验证通过,执行保存操作
  473. this.loading = true;
  474. if (this.$refs.inventoryTable.getTableValue().length == 0) {
  475. this.$message.warning('计划清单不能为空');
  476. return;
  477. }
  478. if (!this.isUpdate) {
  479. delete this.form.id;
  480. }
  481. this.form.sourceTypeName = this.getDictValue(
  482. '需求来源类型',
  483. this.form.sourceType
  484. );
  485. this.form.files = this.form.files || [];
  486. let commitData = Object.assign({}, this.form, {
  487. detailList: this.$refs.inventoryTable.getTableValue()
  488. });
  489. if (this.isUpdate) {
  490. UpdateInformation(commitData)
  491. .then((res) => {
  492. this.loading = false;
  493. this.$message.success('修改成功');
  494. this.cancel();
  495. this.$emit('done');
  496. })
  497. .catch((e) => {
  498. //this.loading = false;
  499. });
  500. } else {
  501. addPurchaseplanManage(commitData)
  502. .then((res) => {
  503. this.loading = false;
  504. this.$message.success('新增成功');
  505. this.cancel();
  506. this.$emit('done');
  507. })
  508. .catch((e) => {
  509. //this.loading = false;
  510. });
  511. }
  512. } catch (error) {
  513. console.log(error);
  514. // 表单验证未通过,不执行保存操作
  515. }
  516. },
  517. downloadFile(file) {
  518. getFile({ objectName: file.storePath }, file.name);
  519. },
  520. cancel() {
  521. this.$nextTick(() => {
  522. this.activeName = 'base';
  523. // 关闭后,销毁所有的表单数据
  524. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  525. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  526. this.form = copyObj(this.formDef);
  527. this.visible = false;
  528. });
  529. },
  530. async init(id) {
  531. await this.getGroupAll();
  532. if (id) await this.getplanData(id);
  533. }
  534. }
  535. };
  536. </script>
  537. <style scoped lang="scss">
  538. .TotalAmount {
  539. font-size: 16px;
  540. padding-right: 30px;
  541. }
  542. </style>