commissionContractFormForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <template>
  2. <a-spin :spinning="loading">
  3. <JFormContainer :disabled="disabled">
  4. <template #detail>
  5. <a-form v-bind="formItemLayout" name="commissionContractForm" ref="formRef">
  6. <a-row>
  7. <a-col :span="12">
  8. <a-form-item label="合同编号(bill code)" v-bind="validateInfos.billCode" id="commissionContractForm-billCode" name="billCode">
  9. <a-input v-model:value="formData.billCode" placeholder="自动生成" disabled />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :span="12">
  13. <a-form-item label="单据日期(bill date)" v-bind="validateInfos.billDate" id="commissionContractForm-billDate" name="billDate">
  14. <a-date-picker
  15. placeholder="请选择单据日期(bill date)"
  16. v-model:value="formData.billDate"
  17. value-format="YYYY-MM-DD"
  18. style="width: 100%"
  19. allow-clear
  20. />
  21. </a-form-item>
  22. </a-col>
  23. <a-col :span="12">
  24. <a-form-item label="供应商(supplier)" v-bind="validateInfos.supplier" id="commissionContractForm-supplier" name="supplier">
  25. <JSelect v-model:value="formData.supplierId" :get-option-url="supplierOption" :showField="showField" @change="handleSupplierChange"></JSelect>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :span="12">
  29. <a-form-item label="币种(currency)" v-bind="validateInfos.currency" id="commissionContractForm-currency" name="currency">
  30. <JDictSelectTag v-model:value="formData.currency" placeholder="请选择" dictCode="currency" />
  31. </a-form-item>
  32. </a-col>
  33. <a-col :span="12">
  34. <a-form-item
  35. label="销售部门(sale department)"
  36. v-bind="validateInfos.saleDepartmen"
  37. id="commissionContractForm-saleDepartmen"
  38. name="saleDepartmen"
  39. >
  40. <a-input v-model:value="formData.saleDepartmenName" placeholder="请输入" allow-clear disabled />
  41. </a-form-item>
  42. </a-col>
  43. <a-col :span="12">
  44. <a-form-item label="业务员(salesman)" v-bind="validateInfos.salesman" id="commissionContractForm-salesman" name="salesman">
  45. <a-input v-model:value="formData.salesmanName" placeholder="请输入采购员(salesman)" allow-clear disabled />
  46. </a-form-item>
  47. </a-col>
  48. <a-col :span="12">
  49. <a-form-item label="备注(notes)" v-bind="validateInfos.notes" id="commissionContractForm-notes" name="notes">
  50. <a-input v-model:value="formData.notes" AutoComplete="off" />
  51. </a-form-item>
  52. </a-col>
  53. <a-col :span="12">
  54. <a-form-item label="附件(attachs)" v-bind="validateInfos.attachs" id="commissionContractForm-attachs" name="attachs">
  55. <JUpload v-model:value="formData.attachs"></JUpload>
  56. </a-form-item>
  57. </a-col>
  58. </a-row>
  59. </a-form>
  60. </template>
  61. </JFormContainer>
  62. <!-- 子表单区域 -->
  63. <a-tabs v-model:activeKey="activeKey" animated style="padding: 24px; padding-top: 0px">
  64. <a-tab-pane tab="佣金合同 - 产品明细(product details)" key="commissionContractFormProduct" :forceRender="true">
  65. <a-button type="primary" style="margin-right: 1%;margin-bottom: 1%;" @click="selectProductList"> 选择产品(select products)</a-button>
  66. <j-vxe-table
  67. :keep-source="true"
  68. resizable
  69. ref="commissionContractFormProductTableRef"
  70. :loading="commissionContractFormProductTable.loading"
  71. :columns="commissionContractFormProductTable.columns"
  72. :dataSource="commissionContractFormProductTable.dataSource"
  73. :maxHeight="340"
  74. :disabled="disabled"
  75. :rowNumber="true"
  76. :rowSelection="true"
  77. asyncRemove
  78. >
  79. <template #action="props">
  80. <a-popconfirm title="确定删除吗?" @confirm="handleDelete(props)">
  81. <a>删除(delete)</a>
  82. </a-popconfirm>
  83. </template>
  84. </j-vxe-table>
  85. </a-tab-pane>
  86. </a-tabs>
  87. <SelectPrpductModal ref="SelectPrpductModalRef" @selectProduct ='addProduct'></SelectPrpductModal>
  88. </a-spin>
  89. </template>
  90. <script lang="ts">
  91. import { defineComponent, ref, reactive, computed, toRaw } from 'vue';
  92. import { useValidateAntFormAndTable } from '/@/hooks/system/useJvxeMethods';
  93. import { queryProductListByMainId, queryDataById, supplierOption, saveOrUpdate,} from '../commissionContractForm.api';
  94. import { JVxeTable } from '/@/components/jeecg/JVxeTable';
  95. import { ProductColumns } from '../commissionContractForm.data';
  96. import SelectPrpductModal from '../../../publicComponents/SelectPrpductModal.vue';
  97. import JFormContainer from '/@/components/Form/src/container/JFormContainer.vue';
  98. import JUpload from '/@/components/Form/src/jeecg/components/JUpload/JUpload.vue';
  99. import { JDictSelectTag, ApiSelect,JSelect} from '/@/components/Form';
  100. import { Form, message } from 'ant-design-vue';
  101. import { useUserStore } from '/@/store/modules/user';
  102. import moment from 'moment';
  103. const useForm = Form.useForm;
  104. export default defineComponent({
  105. name: 'commissionContractForm',
  106. components: {
  107. JVxeTable,
  108. JFormContainer,
  109. SelectPrpductModal,
  110. JUpload,
  111. JDictSelectTag,
  112. ApiSelect,
  113. JSelect
  114. },
  115. props: {
  116. formDisabled: {
  117. type: Boolean,
  118. default: false,
  119. },
  120. formData: { type: Object, default: () => {} },
  121. formBpm: { type: Boolean, default: true },
  122. },
  123. emits: ['success'],
  124. setup(props, { emit }) {
  125. var showField = ref('currency+name');
  126. const userStore = useUserStore();
  127. const loading = ref(false);
  128. const formRef = ref();
  129. const SelectPrpductModalRef = ref();
  130. const commissionContractFormProductTableRef = ref();
  131. const commissionContractFormProductTable = reactive<Record<string, any>>({
  132. loading: false,
  133. columns: ProductColumns,
  134. dataSource: [],
  135. });
  136. const activeKey = ref('commissionContractFormProduct');
  137. const formData = reactive<Record<string, any>>({
  138. id: '',
  139. status: undefined,
  140. delFlag: undefined,
  141. submit: undefined,
  142. billCode: '',
  143. billDate: moment(new Date()).format('YYYY-MM-DD'),
  144. supplierId: '',
  145. supplierName: '',
  146. currency: '',
  147. salesman:'',
  148. salesmanName:'',
  149. saleDepartmen:'',
  150. saleDepartmenName:'',
  151. notes: '',
  152. attachs: '',
  153. });
  154. //表单验证
  155. const validatorRules = reactive({
  156. });
  157. const {resetFields, validate, validateInfos} = useForm(formData, validatorRules, {immediate: false});
  158. const dbData = {};
  159. const formItemLayout = {
  160. labelCol: { xs: { span: 24 }, sm: { span: 7 } },
  161. wrapperCol: { xs: { span: 24 }, sm: { span: 15 } },
  162. labelCol1: { xs: { span: 24 }, sm: { span: 7 } },
  163. wrapperCol1: { xs: { span: 24 }, sm: { span: 15 } },
  164. };
  165. // 表单禁用
  166. const disabled = computed(() => {
  167. if (props.formBpm === true) {
  168. if (props.formData.disabled === false) {
  169. return false;
  170. } else {
  171. return true;
  172. }
  173. }
  174. return props.formDisabled;
  175. });
  176. function add() {
  177. resetFields();
  178. commissionContractFormProductTable.dataSource = [];
  179. activeKey.value = 'commissionContractFormProduct';
  180. formData.salesman = userStore.getUserInfo.username;
  181. formData.salesmanName = userStore.getUserInfo.realname;
  182. formData.saleDepartmen = userStore.getUserInfo.orgCode;
  183. formData.saleDepartmenName = userStore.getUserInfo.orgName;
  184. }
  185. async function edit(row) {
  186. //主表数据
  187. await queryMainData(row.id);
  188. const commissionContractFormProductDataList = await queryProductListByMainId(row['id']);
  189. commissionContractFormProductTable.dataSource = [...commissionContractFormProductDataList];
  190. }
  191. async function queryMainData(id) {
  192. const row = await queryDataById(id);
  193. resetFields();
  194. const tmpData = {};
  195. Object.keys(formData).forEach((key) => {
  196. if (row.hasOwnProperty(key)) {
  197. tmpData[key] = row[key];
  198. }
  199. });
  200. //赋值
  201. Object.assign(formData, tmpData);
  202. }
  203. const { getSubFormAndTableData, transformData } = useValidateAntFormAndTable(activeKey, {
  204. platCommissionContractProduct: commissionContractFormProductTableRef,
  205. });
  206. async function getFormData() {
  207. try {
  208. // 触发表单验证
  209. await validate();
  210. } catch ({ errorFields }) {
  211. if (errorFields) {
  212. const firstField = errorFields[0];
  213. if (firstField) {
  214. formRef.value.scrollToField(firstField.name, { behavior: 'smooth', block: 'center' });
  215. }
  216. }
  217. return Promise.reject(errorFields);
  218. }
  219. return transformData(toRaw(formData));
  220. }
  221. async function submitForm() {
  222. var xTable = commissionContractFormProductTableRef.value!.getXTable()
  223. if(xTable.data.length==0){
  224. message.warning('请添加产品明细')
  225. }else{
  226. commissionContractFormProductTableRef.value!.validateTable().then(async (errMap) => {
  227. if (errMap) {
  228. console.log('表单验证未通过:', { errMap });
  229. } else {
  230. const mainData = await getFormData();
  231. const subData = await getSubFormAndTableData();
  232. const values = Object.assign({}, dbData, mainData, subData);
  233. console.log('表单提交数据', values)
  234. const isUpdate = values.id ? true : false
  235. const isRevise = values.submit=='1' ? true : false
  236. await saveOrUpdate(values, isUpdate,isRevise);
  237. //关闭弹窗
  238. emit('success');
  239. }
  240. })
  241. }
  242. }
  243. function setFieldsValue(values) {
  244. if (values) {
  245. Object.keys(values).map((k) => {
  246. formData[k] = values[k];
  247. });
  248. }
  249. }
  250. function selectProductList(){
  251. SelectPrpductModalRef.value.getTable()
  252. }
  253. function addProduct(data) {
  254. data.map((item) => {
  255. item.productClass = item.classId_dictText;
  256. item.productCode = item.code;
  257. item.productId = item.id;
  258. item.id = undefined
  259. });
  260. var xTable = commissionContractFormProductTableRef.value!.getXTable();
  261. var arrProduct = xTable.data.concat(data);
  262. commissionContractFormProductTable.dataSource = arrProduct;
  263. } //产品明细-删除行
  264. function handleDelete(prop) {
  265. var xTable = commissionContractFormProductTableRef.value!.getXTable()
  266. var newArray = [...xTable.data]
  267. newArray.splice(prop.rowIndex, 1)
  268. commissionContractFormProductTable.dataSource = newArray
  269. } /**
  270. * 值改变事件触发-树控件回调
  271. * @param key
  272. * @param value
  273. */
  274. function handleFormChange(key, value) {
  275. formData[key] = value;
  276. }
  277. async function handleSupplierChange(prop){
  278. if (prop) {
  279. var params = { id: prop };
  280. var obj = await supplierOption(params);
  281. formData.supplierName = obj.records[0].name;
  282. } else {
  283. formData.supplierId = '';
  284. formData.supplierName = '';
  285. }
  286. }
  287. return {
  288. commissionContractFormProductTableRef,
  289. commissionContractFormProductTable,
  290. validatorRules,
  291. validateInfos,
  292. activeKey,
  293. loading,
  294. formData,
  295. setFieldsValue,
  296. handleFormChange,
  297. formItemLayout,
  298. disabled,
  299. getFormData,
  300. submitForm,
  301. add,
  302. edit,
  303. formRef,
  304. selectProductList,
  305. SelectPrpductModalRef,
  306. addProduct,
  307. handleDelete,
  308. supplierOption,
  309. handleSupplierChange,
  310. showField
  311. };
  312. },
  313. });
  314. </script>
  315. <style lang="less" scoped>
  316. /** 时间和数字输入框样式 */
  317. :deep(.ant-input-number) {
  318. width: 100%;
  319. }
  320. :deep(.ant-calendar-picker) {
  321. width: 100%;
  322. }
  323. // /deep/.vxe-table--body-wrapper{
  324. // height: 100% !important;
  325. // }
  326. /deep/.ant-modal-body {
  327. padding: 24px !important;
  328. }
  329. /deep/.ant-form-item {
  330. margin-bottom: 8px !important;
  331. }
  332. /deep/.vxe-cell--valid-error-msg{
  333. color: white !important;
  334. background-color: white !important;
  335. }
  336. </style>