addOpportunityDialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div>
  3. <headerTitle title="基本信息"></headerTitle>
  4. <el-form
  5. label-width="120px"
  6. ref="form"
  7. :model="form"
  8. :rules="rules"
  9. style="margin-top: 30px"
  10. >
  11. <el-row>
  12. <el-col :span="8" style="height: 58px">
  13. <el-form-item label="选择客户" prop="contactName">
  14. <el-input
  15. placeholder="请选择"
  16. v-model="form.contactName"
  17. disabled
  18. maxlength="50"
  19. ></el-input>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="8">
  23. <el-form-item label=" 商机名称" prop="name">
  24. <el-input
  25. placeholder="请输入"
  26. v-model="form.name"
  27. maxlength="50"
  28. ></el-input>
  29. </el-form-item>
  30. </el-col>
  31. <el-col :span="8" style="height: 58px">
  32. <el-form-item label="选择负责人" prop="responsibleName">
  33. <el-input
  34. placeholder="请选择"
  35. v-model="userInfo.name"
  36. disabled
  37. maxlength="50"
  38. ></el-input>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="8" style="height: 58px">
  42. <el-form-item label="商机来源" prop="sourceCode">
  43. <DictSelection
  44. dictName="商机来源"
  45. clearable
  46. v-model="form.sourceCode"
  47. >
  48. </DictSelection>
  49. </el-form-item>
  50. </el-col>
  51. <el-col :span="8" style="height: 58px">
  52. <el-form-item label="赢单率" prop="winRate">
  53. <el-input placeholder="请输入内容" v-model="form.winRate">
  54. <template slot="append">%</template>
  55. </el-input>
  56. </el-form-item>
  57. </el-col>
  58. <el-col :span="8" style="height: 58px">
  59. <el-form-item label="预算" prop="budget">
  60. <el-input placeholder="请输入内容" v-model="form.budget">
  61. <template slot="append">万元</template>
  62. </el-input>
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="8">
  66. <el-form-item label="预计结单日期">
  67. <el-date-picker
  68. v-model="form.expectedClosingDate"
  69. value-format="yyyy-MM-dd"
  70. placeholder="请选择"
  71. type="date"
  72. style="width: 100%"
  73. class="filter-item"
  74. ></el-date-picker>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="8" style="height: 58px">
  78. <el-form-item prop="files" label="附件">
  79. <fileMain v-model="form.files"></fileMain>
  80. </el-form-item>
  81. </el-col>
  82. <el-col :span="16">
  83. <el-form-item label="备注" prop="remark">
  84. <el-input
  85. placeholder="请输入"
  86. v-model="form.remark"
  87. type="textarea"
  88. maxlength="300"
  89. ></el-input>
  90. </el-form-item>
  91. </el-col>
  92. </el-row>
  93. </el-form>
  94. <headerTitle title="物品清单"></headerTitle>
  95. <inventoryTable
  96. :isCustomerMark="false"
  97. ref="inventoryTable"
  98. :isDeliveryDeadline="false"
  99. :isGuaranteePeriod="false"
  100. :isDiscount="false"
  101. pageName="businessOpportunity"
  102. :pricing-way="form.pricingWay"
  103. ></inventoryTable>
  104. <!-- <headerTitle title="竞品"></headerTitle>
  105. <businessAddTable
  106. ref="businessAddTable"
  107. @timeAll="getDetailTable"
  108. :delDetailIds="delDetailIds"
  109. ></businessAddTable>
  110. <headerTitle title="关键人信息"></headerTitle>
  111. <personnelAddTable
  112. ref="personnelAddTable"
  113. :contactId="form.contactId"
  114. @timeAll="getPersonnelAddTable"
  115. :delDetailIds="PersonnelDetailIds"
  116. ></personnelAddTable> -->
  117. <head-list ref="headRef" @changeParent="changeHead"></head-list>
  118. <parentList
  119. ref="parentRef"
  120. classType="1"
  121. @changeParent="changeParent"
  122. ></parentList>
  123. </div>
  124. </template>
  125. <script>
  126. import store from '@/store';
  127. import dictMixins from '@/mixins/dictMixins';
  128. import businessAddTable from './businessAddTable.vue';
  129. import personnelAddTable from './personnelAddTable.vue';
  130. import headList from '@/components/headList';
  131. import parentList from '@/views/bpm/handleTask/components/quotation/parentList.vue';
  132. import { getDetail } from '@/api/bpm/components/saleManage/businessOpportunity';
  133. import { copyObj } from '@/utils/util';
  134. import inventoryTable from '@/BIZComponents/inventoryTable.vue';
  135. import fileUpload from '@/components/upload/fileUpload';
  136. import fileMain from '@/components/addDoc/index.vue';
  137. import {contactDetail} from '@/api/bpm/components/saleManage/contact';
  138. export default {
  139. props: {
  140. businessId: {
  141. default: ''
  142. }
  143. },
  144. mixins: [dictMixins],
  145. components: {
  146. fileMain,
  147. fileUpload,
  148. businessAddTable,
  149. personnelAddTable,
  150. headList,
  151. parentList,
  152. inventoryTable
  153. },
  154. data() {
  155. let formDef = {
  156. id: '',
  157. contactName: '',
  158. contactId: '',
  159. budget: null,
  160. expectedClosingDate: '',
  161. sourceCode: '',
  162. sourceName: '',
  163. stageCode: '',
  164. stageName: '',
  165. winRate: null,
  166. name: '',
  167. remark: '',
  168. responsibleName: '',
  169. responsibleId: '',
  170. source: '',
  171. status: 1,
  172. files: []
  173. };
  174. return {
  175. delDetailIds: [],
  176. PersonnelDetailIds: [],
  177. pricingWayList: [
  178. { id: 1, name: '按数量计价' },
  179. { id: 2, name: '按重量计价' }
  180. ],
  181. visible: false,
  182. title: '',
  183. row: {},
  184. userInfo: {},
  185. activeName: 'base',
  186. formDef,
  187. form: copyObj(formDef),
  188. // removeBankList: [],
  189. // removeLinkList: [],
  190. tableBankData: [],
  191. tableLinkData: [],
  192. rules: {
  193. contactName: [
  194. { required: true, message: '请选择客户', trigger: 'change' }
  195. ],
  196. name: [
  197. { required: true, message: '请输入商机名称', trigger: 'blur' }
  198. ],
  199. expectedClosingDate: [
  200. { required: true, message: '请选择预计结单日期', trigger: 'blur' }
  201. ],
  202. sourceCode: [
  203. { required: true, message: '请选择商机来源名称', trigger: 'change' }
  204. ],
  205. stageCode: [
  206. { required: true, message: '请选择商机阶段名称', trigger: 'change' }
  207. ],
  208. winRate: [
  209. {
  210. required: false,
  211. trigger: 'blur',
  212. validator: (_rule, value, callback) => {
  213. console.log(_rule);
  214. const reg = /^\d+(\.\d{1,2})?$/; // 限制为最多两位小数的正数
  215. if (!value) {
  216. callback(); // 验证通过
  217. return;
  218. }
  219. if (reg.test(value) && parseFloat(value) <= 100) {
  220. callback(); // 验证通过
  221. } else {
  222. value = value && value.replace(/[^0-9.]/g, ''); // 只保留数字和小数点
  223. const [integerPart, decimalPart] = value && value.split('.');
  224. if (decimalPart && decimalPart.length > 2) {
  225. callback(new Error('小数位数不能超过两位'));
  226. } else {
  227. callback(new Error('只能输入小于100的数字'));
  228. }
  229. }
  230. }
  231. }
  232. ],
  233. budget: [
  234. {
  235. required: false,
  236. trigger: 'blur',
  237. validator: (_rule, value, callback) => {
  238. const reg = /^\d{1,13}(\.\d{1,2})?$/; // 限制为最多两位小数的13位以内的正数
  239. if (!value) {
  240. callback(); // 验证通过
  241. return;
  242. }
  243. if (reg.test(value)) {
  244. callback(); // 验证通过
  245. } else {
  246. value = value && value.replace(/[^0-9.]/g, ''); // 只保留数字和小数点
  247. const [integerPart, decimalPart] = value && value.split('.');
  248. if (decimalPart && decimalPart.length > 2) {
  249. callback(new Error('小数位数不能超过两位'));
  250. } else if (integerPart.length > 13) {
  251. callback(new Error('整数位数不能超过13位'));
  252. } else {
  253. callback(new Error('只能输入数字'));
  254. }
  255. }
  256. }
  257. }
  258. ]
  259. },
  260. // 提交状态
  261. loading: false,
  262. // 是否是修改
  263. isUpdate: false,
  264. // 组织机构树形结构数据
  265. groupTreeData: [],
  266. // 组织机构平铺数据
  267. groupData: []
  268. };
  269. },
  270. mounted() {
  271. this.$nextTick(() => {
  272. this.userInfo = store.state.user.info;
  273. });
  274. },
  275. created() {
  276. this.getDetailData(this.businessId);
  277. },
  278. methods: {
  279. //获取竞品
  280. getDetailTable(val) {
  281. this.form.competAnalysisList = val;
  282. },
  283. //获取关键人信息
  284. getPersonnelAddTable(val) {
  285. this.form.partyList = val;
  286. },
  287. //选择客户回调
  288. changeParent(obj) {
  289. this.$set(this.form, 'contactId', obj.id);
  290. this.$set(this.form, 'contactName', obj.name);
  291. this.getContactDetail(1);
  292. },
  293. //获取客户
  294. async getContactDetail(type) {
  295. const { base } = await contactDetail(this.form.contactId);
  296. this.customerMark = base.serialNo;
  297. if (type) {
  298. this.$nextTick(() => {
  299. this.$refs.inventoryTable.setCustomerMark(this.customerMark);
  300. });
  301. }
  302. },
  303. //选择负责人回调
  304. changeHead(obj) {
  305. this.$set(this.form, 'responsibleId', obj.id);
  306. this.$set(this.form, 'responsibleName', obj.name);
  307. },
  308. handParent() {
  309. let item = {
  310. id: this.form.contactId
  311. };
  312. this.$refs.parentRef.open(item);
  313. },
  314. handHead() {
  315. let item = {
  316. id: this.form.responsibleId
  317. };
  318. this.$refs.headRef.open(item);
  319. },
  320. //获取详情
  321. async getDetailData(id) {
  322. this.loading = true;
  323. const data = await getDetail(id);
  324. this.loading = false;
  325. if (data) {
  326. this.form = data;
  327. this.getContactDetail()
  328. this.$nextTick(() => {
  329. this.$refs.inventoryTable &&
  330. this.$refs.inventoryTable.putTableValue(data);
  331. });
  332. }
  333. },
  334. salesmanChange(val, info) {
  335. this.otherForm.salesmanName = info.name;
  336. },
  337. settlementModeChange(info) {
  338. this.otherForm.settlementModeName = info.dictValue;
  339. },
  340. ifChiefChange(value, idx) {
  341. if (value === 1) {
  342. this.tableLinkData.forEach((e) => (e.ifChief = 0));
  343. this.tableLinkData[idx].ifChief = 1;
  344. }
  345. },
  346. getValidate() {
  347. return Promise.all([
  348. new Promise((resolve, reject) => {
  349. this.$refs.form.validate((valid) => {
  350. if (!valid) {
  351. reject(false);
  352. } else {
  353. resolve(true);
  354. }
  355. });
  356. }),
  357. new Promise((resolve, reject) => {
  358. this.$refs.inventoryTable.validateForm((valid) => {
  359. if (!valid) {
  360. reject(false);
  361. } else {
  362. resolve(true);
  363. }
  364. });
  365. })
  366. ]);
  367. },
  368. async getTableValue() {
  369. try {
  370. await this.getValidate();
  371. // 表单验证通过,执行保存操作
  372. let _sourceName = this.getDictValue('商机来源', this.form.sourceCode),
  373. _stageName = this.getDictValue('商机阶段', this.form.stageCode);
  374. this.form = Object.assign({}, this.form, {
  375. responsibleId: this.userInfo.userId,
  376. responsibleName: this.userInfo.name,
  377. sourceName: _sourceName,
  378. stageName: _stageName,
  379. files: this.form.files || []
  380. });
  381. if (this.$refs.inventoryTable.getTableValue().length == 0) {
  382. this.$message.warning('物品清单不能为空');
  383. return;
  384. }
  385. this.form.totalPrice= this.$refs.inventoryTable.getPrice()[0]
  386. const commitData = {
  387. opportunity: this.form,
  388. competAnalysisList: this.form.competAnalysisList,
  389. partyList: this.form.partyList,
  390. productList: this.$refs.inventoryTable.getTableValue()
  391. };
  392. return commitData;
  393. } catch (error) {
  394. console.log(error);
  395. // 表单验证未通过,不执行保存操作
  396. return false
  397. }
  398. },
  399. cancel() {
  400. this.$nextTick(() => {
  401. this.activeName = 'base';
  402. // 关闭后,销毁所有的表单数据
  403. this.$refs['otherForm'] && this.$refs['otherForm'].resetFields();
  404. this.$refs['formRef'] && this.$refs['formRef'].resetFields();
  405. this.form = copyObj(this.formDef);
  406. this.visible = false;
  407. });
  408. }
  409. }
  410. };
  411. </script>