addDialog.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  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="80%"
  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="contactName"
  19. style="margin-bottom: 22px"
  20. >
  21. <el-input
  22. clearable
  23. v-model="form.contactName"
  24. @click.native="handParent"
  25. placeholder="请输入"
  26. />
  27. </el-form-item>
  28. <el-form-item
  29. label="有无商机"
  30. prop="opportunityType"
  31. style="margin-bottom: 22px"
  32. >
  33. <el-select
  34. v-model="form.opportunityType"
  35. placeholder="请选择"
  36. style="width: 100%"
  37. @change="opportunityTypeChange"
  38. >
  39. <el-option
  40. v-for="item in opportunityTypeList"
  41. :key="item.value"
  42. :label="item.label"
  43. :value="item.value"
  44. >
  45. </el-option>
  46. </el-select>
  47. </el-form-item>
  48. <el-form-item
  49. label="关联商机"
  50. prop="opportunityId"
  51. style="margin-bottom: 22px"
  52. :rules="[
  53. {
  54. required: form.opportunityType === 1 ? true : false,
  55. message: '请选择关联商机',
  56. trigger: 'change'
  57. }
  58. ]"
  59. >
  60. <el-select
  61. :disabled="form.opportunityType === 0"
  62. v-model="form.opportunityId"
  63. placeholder="请选择"
  64. style="width: 100%"
  65. @change="opportunityChange"
  66. >
  67. <el-option
  68. v-for="item in businessList"
  69. :key="item.id"
  70. :label="item.name"
  71. :value="item.id"
  72. >
  73. </el-option>
  74. </el-select>
  75. </el-form-item>
  76. <el-form-item
  77. label="询价方联系人"
  78. prop="contactLinkName"
  79. style="margin-bottom: 22px"
  80. >
  81. <el-select
  82. v-model="form.contactLinkName"
  83. style="width: 100%"
  84. placeholder="请选择"
  85. @change="onchangeLink"
  86. @focus="selectFocus"
  87. >
  88. <el-option
  89. v-for="item in linkNameOptions"
  90. :key="item.id"
  91. :label="item.linkName"
  92. :value="item.id"
  93. >
  94. </el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item
  98. label="询价方电话"
  99. prop="contactTel"
  100. style="margin-bottom: 22px"
  101. >
  102. <el-input
  103. clearable
  104. :maxlength="20"
  105. v-model="form.contactTel"
  106. placeholder="请输入"
  107. />
  108. </el-form-item>
  109. <el-form-item
  110. label="询价方传真"
  111. prop="contactFax"
  112. style="margin-bottom: 22px"
  113. >
  114. <el-input
  115. clearable
  116. v-model="form.contactFax"
  117. placeholder="请输入"
  118. />
  119. </el-form-item>
  120. <el-form-item
  121. label=" 询价方Email"
  122. prop="contactEmail"
  123. style="margin-bottom: 22px"
  124. >
  125. <el-input
  126. clearable
  127. v-model="form.contactEmail"
  128. placeholder="请输入"
  129. />
  130. </el-form-item>
  131. <el-form-item
  132. label="询价方地址"
  133. prop="contactAddress"
  134. style="margin-bottom: 22px"
  135. >
  136. <el-input
  137. clearable
  138. v-model="form.contactAddress"
  139. placeholder="请输入"
  140. />
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="12">
  144. <el-form-item
  145. label="报价方名称"
  146. prop="quoteName"
  147. style="margin-bottom: 22px"
  148. >
  149. <el-input
  150. v-if="enterprisePage.length <= 1"
  151. clearable
  152. v-model="form.quoteName"
  153. placeholder="请输入"
  154. />
  155. <el-select
  156. v-if="enterprisePage.length > 1"
  157. style="width: 100%"
  158. v-model="form.quoteName"
  159. placeholder="请选择"
  160. @change="getEnterprise()"
  161. >
  162. <el-option
  163. v-for="item in enterprisePage"
  164. :key="item.id"
  165. :label="item.name"
  166. :value="item.name"
  167. >
  168. </el-option>
  169. </el-select>
  170. </el-form-item>
  171. <el-form-item
  172. label="报价方联系人"
  173. prop="quoteLinkName"
  174. style="margin-bottom: 22px"
  175. >
  176. <el-input
  177. clearable
  178. v-model="form.quoteLinkName"
  179. @click.native="handHead()"
  180. placeholder="请输入"
  181. />
  182. </el-form-item>
  183. <el-form-item prop="quoteTel" label="报价方联系电话">
  184. <el-input clearable v-model="form.quoteTel" placeholder="请输入" />
  185. </el-form-item>
  186. <el-form-item prop="quoteFax" label="报价方传真">
  187. <el-input clearable v-model="form.quoteFax" placeholder="请输入" />
  188. </el-form-item>
  189. <el-form-item
  190. label="报价方Email"
  191. prop="quoteEmail"
  192. style="margin-bottom: 22px"
  193. >
  194. <el-input
  195. clearable
  196. v-model="form.quoteEmail"
  197. placeholder="请输入"
  198. />
  199. </el-form-item>
  200. <el-form-item
  201. label="报价方地址"
  202. prop="quoteAddress"
  203. style="margin-bottom: 22px"
  204. >
  205. <el-input
  206. clearable
  207. v-model="form.quoteAddress"
  208. placeholder="请输入"
  209. />
  210. </el-form-item>
  211. <el-form-item prop="askFile" label="附件">
  212. <fileUpload
  213. v-model="form.askFile"
  214. module="main"
  215. :showLib="false"
  216. :limit="1"
  217. />
  218. </el-form-item>
  219. </el-col>
  220. </el-row>
  221. <headerTitle title="报价单产品清单"></headerTitle>
  222. <inventoryTable
  223. ref="inventoryTable"
  224. :isDeliveryDeadline="false"
  225. :isGuaranteePeriod="false"
  226. ></inventoryTable>
  227. <el-row style="margin-top: 20px">
  228. <el-col :span="6">
  229. <el-form-item prop="taxRate" label="税率">
  230. <el-input clearable v-model="form.taxRate" placeholder="请输入">
  231. <template slot="append">%</template>
  232. </el-input>
  233. </el-form-item>
  234. </el-col>
  235. <el-col :span="6">
  236. <el-form-item prop="deliveryDate" label="交货日期">
  237. <el-date-picker
  238. v-model="form.deliveryDate"
  239. value-format="yyyy-MM-dd"
  240. placeholder="请选择交货日期"
  241. type="date"
  242. style="width: 150px"
  243. class="filter-item"
  244. ></el-date-picker>
  245. </el-form-item>
  246. </el-col>
  247. <el-col :span="6">
  248. <el-form-item
  249. label="结算方式"
  250. prop="settlementMode"
  251. style="margin-bottom: 22px"
  252. >
  253. <DictSelection
  254. dictName="结算方式"
  255. clearable
  256. v-model="form.settlementMode"
  257. >
  258. </DictSelection>
  259. </el-form-item>
  260. </el-col>
  261. <el-col :span="6">
  262. <el-form-item
  263. label="是否接受拆单"
  264. prop="acceptUnpack"
  265. style="margin-bottom: 22px"
  266. >
  267. <el-select v-model="form.acceptUnpack" placeholder="请选择">
  268. <el-option
  269. v-for="item in acceptUnpackoptions"
  270. :key="item.value"
  271. :label="item.label"
  272. :value="item.value"
  273. >
  274. </el-option>
  275. </el-select>
  276. </el-form-item>
  277. </el-col>
  278. </el-row>
  279. </el-form>
  280. <div slot="footer" class="footer">
  281. <el-button type="primary" @click="save">保存</el-button>
  282. <el-button type="primary" @click="save('sub')">提交</el-button>
  283. <el-button @click="cancel">返回</el-button>
  284. </div>
  285. <parentList
  286. ref="parentRef"
  287. classType="1"
  288. @changeParent="changeParent"
  289. ></parentList>
  290. <head-list ref="headRef" @changeParent="changePersonel"></head-list>
  291. </ele-modal>
  292. </template>
  293. <script>
  294. import { emailReg, phoneReg, numberReg } from 'ele-admin';
  295. import { acceptUnpackoptions } from '@/enum/dict';
  296. import inventoryTable from '@/views/contractManage/contractBook/components/inventoryTable.vue';
  297. import { categoryData } from 'element-china-category-data';
  298. import fileUpload from '@/components/upload/fileUpload';
  299. import { cityData } from 'ele-admin/packages/utils/regions';
  300. import dictMixins from '@/mixins/dictMixins';
  301. import deptSelect from '@/components/CommomSelect/dept-select.vue';
  302. import personSelect from '@/components/CommomSelect/person-select.vue';
  303. import parentList from '@/views/saleManage/contact/components/parentList.vue';
  304. import {
  305. getDetail,
  306. UpdateInformation,
  307. addInformation,
  308. submit
  309. } from '@/api/saleManage/quotation';
  310. import { getOpportunityDetail } from '@/api/saleManage/businessOpportunity';
  311. import { getTableList } from '@/api/saleManage/businessOpportunity';
  312. import { enterprisePage } from '@/api/contractManage/contractBook';
  313. import { getcontactlink } from '@/api/saleManage/businessFollow';
  314. import headList from '@/views/saleManage/businessOpportunity/components/headList.vue';
  315. import { copyObj } from '@/utils/util';
  316. import { contactDetail } from '@/api/saleManage/contact';
  317. export default {
  318. props: {
  319. categoryTreeList: Array
  320. },
  321. mixins: [dictMixins],
  322. components: {
  323. fileUpload,
  324. headList,
  325. inventoryTable,
  326. deptSelect,
  327. parentList,
  328. personSelect
  329. },
  330. data() {
  331. let formDef = {
  332. id: '',
  333. acceptUnpack: null,
  334. askFile: null,
  335. contactAddress: '',
  336. opportunityId: '',
  337. contactEmail: '',
  338. contactFax: '',
  339. contactId: '',
  340. contactLinkId: '',
  341. contactLinkName: '',
  342. contactName: '',
  343. contactTel: '',
  344. deliveryDate: '',
  345. settlementMode: '',
  346. settlementModeName: '',
  347. quoteAddress: '',
  348. quoteEmail: '',
  349. quoteFax: '',
  350. quoteLinkId: '',
  351. quoteLinkName: '',
  352. quoteName: '',
  353. quoteTel: '',
  354. taxRate: null,
  355. totalPrice: null,
  356. opportunityType: null
  357. };
  358. return {
  359. opportunityTypeList: [
  360. { label: '有', value: 1 },
  361. { label: '无', value: 0 }
  362. ],
  363. payWayOptions: [],
  364. delDetailIds: [],
  365. linkNameOptions: [],
  366. acceptUnpackoptions,
  367. visible: false,
  368. title: '',
  369. row: {},
  370. activeName: 'base',
  371. formDef,
  372. form: copyObj(formDef),
  373. // removeBankList: [],
  374. // removeLinkList: [],
  375. tableBankData: [],
  376. tableLinkData: [],
  377. businessList: [], //商机列表
  378. rules: {
  379. // opportunityId: [
  380. // { required: true, message: '请选择关联商机', trigger: 'change' }
  381. // ],
  382. contactName: [
  383. { required: true, message: '请选择客户', trigger: 'change' }
  384. ],
  385. name: [
  386. { required: true, message: '请输入客户名称', trigger: 'blur' }
  387. ],
  388. contactLinkName: [
  389. { required: true, message: '请选择联系人', trigger: 'change' }
  390. ],
  391. acceptUnpack: [
  392. { required: true, message: '请选择是否接受', trigger: 'change' }
  393. ],
  394. contactTel: [
  395. {
  396. required: true,
  397. pattern: numberReg,
  398. message: '请输入联系电话',
  399. trigger: 'blur'
  400. }
  401. ],
  402. deliveryDate: [
  403. { required: true, message: '请选择交货日期', trigger: 'change' }
  404. ],
  405. settlementMode: [
  406. { required: true, message: '请选择结算方式', trigger: 'change' }
  407. ],
  408. quoteLinkName: [
  409. { required: true, message: '请输入报价方联系人', trigger: 'change' }
  410. ],
  411. quoteName: [
  412. { required: true, message: '请输入报价方名称', trigger: 'blur' }
  413. ],
  414. quoteTel: [
  415. {
  416. required: true,
  417. pattern: numberReg,
  418. message: '请输入报价方联系电话',
  419. trigger: 'blur'
  420. }
  421. ],
  422. quoteEmail: [
  423. { pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur' }
  424. ],
  425. contactEmail: [
  426. { pattern: emailReg, message: '邮箱格式不正确', trigger: 'blur' }
  427. ],
  428. taxRate: [
  429. { pattern: numberReg, message: '请输入数字', trigger: 'blur' }
  430. ]
  431. },
  432. businessId: '',
  433. options: {
  434. cityData,
  435. categoryData
  436. },
  437. // 提交状态
  438. loading: false,
  439. // 是否是修改
  440. isUpdate: false,
  441. // 组织机构树形结构数据
  442. groupTreeData: [],
  443. // 组织机构平铺数据
  444. groupData: [],
  445. enterprisePage: []
  446. };
  447. },
  448. created() {
  449. this.getEnterprisePage();
  450. },
  451. methods: {
  452. opportunityTypeChange() {
  453. if (this.form.opportunityType === 0) {
  454. this.form.opportunityId = '';
  455. }
  456. },
  457. //获取详情
  458. async getDetailData(id) {
  459. this.businessId = id;
  460. this.loading = true;
  461. const data = await getDetail(id);
  462. this.loading = false;
  463. if (data) {
  464. this.$nextTick(() => {
  465. this.form = data;
  466. if (data.askFile !== '') {
  467. this.$set(this.form, 'askFile', [data?.askFile]);
  468. }
  469. if(data.opportunityId){
  470. this.form.opportunityType=1
  471. }
  472. this.$refs.inventoryTable &&
  473. this.$refs.inventoryTable.putTableValue(data);
  474. this.getLinkInfo(data.contactId);
  475. this.getBusinessList(data.contactName);
  476. });
  477. }
  478. },
  479. opportunityChange(id) {
  480. getOpportunityDetail(id).then((res) => {
  481. if (res.productList.length > 0) {
  482. this.$refs.inventoryTable &&
  483. this.$refs.inventoryTable.putTableValue(res);
  484. }
  485. });
  486. },
  487. //更新联系人数据
  488. async getLinkInfo(contactId) {
  489. const data = await getcontactlink({ contactId });
  490. if (data && data?.length) {
  491. this.linkNameOptions = data;
  492. }
  493. },
  494. selectFocus() {
  495. if (this.linkNameOptions.length === 0) {
  496. return this.$message.error('请先选择名称');
  497. }
  498. },
  499. //获取客户的商机列表
  500. async getBusinessList(name) {
  501. if (!this.form.contactName)
  502. return this.$message.error('请先选择询价方名称');
  503. const data = await getTableList({
  504. pageNum: 1,
  505. size: 30,
  506. contactName: name,
  507. approvalStatus:2
  508. });
  509. console.log(data, '3333');
  510. this.businessList = data.list;
  511. },
  512. //选择下拉框
  513. onchangeLink(selectedOptions) {
  514. const option = this.linkNameOptions.find(
  515. (opt) => opt.id === selectedOptions
  516. );
  517. this.form = Object.assign({}, this.form, {
  518. contactEmail: option?.email,
  519. contactLinkName: option?.linkName || '',
  520. contactTel: option?.mobilePhone || option?.phone || '',
  521. contactLinkId: option?.id
  522. });
  523. },
  524. handHead() {
  525. let item = {
  526. id: this.form.quoteLinkId
  527. };
  528. this.$refs.headRef.open(item);
  529. },
  530. //选择报价方人回调
  531. changePersonel(obj, index) {
  532. this.$set(this.form, 'quoteLinkId', obj.id);
  533. this.$set(this.form, 'quoteLinkName', obj.name);
  534. this.$set(this.form, 'quoteTel', obj.phone);
  535. this.$set(this.form, 'quoteEmail', obj.email);
  536. },
  537. //选择客户回调
  538. changeParent(obj) {
  539. this.form = Object.assign({}, this.form, {
  540. contactId: obj.id,
  541. contactName: obj.name,
  542. contactAddress: obj.addressName + obj.address,
  543. contactLinkId: '',
  544. contactLinkName: '',
  545. contactEmail: '',
  546. contactTel: ''
  547. });
  548. this.getLinkInfo(obj.id);
  549. this.getBusinessList(obj.name);
  550. },
  551. handParent() {
  552. let item = {
  553. id: this.form.contactId
  554. };
  555. this.$refs.parentRef.open(item);
  556. },
  557. async open(type, row, contactCategoryId) {
  558. this.title = type === 'add' ? '新增' : '修改';
  559. this.row = row;
  560. this.visible = true;
  561. if (this.enterprisePage.length == 0) {
  562. await this.getEnterprisePage();
  563. }
  564. if (type == 'add') {
  565. let userInfo=this.$store.getters.user.info
  566. this.isUpdate = false;
  567. userInfo.id=userInfo.userId
  568. this.changePersonel(userInfo)
  569. if (this.enterprisePage.length > 0) {
  570. this.form.quoteName = this.enterprisePage[0].name;
  571. // this.form.quoteTel = this.enterprisePage[0].tel;
  572. this.form.quoteFax = this.enterprisePage[0].fax;
  573. this.form.quoteAddress = this.enterprisePage[0].address;
  574. }
  575. if (row.id) {
  576. this.form.opportunityId = row.id;
  577. await this.opportunityChange(row.id);
  578. let data = await contactDetail(row.contactId);
  579. this.form.opportunityType=1
  580. this.changeParent(data.base);
  581. }
  582. } else {
  583. this.isUpdate = true;
  584. this.getDetailData(row.id);
  585. }
  586. },
  587. getEnterprisePage() {
  588. enterprisePage({
  589. pageNum: 1,
  590. size: 100
  591. }).then((res) => {
  592. this.enterprisePage = [];
  593. this.enterprisePage.push(...res.list);
  594. });
  595. },
  596. getEnterprise() {
  597. let data = this.enterprisePage.find(
  598. (item) => item.name == this.form.quoteName
  599. );
  600. this.form.quoteName = data.name;
  601. // this.form.quoteTel = data.tel;
  602. this.form.quoteFax = data.fax;
  603. this.form.quoteAddress = data.address;
  604. },
  605. salesmanChange(val, info) {
  606. this.otherForm.salesmanName = info.name;
  607. },
  608. ifChiefChange(value, idx) {
  609. if (value === 1) {
  610. this.tableLinkData.forEach((e) => (e.ifChief = 0));
  611. this.tableLinkData[idx].ifChief = 1;
  612. }
  613. },
  614. getValidate() {
  615. return new Promise((resolve, reject) => {
  616. this.$refs.form.validate((valid) => {
  617. if (!valid) {
  618. reject(false);
  619. } else {
  620. resolve(true);
  621. }
  622. });
  623. });
  624. },
  625. getValidate() {
  626. return Promise.all([
  627. new Promise((resolve, reject) => {
  628. this.$refs.form.validate((valid) => {
  629. if (!valid) {
  630. reject(false);
  631. } else {
  632. resolve(true);
  633. }
  634. });
  635. }),
  636. new Promise((resolve, reject) => {
  637. this.$refs.inventoryTable.validateForm((valid) => {
  638. if (!valid) {
  639. reject(false);
  640. } else {
  641. resolve(true);
  642. }
  643. });
  644. })
  645. ]);
  646. },
  647. async save(type) {
  648. try {
  649. await this.getValidate();
  650. // 表单验证通过,执行保存操作
  651. this.loading = true;
  652. if (!this.isUpdate) {
  653. delete this.form.id;
  654. }
  655. let settlementModeName = this.getDictValue(
  656. '结算方式',
  657. this.form.settlementMode
  658. );
  659. if (this.form.askFile && this.form.askFile.length > 0) {
  660. this.form.askFile = this.form.askFile[0];
  661. } else {
  662. this.form.askFile = null;
  663. }
  664. let commitData = Object.assign({}, this.form, {
  665. settlementModeName,
  666. quoteProductList: this.$refs.inventoryTable.getTableValue(),
  667. totalPrice: this.$refs.inventoryTable.getTotalPrice()
  668. });
  669. if (this.isUpdate) {
  670. UpdateInformation(commitData)
  671. .then((res) => {
  672. this.loading = false;
  673. if (type === 'sub') {
  674. this.quotationSubmit(res);
  675. return;
  676. }
  677. this.$message.success('修改成功');
  678. this.cancel();
  679. this.$emit('done');
  680. })
  681. .catch((e) => {
  682. //this.loading = false;
  683. });
  684. } else {
  685. addInformation(commitData)
  686. .then((res) => {
  687. this.loading = false;
  688. if (type === 'sub') {
  689. this.quotationSubmit(res);
  690. return;
  691. }
  692. this.$message.success('新增成功');
  693. this.cancel();
  694. this.$emit('done');
  695. })
  696. .catch((e) => {
  697. //this.loading = false;
  698. });
  699. }
  700. } catch (error) {
  701. console.log(error);
  702. // 表单验证未通过,不执行保存操作
  703. }
  704. },
  705. quotationSubmit(res) {
  706. submit({
  707. businessId: this.businessId || res
  708. }).then((res) => {
  709. this.cancel();
  710. this.$emit('done');
  711. });
  712. },
  713. cancel() {
  714. this.$nextTick(() => {
  715. this.activeName = 'base';
  716. // 关闭后,销毁所有的表单数据
  717. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  718. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  719. this.form = copyObj(this.formDef);
  720. this.visible = false;
  721. });
  722. }
  723. }
  724. };
  725. </script>
  726. <style scoped lang="scss">
  727. .TotalAmount {
  728. font-size: 16px;
  729. padding-right: 30px;
  730. }
  731. </style>