addDialog.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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" style="height: 58px">
  16. <el-form-item label="需求类型" prop="sourceType">
  17. <DictSelection
  18. dictName="需求来源类型"
  19. clearable
  20. v-model="form.sourceType"
  21. :listFormatte="listFormatte"
  22. >
  23. </DictSelection>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="12">
  27. <el-form-item
  28. label="需求部门"
  29. prop="requireDeptId"
  30. style="margin-bottom: 22px"
  31. >
  32. <ele-tree-select
  33. clearable
  34. :data="groupTreeData"
  35. v-model="form.requireDeptId"
  36. valueKey="id"
  37. labelKey="name"
  38. placeholder="请选择"
  39. @change="change_principalDep"
  40. default-expand-all
  41. />
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="12">
  45. <el-form-item
  46. label="需求人"
  47. prop="requireUserId"
  48. style="margin-bottom: 22px"
  49. >
  50. <personSelect
  51. ref="directorRef"
  52. v-model="form.requireUserId"
  53. @selfChange="salesmanChange"
  54. :init="false"
  55. />
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="12">
  59. <el-form-item prop="remark" label="是否接受拆单" label-width="120px">
  60. <el-select
  61. v-model="form.acceptUnpack"
  62. placeholder="请选择"
  63. clearable
  64. style="width: 100%"
  65. >
  66. <el-option
  67. v-for="item in acceptUnpackList"
  68. :key="item.value"
  69. :label="item.label"
  70. :value="item.value"
  71. >
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="12">
  77. <el-form-item label="用途" prop="useTo">
  78. <el-input
  79. type="textarea"
  80. resize="none"
  81. v-model="form.useTo"
  82. :rows="2"
  83. placeholder="请输入"
  84. size="small"
  85. maxlength="200"
  86. ></el-input>
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="12">
  90. <el-form-item prop="remark" label="备注">
  91. <el-input
  92. type="textarea"
  93. resize="none"
  94. v-model="form.remark"
  95. :rows="2"
  96. placeholder="请输入"
  97. size="small"
  98. maxlength="200"
  99. ></el-input>
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="12">
  103. <el-form-item prop="files" label="附件">
  104. <fileUpload
  105. v-model="form.files"
  106. module="main"
  107. :showLib="false"
  108. :limit="1"
  109. />
  110. </el-form-item>
  111. </el-col>
  112. </el-row>
  113. </el-form>
  114. <div slot="footer" class="footer">
  115. <el-button type="primary" @click="save">保存</el-button>
  116. <el-button type="primary" @click="save('sub')">提交</el-button>
  117. <el-button @click="cancel">返回</el-button>
  118. </div>
  119. <headerTitle title="需求清单"></headerTitle>
  120. <inventoryTable
  121. ref="inventoryTable"
  122. :delDetailIds="delDetailIds"
  123. ></inventoryTable>
  124. </ele-modal>
  125. </template>
  126. <script>
  127. import inventoryTable from './inventoryTable.vue';
  128. import fileUpload from '@/components/upload/fileUpload';
  129. import dictMixins from '@/mixins/dictMixins';
  130. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  131. import personSelect from '@/components/CommomSelect/person-select.vue';
  132. import parentList from '@/views/saleManage/contact/components/parentList.vue';
  133. import {
  134. addPurchaseNeedManage,
  135. getDetail,
  136. UpdateInformation,
  137. submit
  138. } from '@/api/purchasingManage/purchaseNeedManage';
  139. import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
  140. import { copyObj } from '@/utils/util';
  141. import { listOrganizations } from '@/api/system/organization';
  142. export default {
  143. props: {
  144. categoryTreeList: Array
  145. },
  146. mixins: [dictMixins],
  147. components: {
  148. fileUpload,
  149. headList,
  150. inventoryTable,
  151. deptSelect,
  152. parentList,
  153. personSelect
  154. },
  155. data() {
  156. let formDef = {
  157. id: '',
  158. receiveDate: null,
  159. remark: null,
  160. requireDeptId: '',
  161. requireUserId: '',
  162. sourceCode: '',
  163. sourceId: '',
  164. sourceType: '',
  165. files: [],
  166. acceptUnpack: 1
  167. };
  168. return {
  169. visible: false,
  170. title: '',
  171. delDetailIds: [],
  172. formDef,
  173. form: copyObj(formDef),
  174. acceptUnpackList: [
  175. {
  176. label: '接受',
  177. value: 1
  178. },
  179. {
  180. label: '不接受',
  181. value: 0
  182. }
  183. ],
  184. rules: {
  185. requireDeptId: [
  186. { required: true, message: '请选择需求部门', trigger: 'change' }
  187. ],
  188. requireUserId: [
  189. { required: true, message: '请选择需求人', trigger: 'change' }
  190. ],
  191. useTo: [{ required: true, message: '请输入用途', trigger: 'change' }],
  192. sourceType: [
  193. { required: true, message: '请选择需求类型', trigger: 'change' }
  194. ]
  195. },
  196. // 提交状态
  197. loading: false,
  198. // 是否是修改
  199. isUpdate: false,
  200. // 组织机构树形结构数据
  201. groupTreeData: [],
  202. // 组织机构平铺数据
  203. groupData: [],
  204. businessId: ''
  205. };
  206. },
  207. created() {
  208. this.getGroupAll();
  209. },
  210. methods: {
  211. listFormatte(data) {
  212. return data.filter((item) => item.dictCode != 1);
  213. },
  214. // 获取公司数据
  215. getGroupAll() {
  216. listOrganizations().then((list) => {
  217. this.groupData = list;
  218. this.groupTreeData = this.$util.toTreeData({
  219. data: list,
  220. idField: 'id',
  221. parentIdField: 'parentId'
  222. });
  223. });
  224. },
  225. // 选择负责人部门
  226. change_principalDep(id) {
  227. const info = this.groupData.find((e) => e.id == id);
  228. this.form.requireDeptName = info.name;
  229. this.form.requireUserId = '';
  230. this.form.requireUserName = '';
  231. // 根据部门获取人员
  232. this.$nextTick(() => {});
  233. this.getrequireUser(id);
  234. },
  235. // //选择需求来源类型
  236. // chaengSource(data) {
  237. // this.form.sourceType = data?.dictValue;
  238. // },
  239. getrequireUser(groupId) {
  240. if (groupId) {
  241. this.$refs.directorRef.getList({ groupId });
  242. }
  243. },
  244. salesmanChange(val, info) {
  245. this.form.requireUserName = info.name;
  246. },
  247. //获取详情
  248. async getDetailData(id) {
  249. this.businessId = id;
  250. this.loading = true;
  251. const data = await getDetail(id);
  252. this.loading = false;
  253. if (data) {
  254. this.$nextTick(() => {
  255. this.form = data;
  256. // if (data.files !== '') {
  257. // this.$set(this.form, 'files', data?.files);
  258. // }
  259. // 根据部门获取人员
  260. this.$refs.inventoryTable &&
  261. this.$refs.inventoryTable.putTableValue(data.detailList);
  262. this.getrequireUser(this.form.requireDeptId);
  263. });
  264. }
  265. },
  266. async open(type, row, contactCategoryId) {
  267. this.title = type === 'add' ? '新增' : '修改';
  268. this.row = row;
  269. this.visible = true;
  270. if (type == 'add') {
  271. this.isUpdate = false;
  272. this.$nextTick(() => {
  273. this.form.requireDeptId = this.$store.getters.user.info.groupId;
  274. this.form.requireUserId = this.$store.getters.user.info.userId;
  275. this.form.requireDeptName = this.$store.getters.user.info.groupName;
  276. this.form.requireUserName = this.$store.getters.user.info.name;
  277. this.getrequireUser(this.form.requireDeptId);
  278. });
  279. } else {
  280. this.isUpdate = true;
  281. this.getDetailData(row.id);
  282. }
  283. },
  284. getValidate() {
  285. return Promise.all([
  286. new Promise((resolve, reject) => {
  287. this.$refs.form.validate((valid) => {
  288. if (!valid) {
  289. reject(false);
  290. } else {
  291. resolve(true);
  292. }
  293. });
  294. }),
  295. new Promise((resolve, reject) => {
  296. this.$refs.inventoryTable.validateForm((valid) => {
  297. if (!valid) {
  298. reject(false);
  299. } else {
  300. resolve(true);
  301. }
  302. });
  303. })
  304. ]);
  305. },
  306. async save(type) {
  307. try {
  308. await this.getValidate();
  309. // 表单验证通过,执行保存操作
  310. this.loading = true;
  311. let isArrivalBatch = false;
  312. let detailList = this.$refs.inventoryTable.getTableValue();
  313. if (!this.isUpdate) {
  314. delete this.form.id;
  315. }
  316. if (detailList.length == 0) {
  317. this.$message.warning('需求清单不能为空');
  318. return;
  319. }
  320. detailList.forEach((v) => {
  321. if (
  322. v.arrivalWay == 2 &&
  323. (!v.arrivalBatch || v.arrivalBatch.length == 0)
  324. ) {
  325. isArrivalBatch = true;
  326. }
  327. });
  328. if (isArrivalBatch) {
  329. this.$message.warning('请设置分批时间');
  330. return;
  331. }
  332. this.form.files = this.form.files || [];
  333. this.form.sourceTypeName = this.getDictValue(
  334. '需求来源类型',
  335. this.form.sourceType
  336. );
  337. let commitData = Object.assign({}, this.form, {
  338. detailList
  339. });
  340. if (this.isUpdate) {
  341. UpdateInformation(commitData)
  342. .then((res) => {
  343. this.loading = false;
  344. this.$message.success('修改成功');
  345. if (type === 'sub') {
  346. this.saleOrderSubmit(res);
  347. return;
  348. }
  349. this.cancel();
  350. this.$emit('done');
  351. })
  352. .catch((e) => {
  353. //this.loading = false;
  354. });
  355. } else {
  356. addPurchaseNeedManage(commitData)
  357. .then((res) => {
  358. this.loading = false;
  359. this.$message.success('新增成功');
  360. if (type === 'sub') {
  361. this.saleOrderSubmit(res);
  362. return;
  363. }
  364. this.cancel();
  365. this.$emit('done');
  366. })
  367. .catch((e) => {
  368. //this.loading = false;
  369. });
  370. }
  371. } catch (error) {
  372. console.log(error);
  373. // 表单验证未通过,不执行保存操作
  374. }
  375. },
  376. saleOrderSubmit(res) {
  377. submit({
  378. businessId: this.businessId || res
  379. // productionSupervisorId
  380. }).then((res) => {
  381. this.cancel();
  382. this.$emit('done');
  383. });
  384. },
  385. cancel() {
  386. this.$nextTick(() => {
  387. this.activeName = 'base';
  388. // 关闭后,销毁所有的表单数据
  389. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  390. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  391. this.form = copyObj(this.formDef);
  392. this.visible = false;
  393. });
  394. }
  395. }
  396. };
  397. </script>
  398. <style scoped lang="scss">
  399. .TotalAmount {
  400. font-size: 16px;
  401. padding-right: 30px;
  402. }
  403. </style>