addDialog.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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. :append-to-body="true"
  10. width="70%"
  11. :maxable="true"
  12. :resizable="true"
  13. @close="cancel"
  14. >
  15. <el-form
  16. ref="form"
  17. :model="form"
  18. :rules="rules"
  19. label-width="120px"
  20. class="el-form-box"
  21. >
  22. <headerTitle title="基本信息"></headerTitle>
  23. <el-row :gutter="12">
  24. <el-col :span="12">
  25. <el-form-item label="类型" prop="type">
  26. <el-select
  27. v-model="form.type"
  28. placeholder="请选择"
  29. style="width: 100%"
  30. @change="handleTypeChange"
  31. >
  32. <el-option
  33. v-for="item in typeOptions"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="询价方名称" prop="contactName">
  41. <el-input
  42. clearable
  43. v-model="form.contactName"
  44. @click.native="handParent"
  45. :disabled="!!contactData.id || !!businessOpportunityData.id"
  46. placeholder="请输入"
  47. />
  48. </el-form-item>
  49. <el-form-item label="有无商机" prop="opportunityType">
  50. <el-select
  51. v-model="form.opportunityType"
  52. placeholder="请选择"
  53. style="width: 100%"
  54. @change="opportunityTypeChange"
  55. :disabled="!!businessOpportunityData.id"
  56. >
  57. <el-option
  58. v-for="item in opportunityTypeList"
  59. :key="item.value"
  60. :label="item.label"
  61. :value="item.value"
  62. >
  63. </el-option>
  64. </el-select>
  65. </el-form-item>
  66. <el-form-item
  67. label="关联商机"
  68. prop="opportunityId"
  69. :rules="[
  70. {
  71. required: form.opportunityType === 1 ? true : false,
  72. message: '请选择关联商机',
  73. trigger: 'change'
  74. }
  75. ]"
  76. >
  77. <el-select
  78. :disabled="
  79. form.opportunityType === 0 || !!businessOpportunityData.id
  80. "
  81. v-model="form.opportunityId"
  82. placeholder="请选择"
  83. style="width: 100%"
  84. @change="opportunityChange"
  85. >
  86. <el-option
  87. v-for="item in businessList"
  88. :key="item.id"
  89. :label="item.name"
  90. :value="item.id"
  91. >
  92. </el-option>
  93. </el-select>
  94. </el-form-item>
  95. <el-form-item label="询价方联系人" prop="contactLinkName">
  96. <el-autocomplete
  97. v-model="form.contactLinkName"
  98. :fetch-suggestions="queryContactLink"
  99. @select="handleContactSelect"
  100. @input="handleContactInput"
  101. placeholder="请输入或选择询价方联系人"
  102. style="width: 100%"
  103. clearable
  104. ></el-autocomplete>
  105. </el-form-item>
  106. <el-form-item label="询价方电话" prop="contactTel">
  107. <el-input
  108. clearable
  109. :maxlength="20"
  110. v-model="form.contactTel"
  111. placeholder="请输入"
  112. />
  113. </el-form-item>
  114. <el-form-item label="询价方传真" prop="contactFax">
  115. <el-input
  116. clearable
  117. v-model="form.contactFax"
  118. placeholder="请输入"
  119. />
  120. </el-form-item>
  121. <el-form-item label=" 询价方Email" prop="contactEmail">
  122. <el-input
  123. clearable
  124. v-model="form.contactEmail"
  125. placeholder="请输入"
  126. />
  127. </el-form-item>
  128. <el-form-item label="询价方地址" prop="contactAddress">
  129. <el-input
  130. clearable
  131. v-model="form.contactAddress"
  132. placeholder="请输入"
  133. />
  134. </el-form-item>
  135. <el-form-item label="结算方式" prop="settlementMode">
  136. <DictSelection
  137. dictName="结算方式"
  138. clearable
  139. v-model="form.settlementMode"
  140. >
  141. </DictSelection>
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="12">
  145. <el-form-item label="报价方名称" prop="quoteName">
  146. <el-input
  147. v-if="enterprisePage.length <= 1"
  148. clearable
  149. v-model="form.quoteName"
  150. placeholder="请输入"
  151. />
  152. <el-select
  153. v-if="enterprisePage.length > 1"
  154. style="width: 100%"
  155. v-model="form.quoteName"
  156. placeholder="请选择"
  157. @change="getEnterprise()"
  158. >
  159. <el-option
  160. v-for="item in enterprisePage"
  161. :key="item.id"
  162. :label="item.name"
  163. :value="item.name"
  164. >
  165. </el-option>
  166. </el-select>
  167. </el-form-item>
  168. <el-form-item label="报价方联系人" prop="quoteLinkName">
  169. <el-input
  170. clearable
  171. v-model="form.quoteLinkName"
  172. @click.native="handHead()"
  173. placeholder="请输入"
  174. />
  175. </el-form-item>
  176. <el-form-item prop="quoteTel" label="报价方联系电话">
  177. <el-input clearable v-model="form.quoteTel" placeholder="请输入" />
  178. </el-form-item>
  179. <el-form-item prop="quoteFax" label="报价方传真">
  180. <el-input clearable v-model="form.quoteFax" placeholder="请输入" />
  181. </el-form-item>
  182. <el-form-item label="报价方Email" prop="quoteEmail">
  183. <el-input
  184. clearable
  185. v-model="form.quoteEmail"
  186. placeholder="请输入"
  187. />
  188. </el-form-item>
  189. <el-form-item label="报价方地址" prop="quoteAddress">
  190. <el-input
  191. clearable
  192. v-model="form.quoteAddress"
  193. placeholder="请输入"
  194. />
  195. </el-form-item>
  196. <el-form-item prop="askFile" label="附件">
  197. <fileMain v-model="form.askFile"></fileMain>
  198. </el-form-item>
  199. <el-form-item label="是否接受拆单" prop="acceptUnpack">
  200. <el-select
  201. v-model="form.acceptUnpack"
  202. placeholder="请选择"
  203. style="width: 100%"
  204. >
  205. <el-option
  206. v-for="item in acceptUnpackoptions"
  207. :key="item.value"
  208. :label="item.label"
  209. :value="item.value"
  210. >
  211. </el-option>
  212. </el-select>
  213. </el-form-item>
  214. </el-col>
  215. </el-row>
  216. <headerTitle title="报价单物品清单"></headerTitle>
  217. <inventoryTable
  218. ref="inventoryTable"
  219. :customerMark="form.customerMark"
  220. :isTemporary="true"
  221. :isDiscount="false"
  222. :cacheKeyUrl="cacheKeyUrl"
  223. :quoteType="form.type"
  224. :isHideProductionRequirements="true"
  225. :rowActionWidth="260"
  226. >
  227. <!-- 行内操作:BOM导入 / BOM详情(仅报价单传入,其它单据不受影响) -->
  228. <template v-slot:rowActions="{ row, index }">
  229. <el-link
  230. type="primary"
  231. :underline="false"
  232. icon="el-icon-upload2"
  233. @click="openBomImport(row, index)"
  234. >
  235. BOM导入
  236. </el-link>
  237. <el-link
  238. type="primary"
  239. :underline="false"
  240. icon="el-icon-document"
  241. @click="openBomDetail(row, index)"
  242. >
  243. BOM详情<span v-if="bomCount(row)">({{ bomCount(row) }})</span>
  244. </el-link>
  245. </template>
  246. </inventoryTable>
  247. <!-- <el-row style="margin-top: 20px">
  248. <el-col :span="6">
  249. <el-form-item prop="taxRate" label="税率">
  250. <el-input clearable v-model="form.taxRate" placeholder="请输入">
  251. <template slot="append">%</template>
  252. </el-input>
  253. </el-form-item>
  254. </el-col>
  255. <el-col :span="6">
  256. <el-form-item prop="deliveryDate" label="交货日期">
  257. <el-date-picker
  258. v-model="form.deliveryDate"
  259. value-format="yyyy-MM-dd"
  260. placeholder="请选择交货日期"
  261. type="date"
  262. style="width: 100%"
  263. class="filter-item"
  264. ></el-date-picker>
  265. </el-form-item>
  266. </el-col>
  267. </el-row> -->
  268. </el-form>
  269. <div slot="footer" class="footer">
  270. <el-button type="primary" @click="save" v-click-once>保存</el-button>
  271. <el-button
  272. type="primary"
  273. @click="isNeed_process_is_close && save('sub')"
  274. v-click-once
  275. >提交</el-button
  276. >
  277. <el-button @click="cancel">返回</el-button>
  278. </div>
  279. <parentList
  280. ref="parentRef"
  281. classType="1"
  282. @changeParent="changeParent"
  283. ></parentList>
  284. <head-list ref="headRef" @changeParent="changePersonel"></head-list>
  285. <process-submit-dialog
  286. api-fun-name="quoteUpdateStatusAPI"
  287. :processSubmitDialogFlag.sync="processSubmitDialogFlag"
  288. v-if="processSubmitDialogFlag"
  289. ref="processSubmitDialogRef"
  290. @reload="reload"
  291. ></process-submit-dialog>
  292. <bom-import-dialog
  293. ref="bomImportDialogRef"
  294. @success="handleBomImported"
  295. ></bom-import-dialog>
  296. <bom-detail-dialog ref="bomDetailDialogRef"></bom-detail-dialog>
  297. </ele-modal>
  298. </template>
  299. <script>
  300. import { emailReg, phoneReg, numberReg, telReg } from 'ele-admin';
  301. import { acceptUnpackoptions } from '@/enum/dict';
  302. import inventoryTable from '@/BIZComponents/inventoryTable.vue';
  303. import { categoryData } from 'element-china-category-data';
  304. import fileUpload from '@/components/upload/fileUpload';
  305. import { cityData } from 'ele-admin/packages/utils/regions';
  306. import dictMixins from '@/mixins/dictMixins';
  307. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  308. import personSelect from '@/components/CommomSelect/person-select.vue';
  309. import parentList from '@/views/saleManage/contact/components/parentList.vue';
  310. import {
  311. getDetail,
  312. UpdateInformation,
  313. addInformation,
  314. submit
  315. } from '@/api/saleManage/quotation';
  316. import {
  317. getOpportunityDetail,
  318. isHasGeneratedQuoteAPI
  319. } from '@/api/saleManage/businessOpportunity';
  320. import { getTableList } from '@/api/saleManage/businessOpportunity';
  321. import { enterprisePage } from '@/api/contractManage/contractBook';
  322. import { listOrganizations } from '@/api/system/organization';
  323. import { getcontactlink } from '@/api/saleManage/businessFollow';
  324. import headList from '@/BIZComponents/user-select/user-select.vue';
  325. import { copyObj } from '@/utils/util';
  326. import { contactDetail, updateRelationStatus } from '@/api/saleManage/contact';
  327. // import fileMain from '@/components/addDoc/index.vue';
  328. import processSubmitDialog from '@/BIZComponents/processSubmitDialog/processSubmitDialog.vue';
  329. import bomImportDialog from './bomImportDialog.vue';
  330. import bomDetailDialog from './bomDetailDialog.vue';
  331. import { buildRowKey } from '@/utils/quotationBom';
  332. export default {
  333. props: {
  334. categoryTreeList: Array,
  335. contactData: {
  336. default: () => {
  337. return {};
  338. }
  339. },
  340. businessOpportunityData: {
  341. default: () => {
  342. return {};
  343. }
  344. }
  345. },
  346. mixins: [dictMixins],
  347. components: {
  348. processSubmitDialog,
  349. // fileMain,
  350. fileUpload,
  351. headList,
  352. inventoryTable,
  353. deptSelect,
  354. parentList,
  355. personSelect,
  356. bomImportDialog,
  357. bomDetailDialog
  358. },
  359. data() {
  360. let formDef = {
  361. id: '',
  362. acceptUnpack: 1,
  363. askFile: [],
  364. contactAddress: '',
  365. opportunityId: '',
  366. contactEmail: '',
  367. contactFax: '',
  368. contactId: '',
  369. contactLinkId: '',
  370. contactLinkName: '',
  371. contactName: '',
  372. contactTel: '',
  373. deliveryDate: '',
  374. settlementMode: '',
  375. settlementModeName: '',
  376. quoteAddress: '',
  377. quoteEmail: '',
  378. quoteFax: '',
  379. quoteLinkId: '',
  380. quoteLinkName: '',
  381. quoteName: '',
  382. quoteTel: '',
  383. taxRate: null,
  384. totalPrice: null,
  385. opportunityType: null,
  386. type: 1
  387. };
  388. return {
  389. fullscreen: false,
  390. cacheKeyUrl: 'eos-saleManage-quotation-inventoryTable',
  391. opportunityTypeList: [
  392. { label: '有', value: 1 },
  393. { label: '无', value: 0 }
  394. ],
  395. typeOptions: [
  396. { label: '产品销售', value: 1 },
  397. { label: '生产加工', value: 2 }
  398. ],
  399. payWayOptions: [],
  400. delDetailIds: [],
  401. linkNameOptions: [],
  402. acceptUnpackoptions,
  403. visible: false,
  404. processSubmitDialogFlag: false,
  405. title: '',
  406. row: {},
  407. activeName: 'base',
  408. formDef,
  409. form: copyObj(formDef),
  410. // removeBankList: [],
  411. // removeLinkList: [],
  412. tableBankData: [],
  413. tableLinkData: [],
  414. businessList: [], //商机列表
  415. rules: {
  416. // opportunityId: [
  417. // { required: true, message: '请选择关联商机', trigger: 'change' }
  418. // ],
  419. contactName: [
  420. { required: true, message: '请选择客户', trigger: 'change' }
  421. ],
  422. name: [{ required: true, message: '请输入客户名称', trigger: 'blur' }],
  423. contactLinkName: [
  424. { required: true, message: '请选择联系人', trigger: 'change' }
  425. ],
  426. acceptUnpack: [
  427. { required: true, message: '请选择是否接受', trigger: 'change' }
  428. ],
  429. type: [{ required: true, message: '请选择类型', trigger: 'change' }],
  430. contactTel: [
  431. // {
  432. // required: true,
  433. // pattern: phoneReg,
  434. // message: '请输入联系电话',
  435. // trigger: 'blur'
  436. // },
  437. {
  438. required: true, // 只保留必填校验
  439. message: '请输入联系电话', // 提示文字不变(仅提示必填)
  440. trigger: 'blur' // 触发时机(失去焦点时校验)
  441. }
  442. ],
  443. deliveryDate: [
  444. { required: true, message: '请选择交货日期', trigger: 'change' }
  445. ],
  446. settlementMode: [
  447. { required: true, message: '请选择结算方式', trigger: 'change' }
  448. ],
  449. quoteLinkName: [
  450. { required: true, message: '请输入报价方联系人', trigger: 'change' }
  451. ],
  452. quoteName: [
  453. { required: true, message: '请输入报价方名称', trigger: 'blur' }
  454. ],
  455. quoteTel: [
  456. {
  457. required: true,
  458. pattern: telReg,
  459. message: '请输入报价方联系电话',
  460. trigger: 'blur'
  461. }
  462. ],
  463. quoteEmail: [
  464. { pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur' }
  465. ],
  466. contactEmail: [
  467. { pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur' }
  468. ],
  469. taxRate: [
  470. { pattern: numberReg, message: '请输入数字', trigger: 'blur' }
  471. ]
  472. },
  473. businessId: '',
  474. options: {
  475. cityData,
  476. categoryData
  477. },
  478. // 提交状态
  479. loading: false,
  480. // 是否是修改
  481. isUpdate: false,
  482. // 组织机构树形结构数据
  483. groupTreeData: [],
  484. // 组织机构平铺数据
  485. groupData: [],
  486. enterprisePage: [],
  487. editType: ''
  488. };
  489. },
  490. created() {
  491. this.getGroupAll();
  492. this.getEnterprisePage();
  493. },
  494. methods: {
  495. handleTypeChange() {
  496. // 调用inventoryTable的putTableValue方法,传入空数组清空数据
  497. if (this.$refs.inventoryTable) {
  498. this.$refs.inventoryTable.putTableValue([]);
  499. }
  500. },
  501. opportunityTypeChange() {
  502. if (this.form.opportunityType === 0) {
  503. this.form.opportunityId = '';
  504. }
  505. },
  506. //获取详情
  507. async getDetailData(id) {
  508. this.businessId = id;
  509. this.loading = true;
  510. const data = await getDetail(id);
  511. this.loading = false;
  512. if (data) {
  513. this.$nextTick(() => {
  514. this.form = data;
  515. // if (data.askFile !== '') {
  516. // this.$set(this.form, 'askFile', [data?.askFile]);
  517. // }
  518. if (data.opportunityId) {
  519. this.form.opportunityType = 1;
  520. }
  521. this.$refs.inventoryTable &&
  522. this.$refs.inventoryTable.putTableValue(data);
  523. this.getLinkInfo(data.contactId);
  524. this.getBusinessList(data.contactId);
  525. });
  526. }
  527. },
  528. async opportunityChange(id) {
  529. //是否生成过报价单
  530. let res = await isHasGeneratedQuoteAPI(id);
  531. if (res) this.$message.warning('该商机已生成过报价单,请注意。');
  532. //获取台账库存
  533. getOpportunityDetail(id).then((res) => {
  534. if (res.productList.length > 0) {
  535. this.$refs.inventoryTable &&
  536. this.$refs.inventoryTable.putTableValue(res);
  537. }
  538. });
  539. },
  540. //更新联系人数据
  541. async getLinkInfo(contactId) {
  542. const data = await getcontactlink({ contactId });
  543. if (data && data?.length) {
  544. this.linkNameOptions = data;
  545. let firstLink =
  546. this.linkNameOptions.find((item) => item.ifChief == 1) || {};
  547. this.form = Object.assign({}, this.form, {
  548. contactLinkId: firstLink.id || this.linkNameOptions[0]?.id,
  549. contactLinkName:
  550. firstLink.linkName || this.linkNameOptions[0]?.linkName,
  551. contactTel:
  552. firstLink.mobilePhone || this.linkNameOptions[0]?.mobilePhone,
  553. contactEmail: firstLink.email || this.linkNameOptions[0]?.email
  554. });
  555. console.log(this.form);
  556. }
  557. },
  558. //获取客户的商机列表
  559. async getBusinessList(id) {
  560. if (!this.form.contactId)
  561. return this.$message.error('请先选择询价方名称');
  562. const data = await getTableList({
  563. pageNum: 1,
  564. size: 30,
  565. contactId: id,
  566. approvalStatus: 2,
  567. status: 1
  568. });
  569. this.businessList = data.list;
  570. },
  571. queryContactLink(queryString, callback) {
  572. const filtered = queryString
  573. ? this.linkNameOptions.filter((item) =>
  574. item.linkName.toLowerCase().includes(queryString.toLowerCase())
  575. )
  576. : this.linkNameOptions;
  577. callback(filtered.map((item) => ({ ...item, value: item.linkName })));
  578. },
  579. handleContactSelect(selectedItem) {
  580. this.form.contactLinkId = selectedItem.id;
  581. this.form.contactTel =
  582. selectedItem.mobilePhone || selectedItem.phone || '';
  583. this.form.contactEmail = selectedItem.email || '';
  584. },
  585. handleContactInput() {
  586. const isExist = this.linkNameOptions.some(
  587. (item) => item.linkName === this.form.contactLinkName
  588. );
  589. if (!isExist) {
  590. this.form.contactLinkId = ''; // 手动输入时无对应ID
  591. }
  592. },
  593. handHead() {
  594. let item = {
  595. id: this.form.quoteLinkId
  596. };
  597. this.$refs.headRef.open(item);
  598. },
  599. //选择报价方人回调
  600. changePersonel(obj, index) {
  601. this.$set(this.form, 'quoteLinkId', obj.id);
  602. this.$set(this.form, 'quoteLinkName', obj.name);
  603. this.$set(this.form, 'quoteTel', obj.phone);
  604. this.$set(this.form, 'quoteEmail', obj.email);
  605. },
  606. //选择客户回调
  607. async changeParent(obj, type) {
  608. const { base, other } = await contactDetail(obj.id);
  609. this.form = Object.assign({}, this.form, {
  610. contactId: base.id,
  611. contactName: base.name,
  612. contactAddress: other.addressName + other.address,
  613. contactLinkId: '',
  614. contactLinkName: '',
  615. contactEmail: '',
  616. contactTel: '',
  617. customerMark: base.serialNo
  618. });
  619. this.getLinkInfo(obj.id);
  620. this.getBusinessList(base.id);
  621. if (type == 'init') {
  622. return;
  623. }
  624. this.$nextTick(() => {
  625. if (this.form.opportunityType == 1) {
  626. this.$refs.inventoryTable.putTableValue([]);
  627. this.form.opportunityId = '';
  628. }
  629. this.$refs.inventoryTable.setCustomerMark(base.serialNo);
  630. });
  631. },
  632. handParent() {
  633. let item = {
  634. id: this.form.contactId
  635. };
  636. this.$refs.parentRef.open(item);
  637. },
  638. async open(type, row, contactCategoryId) {
  639. this.title = type === 'add' ? '新增' : type === 'copy' ? '复制' : '修改';
  640. this.editType = type;
  641. this.row = row;
  642. this.visible = true;
  643. if (this.groupData.length == 0) {
  644. await this.getGroupAll();
  645. }
  646. if (this.enterprisePage.length == 0) {
  647. await this.getEnterprisePage();
  648. }
  649. if (type == 'add') {
  650. let userInfo = this.$store.getters.user.info;
  651. this.isUpdate = false;
  652. userInfo.id = userInfo.userId;
  653. this.form.settlementMode = '3';
  654. this.changePersonel(userInfo);
  655. const enterprise = this.getCurrentEnterprise();
  656. if (enterprise) {
  657. this.getEnterprise(enterprise);
  658. }
  659. if (this.contactData.id) {
  660. this.changeParent({ id: this.contactData.id }, 'init');
  661. }
  662. if (this.businessOpportunityData.id) {
  663. this.form.opportunityId = this.businessOpportunityData.id;
  664. await this.opportunityChange(this.businessOpportunityData.id);
  665. this.form.opportunityType = 1;
  666. this.changeParent(
  667. { id: this.businessOpportunityData.contactId },
  668. 'init'
  669. );
  670. }
  671. if (row.id) {
  672. this.form.opportunityId = row.id;
  673. await this.opportunityChange(row.id);
  674. this.form.opportunityType = 1;
  675. this.changeParent({ id: row.contactId }, 'init');
  676. }
  677. } else {
  678. this.isUpdate = true;
  679. await this.getDetailData(row.id);
  680. }
  681. },
  682. getGroupAll() {
  683. return listOrganizations().then((list) => {
  684. this.groupData = list;
  685. });
  686. },
  687. getEnterprisePage() {
  688. return enterprisePage({
  689. pageNum: 1,
  690. size: 100
  691. }).then((res) => {
  692. this.enterprisePage = [];
  693. this.enterprisePage.push(...res.list);
  694. });
  695. },
  696. getCurrentEnterprise() {
  697. let groupId = this.$store.state.user.info?.groupId;
  698. const visitedGroupIds = [];
  699. while (groupId && !visitedGroupIds.includes(groupId)) {
  700. const enterprise = this.enterprisePage.find(
  701. (item) => item.groupId == groupId
  702. );
  703. if (enterprise) {
  704. return enterprise;
  705. }
  706. visitedGroupIds.push(groupId);
  707. const group = this.groupData.find((item) => item.id == groupId);
  708. groupId = group?.parentId;
  709. }
  710. return this.enterprisePage.length === 1 ? this.enterprisePage[0] : null;
  711. },
  712. getEnterprise(enterprise) {
  713. let data =
  714. enterprise ||
  715. this.enterprisePage.find((item) => item.name == this.form.quoteName);
  716. this.form.quoteName = data.name;
  717. // this.form.quoteTel = data.tel;
  718. this.form.quoteFax = data.fax;
  719. this.form.quoteAddress = data.address;
  720. },
  721. salesmanChange(val, info) {
  722. this.otherForm.salesmanName = info.name;
  723. },
  724. ifChiefChange(value, idx) {
  725. if (value === 1) {
  726. this.tableLinkData.forEach((e) => (e.ifChief = 0));
  727. this.tableLinkData[idx].ifChief = 1;
  728. }
  729. },
  730. // getValidate() {
  731. // return new Promise((resolve, reject) => {
  732. // this.$refs.form.validate((valid) => {
  733. // if (!valid) {
  734. // reject(false);
  735. // } else {
  736. // resolve(true);
  737. // }
  738. // });
  739. // });
  740. // },
  741. getValidate() {
  742. return Promise.all([
  743. new Promise((resolve, reject) => {
  744. this.$refs.form.validate((valid) => {
  745. if (!valid) {
  746. reject(false);
  747. } else {
  748. resolve(true);
  749. }
  750. });
  751. }),
  752. new Promise((resolve, reject) => {
  753. this.$refs.inventoryTable.validateForm((valid) => {
  754. if (!valid) {
  755. reject(false);
  756. } else {
  757. resolve(true);
  758. }
  759. });
  760. })
  761. ]);
  762. },
  763. /* ===== BOM导入 / BOM详情 ===== */
  764. bomCount(row) {
  765. return row && Array.isArray(row.bomList) ? row.bomList.length : 0;
  766. },
  767. // 物品清单行的稳定唯一键:已落库行用明细行id,新增行生成 uuid(服务端据此判重覆盖)
  768. bomRowKey(row, index) {
  769. if (!row.rowKey) {
  770. this.$set(row, 'rowKey', buildRowKey(row, index));
  771. }
  772. return row.rowKey;
  773. },
  774. openBomImport(row, index) {
  775. this.$refs.bomImportDialogRef.open({
  776. row: row,
  777. index: index,
  778. quoteId: this.form.id,
  779. rowKey: this.bomRowKey(row, index)
  780. });
  781. },
  782. openBomDetail(row, index) {
  783. this.$refs.bomDetailDialogRef.open({
  784. row: row,
  785. index: index,
  786. quoteId: this.form.id,
  787. rowKey: this.bomRowKey(row, index)
  788. });
  789. },
  790. // 导入成功:BOM 挂到清单行(随报价单一起提交),累计价格回填到该行单价
  791. handleBomImported(payload) {
  792. const row = (payload && payload.row) || {};
  793. const price = (payload && payload.price) || {};
  794. const bomList = (payload && payload.bomList) || [];
  795. this.$set(row, 'bomList', bomList);
  796. this.$set(row, 'singlePrice', price.singlePrice);
  797. this.$set(row, 'notaxSinglePrice', price.notaxSinglePrice);
  798. if (price.taxRate !== null && price.taxRate !== undefined) {
  799. this.$set(row, 'taxRate', price.taxRate);
  800. }
  801. const count = Number(row.totalCount) || 0;
  802. const weight = Number(row.singleWeight) || 0;
  803. // 与清单表自身口径一致:按数量计价 单价×数量;按重量计价 单价×数量×单重
  804. const rowAmount =
  805. Number(row.pricingWay) === 2
  806. ? price.singlePrice * count * weight
  807. : price.singlePrice * count;
  808. this.$set(row, 'totalPrice', Number(rowAmount.toFixed(4)));
  809. // 单价/总价被外部改写后必须让清单表重算「总计」,否则重新导入后总计不刷新
  810. this.$nextTick(() => {
  811. const table = this.$refs.inventoryTable;
  812. if (table && typeof table.changeAll === 'function') {
  813. table.changeAll();
  814. }
  815. });
  816. },
  817. async save(type) {
  818. try {
  819. await this.getValidate();
  820. // 表单验证通过,执行保存操作
  821. this.loading = true;
  822. if (!this.isUpdate) {
  823. delete this.form.id;
  824. }
  825. let settlementModeName = this.getDictValue(
  826. '结算方式',
  827. this.form.settlementMode
  828. );
  829. let commitData = Object.assign({}, this.form, {
  830. settlementModeName,
  831. quoteProductList: this.$refs.inventoryTable.getTableValue(),
  832. totalPrice: this.$refs.inventoryTable.getPrice()[0]
  833. });
  834. if (this.isUpdate && this.editType == 'edit') {
  835. UpdateInformation(commitData)
  836. .then((res) => {
  837. this.loading = false;
  838. updateRelationStatus([this.form.contactId]);
  839. if (type === 'sub') {
  840. this.quotationSubmit(res);
  841. return;
  842. }
  843. this.$message.success('修改成功');
  844. this.cancel();
  845. this.$emit('done');
  846. })
  847. .catch((e) => {
  848. //this.loading = false;
  849. });
  850. } else {
  851. if (this.editType == 'copy') {
  852. console.log('copy~~~~~~')
  853. // 删除quoteProductList中每个对象的id属性
  854. commitData.quoteProductList = commitData.quoteProductList.map(({ id, ...rest }) => rest);
  855. // 删除commitData本身的id属性
  856. delete commitData.id;
  857. }
  858. console.log('commitData~~~~~~~~', commitData)
  859. addInformation(commitData)
  860. .then((res) => {
  861. this.loading = false;
  862. updateRelationStatus([this.form.contactId]);
  863. if (type === 'sub') {
  864. this.quotationSubmit(res);
  865. return;
  866. }
  867. this.$message.success('新增成功');
  868. this.cancel();
  869. this.$emit('done');
  870. })
  871. .catch((e) => {
  872. //this.loading = false;
  873. });
  874. }
  875. } catch (error) {
  876. console.log(error);
  877. // 表单验证未通过,不执行保存操作
  878. }
  879. },
  880. async quotationSubmit(res) {
  881. const data = await getDetail(this.businessId || res);
  882. this.processSubmitDialogFlag = true;
  883. this.$nextTick(() => {
  884. let params = {
  885. businessId: this.businessId || res,
  886. businessKey: 'quote_approve',
  887. formCreateUserId: data.createUserId,
  888. variables: {
  889. businessCode: data.code,
  890. businessName: data.contactName,
  891. businessType: '报价单'
  892. }
  893. // callBackMethodType : '1',
  894. // callBackMethod : 'proTargetPlanApproveApiImpl.updatePlanApprovalStatus',
  895. // pcHandle : '/bpm/handleTask/components/project-manage/plan-manage/submit.vue',
  896. // pcView : '/bpm/handleTask/components/project-manage/plan-manage/detailDialog.vue',
  897. // miniHandle : '',
  898. // miniView : '',
  899. };
  900. this.$refs.processSubmitDialogRef.init(params);
  901. });
  902. // submit({
  903. // businessId: this.businessId || res
  904. // }).then((res) => {
  905. // this.cancel();
  906. // this.$emit('done');
  907. // });
  908. },
  909. reload() {
  910. this.cancel();
  911. this.$emit('done');
  912. },
  913. cancel() {
  914. this.$nextTick(() => {
  915. this.activeName = 'base';
  916. // 关闭后,销毁所有的表单数据
  917. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  918. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  919. this.form = copyObj(this.formDef);
  920. this.visible = false;
  921. });
  922. }
  923. }
  924. };
  925. </script>
  926. <style scoped lang="scss">
  927. .TotalAmount {
  928. font-size: 16px;
  929. padding-right: 30px;
  930. }
  931. </style>