SaleInquiryFormForm.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <a-spin :spinning="loading">
  3. <JFormContainer :disabled="disabled">
  4. <template #detail>
  5. <a-form v-bind="formItemLayout" name="SaleInquiryFormForm" ref="formRef">
  6. <a-row>
  7. <a-col :span="12">
  8. <a-form-item label="单据日期(bill date)" v-bind="validateInfos.billDate" id="SaleInquiryFormForm-billDate" name="billDate">
  9. <a-date-picker placeholder="请选择单据日期(bill date)" v-model:value="formData.billDate" value-format="YYYY-MM-DD" style="width: 100%" allow-clear />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :span="12">
  13. <a-form-item label="询价单号(bill code)" v-bind="validateInfos.billCode" id="SaleInquiryFormForm-billCode" name="billCode">
  14. <a-input v-model:value="formData.billCode" placeholder="请输入询价单号(bill code)" disabled></a-input>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :span="12">
  18. <a-form-item label="询价项目(inquiry project)" v-bind="validateInfos.projectName" id="SaleInquiryFormForm-inquiryProject" name="inquiryProject">
  19. <a-input-search v-model:value="formData.projectName" placeholder="请输入询价项目(inquiry project)" allow-clear enter-button="Search" @search="onSearchProject"></a-input-search>
  20. </a-form-item>
  21. </a-col>
  22. <a-col :span="12">
  23. <a-form-item label="询价客户(inquiry customer)" v-bind="validateInfos.inquiryCustomer" id="SaleInquiryFormForm-inquiryCustomer" name="inquiryCustomer">
  24. <JSelectInput v-model:value="formData.inquiryCustomer" placeholder="请选择" :options="customerOption" ></JSelectInput>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="12">
  28. <a-form-item label="询价平台(inquiry platform)" v-bind="validateInfos.inquiryPlatform" id="SaleInquiryFormForm-inquiryPlatform" name="inquiryPlatform">
  29. <a-input v-model:value="formData.inquiryPlatform" placeholder="请输入询价平台(inquiry platform)" allow-clear ></a-input>
  30. </a-form-item>
  31. </a-col>
  32. <a-col :span="12">
  33. <a-form-item label="客户询价单号(customer inquiry number)" v-bind="validateInfos.customerInquiryNumber" id="SaleInquiryFormForm-customerInquiryNumber" name="customerInquiryNumber">
  34. <a-input v-model:value="formData.customerInquiryNumber" placeholder="请输入客户询价单号(customer inquiry number)" allow-clear ></a-input>
  35. </a-form-item>
  36. </a-col>
  37. <a-col :span="12">
  38. <a-form-item label="询价有效期(inquiry period)" v-bind="validateInfos.inquiryPeriodEnd" id="SaleInquiryFormForm-inquiryPeriodEnd" name="inquiryPeriodEnd">
  39. <a-range-picker v-model:value="inquiryPeriod" :format="['YYYY-MM-DD','YYYY-MM-DD']" @change="onChangeInquiryPeriod" style="width: 100%" />
  40. </a-form-item>
  41. </a-col>
  42. <a-col :span="12">
  43. <a-form-item label="业务类型(busyness type)" v-bind="validateInfos.busynessType" id="SaleInquiryFormForm-busynessType" name="busynessType">
  44. <JDictSelectTag v-model:value="formData.busynessType" placeholder="请选择" dictCode="busyness_type"/>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :span="12">
  48. <a-form-item label="优先级(priority)" v-bind="validateInfos.priority" id="SaleInquiryFormForm-priority" name="priority">
  49. <JDictSelectTag v-model:value="formData.priority" placeholder="请选择" dictCode="priority"/>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :span="12">
  53. <a-form-item label="产品分类(production class)" v-bind="validateInfos.productionClass" id="SaleInquiryFormForm-productionClass" name="productionClass">
  54. <JSelectInput v-model:value="formData.productionClass" placeholder="请选择" :options="classOption" ></JSelectInput>
  55. </a-form-item>
  56. </a-col>
  57. <a-col :span="12">
  58. <a-form-item label="机型(model)" v-bind="validateInfos.model" id="SaleInquiryFormForm-model" name="model">
  59. <JDictSelectTag v-model:value="formData.model" placeholder="请选择" dictCode="model_typer"/>
  60. </a-form-item>
  61. </a-col>
  62. <a-col :span="12">
  63. <a-form-item label="厂家(maker)" v-bind="validateInfos.maker" id="SaleInquiryFormForm-maker" name="maker">
  64. <a-input v-model:value="formData.maker" placeholder="请输入厂家(maker)" allow-clear ></a-input>
  65. </a-form-item>
  66. </a-col>
  67. <a-col :span="12">
  68. <a-form-item label="销售部门(sale department)" v-bind="validateInfos.saleDepartment" id="SaleInquiryFormForm-saleDepartment" name="saleDepartment">
  69. <JSelectDept v-model:value="formData.saleDepartment" :multiple="false" />
  70. </a-form-item>
  71. </a-col>
  72. <a-col :span="12">
  73. <a-form-item label="业务员(salesman)" v-bind="validateInfos.salesman" id="SaleInquiryFormForm-salesman" name="salesman">
  74. <JSelectUser v-model:value="formData.salesman" placeholder="请选择" :multiple="false"></JSelectUser>
  75. </a-form-item>
  76. </a-col>
  77. <a-col :span="12">
  78. <a-form-item label="交期(delivery time)" v-bind="validateInfos.deliveryTime" id="SaleInquiryFormForm-deliveryTime" name="deliveryTime">
  79. <a-date-picker placeholder="请选择交期(delivery time)" v-model:value="formData.deliveryTime" value-format="YYYY-MM-DD" format="YYYY-MM-DD" style="width: 100%" allow-clear />
  80. </a-form-item>
  81. </a-col>
  82. <a-col :span="12">
  83. <a-form-item label="采购询价组(procurement inquiry team)" v-bind="validateInfos.inquiryTeam" id="SaleInquiryFormForm-inquiryTeam" name="inquiryTeam">
  84. <JDictSelectTag v-model:value="formData.inquiryTeam" placeholder="请选择" dictCode="procurement_inquiry_team"/>
  85. </a-form-item>
  86. </a-col>
  87. <a-col :span="12">
  88. <a-form-item label="询价备注(inquiry notes)" v-bind="validateInfos.inquiryNotes" id="SaleInquiryFormForm-inquiryNotes" name="inquiryNotes">
  89. <a-input v-model:value="formData.inquiryNotes" placeholder="请输入询价备注(inquiry notes)" allow-clear ></a-input>
  90. </a-form-item>
  91. </a-col>
  92. <a-col :span="12">
  93. <a-form-item label="附件(attachs)" v-bind="validateInfos.attachs" id="SaleInquiryFormForm-attachs" name="attachs">
  94. <JUpload v-model:value="formData.attachsn"></JUpload>
  95. </a-form-item>
  96. </a-col>
  97. </a-row>
  98. </a-form>
  99. </template>
  100. </JFormContainer>
  101. <!-- 子表单区域 -->
  102. <a-tabs v-model:activeKey="activeKey" animated style=" padding: 24px;padding-top: 0px;">
  103. <a-tab-pane tab="销售询价单子表 - 船明细(ship details)" key="saleInquiryFormShip" :forceRender="true">
  104. <a-button type="primary" @click="selectShip"> 选择船(select ship)</a-button>
  105. <j-vxe-table
  106. :keep-source="true"
  107. resizable
  108. ref="saleInquiryFormShipTableRef"
  109. :loading="saleInquiryFormShipTable.loading"
  110. :columns="saleInquiryFormShipTable.columns"
  111. :dataSource="saleInquiryFormShipTable.dataSource"
  112. :height="340"
  113. :disabled="disabled"
  114. :rowNumber="true"
  115. :rowSelection="true"
  116. >
  117. <template #action="props" >
  118. <a @click="viewAccessory(props)" >查看配件信息(view accessory information)</a>
  119. <a-divider type="vertical"/>
  120. <a-popconfirm title="确定删除吗?" @confirm="handleDelete(props)">
  121. <a>删除(delete)</a>
  122. </a-popconfirm>
  123. </template>
  124. </j-vxe-table>
  125. </a-tab-pane>
  126. <a-tab-pane tab="销售询价单子表 - 产品明细(product details)" key="saleInquiryFormProduct" :forceRender="true">
  127. <a-button type="primary" @click="selectProducts" style="margin-right: 1%;margin-bottom: 1%;"> 选择产品(select product)</a-button>
  128. <a-button type="primary" @click="setNeed" style="margin-right: 1%;"> 设置需要船检证书(set need ship inspection certificate)</a-button>
  129. <a-button type="primary" @click="setNotNeed"> 设置不需要船检证书(set need not ship inspection certificate)</a-button>
  130. <j-vxe-table
  131. :keep-source="true"
  132. resizable
  133. ref="saleInquiryFormProductTableRef"
  134. :loading="saleInquiryFormProductTable.loading"
  135. :columns="saleInquiryFormProductTable.columns"
  136. :dataSource="saleInquiryFormProductTable.dataSource"
  137. :height="340"
  138. :disabled="disabled"
  139. :rowNumber="true"
  140. :rowSelection="true"
  141. >
  142. <template #action="props">
  143. <a-popconfirm title="确定删除吗?" @confirm="handleDelete1(props)">
  144. <a>删除(delete)</a>
  145. </a-popconfirm>
  146. </template>
  147. </j-vxe-table>
  148. </a-tab-pane>
  149. </a-tabs>
  150. <SelectShipSModal ref="SelectShipSModalRef" @select="addShip"></SelectShipSModal>
  151. <BaseShipArchiveAccessoriesList ref="BaseShipArchiveAccessoriesListRef"></BaseShipArchiveAccessoriesList>
  152. <SelectPrpductModal ref="SelectPrpductModalRef" @selectProduct="addProduct"></SelectPrpductModal>
  153. <SelectProjectModal ref="SelectProjectModalRef" @selectProject="addProject"></SelectProjectModal>
  154. </a-spin>
  155. </template>
  156. <script lang="ts">
  157. import { defineComponent, ref, reactive, computed, toRaw, onMounted } from 'vue';
  158. import { defHttp } from '/@/utils/http/axios';
  159. // import moment from "moment";
  160. import { useValidateAntFormAndTable } from '/@/hooks/system/useJvxeMethods';
  161. import { querySaleInquiryFormShipListByMainId, querySaleInquiryFormProductListByMainId, queryDataById, saveOrUpdate } from '../SaleInquiryForm.api';
  162. import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  163. import {saleInquiryFormShipColumns, saleInquiryFormProductColumns} from '../SaleInquiryForm.data';
  164. import SelectShipSModal from './SelectShipSModal.vue';
  165. import BaseShipArchiveAccessoriesList from './BaseShipArchiveAccessoriesModal.vue';
  166. import SelectPrpductModal from './SelectPrpductModal.vue';
  167. import SelectProjectModal from './SelectProjectModal.vue';
  168. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  169. import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  170. import { JDictSelectTag} from '/@/components/Form';
  171. import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  172. import JSelectUser from '/@/components/Form/src/jeecg/components/JSelectUser.vue';
  173. import JSelectDept from '/@/components/Form/src/jeecg/components/JSelectDept.vue';
  174. import { Form } from 'ant-design-vue';
  175. import moment from 'moment';
  176. const useForm = Form.useForm;
  177. export default defineComponent({
  178. name: "SaleInquiryFormForm",
  179. components:{
  180. JVxeTable,
  181. JFormContainer,
  182. SelectShipSModal,
  183. BaseShipArchiveAccessoriesList,
  184. SelectPrpductModal,
  185. JUpload,
  186. SelectProjectModal,
  187. JDictSelectTag,
  188. JSelectInput,
  189. JSelectUser,
  190. JSelectDept
  191. },
  192. props:{
  193. formDisabled:{
  194. type: Boolean,
  195. default: false
  196. },
  197. formData: { type: Object, default: ()=>{} },
  198. formBpm: { type: Boolean, default: true }
  199. },
  200. emits:['success'],
  201. setup(props, {emit}) {
  202. const loading = ref(false);
  203. const formRef = ref();
  204. var SelectPrpductModalRef = ref()
  205. var SelectProjectModalRef = ref()
  206. var inquiryPeriod = ref([])
  207. const saleInquiryFormShipTableRef = ref();
  208. const saleInquiryFormShipTable = reactive<Record<string, any>>({
  209. loading: false,
  210. columns: saleInquiryFormShipColumns,
  211. dataSource: []
  212. });
  213. const saleInquiryFormProductTableRef = ref();
  214. const saleInquiryFormProductTable = reactive<Record<string, any>>({
  215. loading: false,
  216. columns: saleInquiryFormProductColumns,
  217. dataSource: []
  218. });
  219. var SelectShipSModalRef = ref();
  220. var BaseShipArchiveAccessoriesListRef = ref();
  221. const activeKey = ref('saleInquiryFormShip');
  222. var classOption = ref([]);
  223. var customerOption =ref([]);
  224. const formData = reactive<Record<string, any>>({
  225. id: '',
  226. status: undefined,
  227. delFlag: undefined,
  228. otherStatus: '',
  229. submit: '',
  230. billDate: moment(new Date()).format('YYYY-MM-DD'),
  231. billCode: '',
  232. inquiryProject: '',
  233. inquiryCustomer: '',
  234. inquiryPlatform: '',
  235. customerInquiryNumber: '',
  236. inquiryPeriodEnd: '',
  237. inquiryPeriodBegin: '',
  238. busynessType: '',
  239. priority: '',
  240. productionClass: '',
  241. model: '',
  242. maker: '',
  243. saleDepartment: '',
  244. salesman: '',
  245. inquiryTeam: '',
  246. deliveryTime: '',
  247. attachs: '',
  248. inquiryNotes: '',
  249. });
  250. //表单验证
  251. const validatorRules = reactive({
  252. });
  253. const {resetFields, validate, validateInfos} = useForm(formData, validatorRules, {immediate: false});
  254. const dbData = {};
  255. const formItemLayout = {
  256. labelCol: {xs: {span: 24}, sm: {span: 5}},
  257. wrapperCol: {xs: {span: 24}, sm: {span: 16}},
  258. };
  259. // 表单禁用
  260. const disabled = computed(()=>{
  261. if(props.formBpm === true){
  262. if(props.formData.disabled === false){
  263. return false;
  264. }else{
  265. return true;
  266. }
  267. }
  268. return props.formDisabled;
  269. });
  270. function add() {
  271. resetFields();
  272. saleInquiryFormShipTable.dataSource = [];
  273. saleInquiryFormProductTable.dataSource = [];
  274. activeKey.value = 'saleInquiryFormShip'
  275. getOptiom()
  276. getCustomerOptions()
  277. inquiryPeriod.value = []
  278. }
  279. async function edit(row) {
  280. //主表数据
  281. await queryMainData(row.id);
  282. //子表数据
  283. const saleInquiryFormShipDataList = await querySaleInquiryFormShipListByMainId(row['id']);
  284. saleInquiryFormShipTable.dataSource = [...saleInquiryFormShipDataList];
  285. const saleInquiryFormProductDataList = await querySaleInquiryFormProductListByMainId(row['id']);
  286. saleInquiryFormProductTable.dataSource = [...saleInquiryFormProductDataList];
  287. getOptiom()
  288. getCustomerOptions()
  289. inquiryPeriod.value[0]=formData.inquiryPeriodBegin?moment(formData.inquiryPeriodBegin):''
  290. inquiryPeriod.value[1]=formData.inquiryPeriodEnd?moment(formData.inquiryPeriodEnd):''
  291. }
  292. async function queryMainData(id) {
  293. const row = await queryDataById(id);
  294. resetFields();
  295. const tmpData = {};
  296. Object.keys(formData).forEach((key) => {
  297. if(row.hasOwnProperty(key)){
  298. tmpData[key] = row[key]
  299. }
  300. })
  301. //赋值
  302. Object.assign(formData,tmpData);
  303. }
  304. const {getSubFormAndTableData, transformData} = useValidateAntFormAndTable(activeKey, {
  305. 'saleInquiryFormShip': saleInquiryFormShipTableRef,
  306. 'saleInquiryFormProduct': saleInquiryFormProductTableRef,
  307. });
  308. async function getFormData() {
  309. try {
  310. // 触发表单验证
  311. await validate();
  312. } catch ({ errorFields }) {
  313. if (errorFields) {
  314. const firstField = errorFields[0];
  315. if (firstField) {
  316. formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
  317. }
  318. }
  319. return Promise.reject(errorFields);
  320. }
  321. return transformData(toRaw(formData))
  322. }
  323. async function submitForm() {
  324. const mainData = await getFormData();
  325. const subData = await getSubFormAndTableData();
  326. const values = Object.assign({}, dbData, mainData, subData);
  327. console.log('表单提交数据', values)
  328. const isUpdate = values.id ? true : false
  329. await saveOrUpdate(values, isUpdate);
  330. //关闭弹窗
  331. emit('success');
  332. }
  333. function setFieldsValue(values) {
  334. if(values){
  335. Object.keys(values).map(k=>{
  336. formData[k] = values[k];
  337. });
  338. }
  339. }
  340. /**
  341. * 值改变事件触发-树控件回调
  342. * @param key
  343. * @param value
  344. */
  345. function handleFormChange(key, value) {
  346. formData[key] = value;
  347. }
  348. function handleDelete({row}) {
  349. saleInquiryFormShipTableRef.value?.removeRows(row)
  350. }
  351. function handleDelete1({row}) {
  352. saleInquiryFormProductTableRef.value?.removeRows(row)
  353. }
  354. function selectShip(){
  355. SelectShipSModalRef.value.getTable()
  356. }
  357. function addShip(data){
  358. var arr = data.concat(saleInquiryFormShipTable.dataSource)
  359. arr.map(item=>item.shipowner = item.relateCustomer)
  360. saleInquiryFormShipTable.dataSource=arr
  361. }
  362. function addProduct(data){
  363. var arrProduct = data.concat(saleInquiryFormProductTable.dataSource)
  364. arrProduct.map(item=>{
  365. item.productClass = item.classId
  366. item.productCode = item.code
  367. item.unit = item.measurementUnit
  368. })
  369. saleInquiryFormProductTable.dataSource=arrProduct
  370. }
  371. function addProject(data) {
  372. formData.inquiryProject = data[0].id
  373. formData.projectName = data[0].name
  374. formData.inquiryCustomer =data[0].customerId
  375. formData.customerName =data[0].customerId_dictText
  376. }
  377. function getCustomerOptions(){
  378. let params = {pageSize:'-1',status:1}
  379. defHttp.get({url:'/cuspCode/cuspCustomerProfile/list',params}, { isTransformResponse: false }).then(res=>{
  380. if(res){
  381. customerOption.value = []
  382. res.result.records.forEach(item=>{
  383. customerOption.value.push({
  384. label: item.name,
  385. value: item.id
  386. })
  387. })
  388. }
  389. })
  390. }
  391. function viewAccessory(prop){
  392. BaseShipArchiveAccessoriesListRef.value.getTable(prop.row)
  393. }
  394. function selectProducts(){
  395. SelectPrpductModalRef.value.getTable()
  396. }
  397. function setNeed(){
  398. const values = saleInquiryFormProductTableRef.value.getSelectionData()
  399. values.map(item=>{
  400. saleInquiryFormProductTable.dataSource.map(event=>{
  401. if(item.id == event.id){
  402. event.needShip = 1
  403. }
  404. })
  405. const xTable = saleInquiryFormProductTableRef.value!.getXTable();//关键代码 如果不更新 重新加载表格即可
  406. xTable.loadData(saleInquiryFormProductTable.dataSource)
  407. })
  408. }
  409. function setNotNeed(){
  410. const values = saleInquiryFormProductTableRef.value.getSelectionData()
  411. values.map(item=>{
  412. saleInquiryFormProductTable.dataSource.map(event=>{
  413. if(item.id == event.id){
  414. event.needShip = 0
  415. }
  416. })
  417. const xTable = saleInquiryFormProductTableRef.value!.getXTable();//关键代码 如果不更新 重新加载表格即可
  418. xTable.loadData(saleInquiryFormProductTable.dataSource)
  419. })
  420. }
  421. function onSearchProject(){
  422. SelectProjectModalRef.value.getTable()
  423. }
  424. function getOptiom(){
  425. defHttp
  426. .get({ url: 'baseCode/baseProductClass/list'}, { isTransformResponse: false })
  427. .then((res) => {
  428. if (res.success) {
  429. classOption.value = []
  430. res.result.records.forEach(element => {
  431. var obj = {
  432. label: element.name?element.name:'无名称请维护',
  433. value: element.id?element.id:''
  434. };
  435. classOption.value.push( obj)
  436. });
  437. }
  438. })
  439. .finally(() => {
  440. // loading.value = false;
  441. });
  442. }
  443. function onChangeInquiryPeriod(data){
  444. inquiryPeriod.value = data
  445. formData.inquiryPeriodBegin = data[0].format('YYYY-MM-DD')
  446. formData.inquiryPeriodEnd = data[1].format('YYYY-MM-DD')
  447. }
  448. return {
  449. saleInquiryFormShipTableRef,
  450. saleInquiryFormShipTable,
  451. saleInquiryFormProductTableRef,
  452. saleInquiryFormProductTable,
  453. validatorRules,
  454. validateInfos,
  455. activeKey,
  456. loading,
  457. formData,
  458. setFieldsValue,
  459. handleFormChange,
  460. formItemLayout,
  461. disabled,
  462. getFormData,
  463. submitForm,
  464. SelectShipSModalRef,
  465. add,
  466. edit,
  467. formRef,
  468. selectShip,
  469. addShip,
  470. addProduct,
  471. BaseShipArchiveAccessoriesListRef,
  472. viewAccessory,
  473. handleDelete,
  474. handleDelete1,
  475. selectProducts,
  476. setNeed,
  477. setNotNeed,
  478. SelectPrpductModalRef,
  479. SelectProjectModalRef,
  480. onSearchProject,
  481. addProject,
  482. getOptiom,
  483. classOption,
  484. getCustomerOptions,
  485. customerOption,
  486. inquiryPeriod,
  487. onChangeInquiryPeriod
  488. }
  489. }
  490. });
  491. </script>
  492. <style lang="less" scoped>
  493. /** 时间和数字输入框样式 */
  494. :deep(.ant-input-number) {
  495. width: 100%;
  496. }
  497. :deep(.ant-calendar-picker) {
  498. width: 100%;
  499. }
  500. /deep/.vxe-table--body-wrapper{
  501. height: 100% !important;
  502. }
  503. /deep/.ant-modal-body{
  504. padding: 24px !important;
  505. }
  506. /deep/.ant-form-item{
  507. margin-bottom: 8px !important;
  508. }
  509. </style>