otherInForm.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <a-spin :spinning="loading">
  3. <JFormContainer :disabled="disabled">
  4. <template #detail>
  5. <a-form v-bind="formItemLayout" name="SaleOrderForm" ref="formRef">
  6. <a-row>
  7. <a-col :span="12">
  8. <a-form-item label="入库单号(bill code)" v-bind="validateInfos.billCode" id="SaleOrderForm-billCode" name="billCode">
  9. <a-input v-model:value="formData.billCode" placeholder="自动生成" disabled></a-input>
  10. </a-form-item>
  11. </a-col>
  12. <a-col :span="12">
  13. <a-form-item label="入库日期(bill date)" v-bind="validateInfos.billDate" id="SaleOrderForm-billDate" name="billDate">
  14. <a-date-picker placeholder="请选择入库日期(bill date)" v-model:value="formData.billDate" value-format="YYYY-MM-DD" style="width: 100%" allow-clear />
  15. </a-form-item>
  16. </a-col>
  17. <a-col :span="12">
  18. <a-form-item label="项目(project)" v-bind="validateInfos.projectName" id="SaleOrderForm-projectName" name="projectName">
  19. <a-input-search v-model:value="formData.projectName" placeholder="请输入项目(project)" readOnly AutoComplete="off" 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="供应商(supplier)" v-bind="validateInfos.supplier" id="SaleOrderForm-supplier" name="supplier">
  24. <JSelect v-model:value="formData.supplier" :get-option-url="supplierOption" :showField="showField" @change="changeSupplier"></JSelect>
  25. </a-form-item>
  26. </a-col>
  27. <a-col :span="12">
  28. <a-form-item label="产品分类(production class)" v-bind="validateInfos.productionClass" id="SaleOrderForm-productionClass" name="productionClass">
  29. <ApiSelect
  30. :api="ClassList"
  31. showSearch
  32. v-model:value="formData.productionClass"
  33. :filterOption="true"
  34. resultField="records"
  35. labelField="name"
  36. valueField="id"
  37. :params='{pageSize:-1}'
  38. optionFilterProp='label'
  39. />
  40. </a-form-item>
  41. </a-col>
  42. <a-col :span="12">
  43. <a-form-item label="机型(model)" v-bind="validateInfos.model" id="SaleOrderForm-model" name="model">
  44. <JDictSelectTag v-model:value="formData.model" placeholder="请选择" dictCode="model_typer"/>
  45. </a-form-item>
  46. </a-col>
  47. <a-col :span="12">
  48. <a-form-item label="厂家(maker)" v-bind="validateInfos.maker" id="SaleOrderForm-maker" name="maker">
  49. <JDictSelectTag v-model:value="formData.maker" placeholder="请选择" dictCode="factory"/>
  50. </a-form-item>
  51. </a-col>
  52. <a-col :span="12">
  53. <a-form-item label="货位(goods allocation)" v-bind="validateInfos.goodsAllocation" id="SaleOrderForm-goodsAllocation" name="goodsAllocation">
  54. <JDictSelectTag v-model:value="formData.goodsAllocation" placeholder="请选择" dictCode="goods_allocation"/>
  55. </a-form-item>
  56. </a-col>
  57. <a-col :span="12">
  58. <a-form-item label="仓库(warehouse)" v-bind="validateInfos.warehouse" id="SaleOrderForm-warehouse" name="warehouse">
  59. <JDictSelectTag v-model:value="formData.warehouse" placeholder="请选择" dictCode="warehouse"/>
  60. </a-form-item>
  61. </a-col>
  62. <a-col :span="12">
  63. <a-form-item label="备注(notes)" v-bind="validateInfos.notes" id="SaleOrderForm-notes" name="notes">
  64. <a-input v-model:value="formData.notes" AutoComplete="off"></a-input>
  65. </a-form-item>
  66. </a-col>
  67. <a-col :span="12">
  68. <a-form-item label="附件(attachs)" v-bind="validateInfos.attachs" id="PuechaseInquiryFormForm-attachs" name="attachs" >
  69. <JUpload v-model:value="formData.attachs"></JUpload>
  70. </a-form-item>
  71. </a-col>
  72. </a-row>
  73. </a-form>
  74. </template>
  75. </JFormContainer>
  76. <!-- 子表单区域 -->
  77. <a-tabs v-model:activeKey="activeKey" animated style=" padding: 24px;padding-top: 0px;">
  78. <a-tab-pane tab="其他入库 - 船明细(ship details)" key="otherInShip" :forceRender="true">
  79. <a-button type="primary" style="margin-right: 1%;margin-bottom: 1%;" @click="selectShip"> 选择船(select ship)</a-button>
  80. <j-vxe-table
  81. :keep-source="true"
  82. resizable
  83. ref="otherInShipTableRef"
  84. :loading="otherInShipTable.loading"
  85. :columns="otherInShipTable.columns"
  86. :dataSource="otherInShipTable.dataSource"
  87. :maxHeight="340"
  88. :disabled="disabled"
  89. :rowNumber="true"
  90. :rowSelection="true"
  91. >
  92. <template #action="props" >
  93. <a @click="viewAccessory(props)">查看配件信息(view accessory information)</a>
  94. </template>
  95. </j-vxe-table>
  96. </a-tab-pane>
  97. <a-tab-pane tab="其他入库 - 入库明细(arrive details)" key="stockIn" :forceRender="true">
  98. <a-button type="primary" style="margin-right: 1%;margin-bottom: 1%;" @click="selectProductList"> 选择产品(select product)</a-button>
  99. <j-vxe-table
  100. :keep-source="true"
  101. resizable
  102. ref="stockInTableRef"
  103. :loading="stockInTable.loading"
  104. :columns="stockInTable.columns"
  105. :dataSource="stockInTable.dataSource"
  106. :maxHeight="340"
  107. :disabled="disabled"
  108. :rowNumber="true"
  109. :rowSelection="true"
  110. asyncRemove
  111. >
  112. <template #action="props">
  113. <a-popconfirm title="确定删除吗?" @confirm="handleDelete(props)">
  114. <a>删除(delete)</a>
  115. </a-popconfirm>
  116. <!-- 逻辑不通暂时取消次功能 -->
  117. <!-- <a>复制(copy)</a> -->
  118. </template>
  119. </j-vxe-table>
  120. </a-tab-pane>
  121. </a-tabs>
  122. <BaseShipArchiveAccessoriesModal ref="BaseShipArchiveAccessoriesModalRef"></BaseShipArchiveAccessoriesModal>
  123. <SelectPrpductModal ref="SelectPrpductModalRef" @selectProduct ='addProduct'></SelectPrpductModal>
  124. <SelectProjectModal ref="SelectProjectModalRef" @selectProject="addProject"></SelectProjectModal>
  125. <SelectShipSModal ref="SelectShipSModalRef" @select="addShip"></SelectShipSModal>
  126. </a-spin>
  127. </template>
  128. <script lang="ts">
  129. import { defineComponent, ref, reactive, computed, toRaw} from 'vue';
  130. import { defHttp } from '/@/utils/http/axios';
  131. import { useValidateAntFormAndTable } from '/@/hooks/system/useJvxeMethods';
  132. import { queryOtherInFormShipFormShippTable, querystockInByMainId, queryDataById, saveOrUpdate,supplierOption,ClassList} from '../otherInForm.api';
  133. import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  134. import {otherInShipColumns, stockInColumns} from '../otherInForm.data';
  135. import BaseShipArchiveAccessoriesModal from '../../../publicComponents/BaseShipArchiveAccessoriesModal.vue';
  136. import SelectPrpductModal from '../../../publicComponents/SelectPrpductModal.vue';
  137. import SelectProjectModal from '../../../publicComponents/SelectProjectModal.vue';
  138. import SelectShipSModal from '../../../publicComponents/SelectShipSModal.vue';
  139. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  140. import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  141. import JSelectInput from '/@/components/Form/src/jeecg/components/JSelectInput.vue';
  142. import { JDictSelectTag,ApiSelect,JSelect} from '/@/components/Form';
  143. import { Form, message } from 'ant-design-vue';
  144. import moment from 'moment';
  145. const useForm = Form.useForm;
  146. export default defineComponent({
  147. name: "otherInForm",
  148. components:{
  149. JVxeTable,
  150. JFormContainer,
  151. JUpload,
  152. JDictSelectTag,
  153. BaseShipArchiveAccessoriesModal,
  154. SelectProjectModal,
  155. SelectPrpductModal,
  156. SelectShipSModal,
  157. JSelectInput,
  158. ApiSelect,
  159. JSelect
  160. },
  161. props:{
  162. formDisabled:{
  163. type: Boolean,
  164. default: false
  165. },
  166. formData: { type: Object, default: ()=>{} },
  167. formBpm: { type: Boolean, default: true }
  168. },
  169. emits:['success'],
  170. setup(props, {emit}) {
  171. const loading = ref(false);
  172. var showField = ref('currency+name');
  173. const formRef = ref();
  174. const SelectProjectModalRef = ref()
  175. const SelectPrpductModalRef = ref()
  176. const SelectShipSModalRef = ref();
  177. const otherInShipTableRef = ref();
  178. const BaseShipArchiveAccessoriesModalRef = ref();
  179. const otherInShipTable = reactive<Record<string, any>>({
  180. loading: false,
  181. columns: otherInShipColumns,
  182. dataSource: []
  183. });
  184. const stockInTableRef = ref();
  185. const stockInTable = reactive<Record<string, any>>({
  186. loading: false,
  187. columns: stockInColumns,
  188. dataSource: []
  189. });
  190. const activeKey = ref('otherInShip');
  191. const formData = reactive<Record<string, any>>({
  192. id: '',
  193. status: undefined,
  194. delFlag: undefined,
  195. billCode:'',
  196. billDate: moment(new Date()).format('YYYY-MM-DD'),
  197. project: '',
  198. projectName:'',
  199. supplier:"",
  200. supplierName:'',
  201. productionClass: '',
  202. model:'',
  203. maker: '',
  204. goodsAllocation:'',
  205. warehouse:'',
  206. notes:'',
  207. attachs:'',
  208. });
  209. //表单验证
  210. const validatorRules = reactive({
  211. projectName: [
  212. { required: true, message: '请选择项目(select project)' }
  213. ],
  214. supplier: [
  215. { required: true, message: '请选择供应商(select supplier)' }
  216. ],
  217. model: [
  218. { required: true, message: '请选择机型(model)' }
  219. ],
  220. });
  221. const {resetFields, validate, validateInfos} = useForm(formData, validatorRules, {immediate: false});
  222. const dbData = {};
  223. const formItemLayout = {
  224. labelCol: {xs: {span: 24}, sm: {span: 5}},
  225. wrapperCol: {xs: {span: 24}, sm: {span: 16}},
  226. labelCol1: {xs: {span: 24}, sm: {span: 7}},
  227. wrapperCol1: {xs: {span: 24}, sm: {span: 15}},
  228. };
  229. // 表单禁用
  230. const disabled = computed(()=>{
  231. if(props.formBpm === true){
  232. if(props.formData.disabled === false){
  233. return false;
  234. }else{
  235. return true;
  236. }
  237. }
  238. return props.formDisabled;
  239. });
  240. function add() {
  241. resetFields();
  242. otherInShipTable.dataSource = [];
  243. stockInTable.dataSource = [];
  244. activeKey.value = 'otherInShip'
  245. }
  246. async function edit(row) {
  247. //主表数据
  248. await queryMainData(row.id);
  249. //子表数据
  250. const otherInShipDataList = await queryOtherInFormShipFormShippTable(row['id']);
  251. otherInShipTable.dataSource = [...otherInShipDataList];
  252. const stockInDataList = await querystockInByMainId(row['id']);
  253. stockInTable.dataSource = [...stockInDataList];
  254. }
  255. async function queryMainData(id) {
  256. const row = await queryDataById(id);
  257. resetFields();
  258. const tmpData = {};
  259. Object.keys(formData).forEach((key) => {
  260. if(row.hasOwnProperty(key)){
  261. tmpData[key] = row[key]
  262. }
  263. })
  264. //赋值
  265. Object.assign(formData,tmpData);
  266. }
  267. const {getSubFormAndTableData, transformData} = useValidateAntFormAndTable(activeKey, {
  268. 'storePurchaseOtherShip': otherInShipTableRef,
  269. 'storePurchaseOtherDetails': stockInTableRef,
  270. });
  271. async function getFormData() {
  272. try {
  273. // 触发表单验证
  274. await validate();
  275. } catch ({ errorFields }) {
  276. if (errorFields) {
  277. const firstField = errorFields[0];
  278. if (firstField) {
  279. formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
  280. }
  281. }
  282. return Promise.reject(errorFields);
  283. }
  284. return transformData(toRaw(formData))
  285. }
  286. async function submitForm() {
  287. var xTable = stockInTableRef.value!.getXTable()
  288. if( xTable.data.length==0){
  289. message.error('请添加入库明细!');
  290. }else{
  291. stockInTableRef.value!.validateTable().then(async (errMap) => {
  292. if (errMap) {
  293. console.log('表单验证未通过:', { errMap });
  294. } else {
  295. const mainData = await getFormData();
  296. const subData = await getSubFormAndTableData();
  297. const values = Object.assign({}, dbData, mainData, subData);
  298. console.log('表单提交数据', values)
  299. const isUpdate = values.id ? true : false
  300. await saveOrUpdate(values, isUpdate);
  301. //关闭弹窗
  302. emit('success');
  303. }
  304. })
  305. }
  306. }
  307. function setFieldsValue(values) {
  308. if(values){
  309. Object.keys(values).map(k=>{
  310. formData[k] = values[k];
  311. });
  312. }
  313. }
  314. //查看配件信息
  315. function viewAccessory(prop){
  316. BaseShipArchiveAccessoriesModalRef.value.getTable(prop.row)
  317. }
  318. //入库明细-删除行
  319. function handleDelete(prop) {
  320. var xTable = stockInTableRef.value!.getXTable()
  321. var newArray = [...xTable.data]
  322. newArray.splice(prop.rowIndex, 1)
  323. stockInTable.dataSource = newArray
  324. }
  325. function onSearchProject(){
  326. SelectProjectModalRef.value.getTable()
  327. }
  328. function addProject(data){
  329. if(data.lenght==0){
  330. formData.projectName = ''
  331. formData.projectName = ''
  332. }else{
  333. formData.project = data[0].id
  334. formData.projectName = data[0].code
  335. }
  336. }
  337. function addProduct(data){
  338. data.map(item=>{
  339. item.productClass = item.classId_dictText
  340. item.productCode = item.code
  341. item.productId = item.id
  342. item.id = undefined
  343. })
  344. var xTable = stockInTableRef.value!.getXTable()
  345. var arrProduct = xTable.data.concat(data)
  346. stockInTable.dataSource=arrProduct
  347. }
  348. function selectProductList(){
  349. SelectPrpductModalRef.value.getTable()
  350. }
  351. function selectShip(){
  352. SelectShipSModalRef.value.getTable()
  353. }
  354. function addShip(data){
  355. data.map(item=>{
  356. item.shipowner = item.relateCustomer
  357. item.shipId = item.id;
  358. item.id=undefined
  359. })
  360. var xTable = otherInShipTableRef.value!.getXTable()
  361. var arr = xTable.data.concat(data)
  362. otherInShipTable.dataSource=arr
  363. }
  364. async function changeSupplier(prop){
  365. if(prop){
  366. var params={id:prop}
  367. var obj = await supplierOption(params)
  368. formData.supplierName = obj.records[0].name
  369. }else{
  370. formData.supplier = ''
  371. formData.supplierName = ''
  372. }
  373. }
  374. /**
  375. * 值改变事件触发-树控件回调
  376. * @param key
  377. * @param value
  378. */
  379. function handleFormChange(key, value) {
  380. formData[key] = value;
  381. }
  382. return {
  383. otherInShipTableRef,
  384. otherInShipTable,
  385. stockInTableRef,
  386. stockInTable,
  387. validatorRules,
  388. validateInfos,
  389. activeKey,
  390. loading,
  391. formData,
  392. setFieldsValue,
  393. handleFormChange,
  394. formItemLayout,
  395. disabled,
  396. getFormData,
  397. submitForm,
  398. add,
  399. edit,
  400. formRef,
  401. handleDelete,
  402. BaseShipArchiveAccessoriesModalRef,
  403. viewAccessory,
  404. onSearchProject,
  405. SelectProjectModalRef,
  406. addProject,
  407. selectProductList,
  408. SelectPrpductModalRef,
  409. addProduct,
  410. selectShip,
  411. SelectShipSModalRef,
  412. addShip,
  413. changeSupplier,
  414. ClassList,
  415. supplierOption,
  416. showField
  417. }
  418. }
  419. });
  420. </script>
  421. <style lang="less" scoped>
  422. /** 时间和数字输入框样式 */
  423. :deep(.ant-input-number) {
  424. width: 100%;
  425. }
  426. :deep(.ant-calendar-picker) {
  427. width: 100%;
  428. }
  429. /deep/.vxe-table--body-wrapper{
  430. height: 100% !important;
  431. }
  432. /deep/.ant-modal-body{
  433. padding: 24px !important;
  434. }
  435. /deep/.ant-form-item{
  436. margin-bottom: 8px !important;
  437. }
  438. /deep/.vxe-cell--valid-error-msg{
  439. color: white !important;
  440. background-color: white !important;
  441. }
  442. </style>