123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582 |
- <template>
- <div class="form">
- <van-nav-bar :title="$t('salesContract.name')" :left-text="$t('common.back')" left-arrow @click-left="onClickLeft">
- </van-nav-bar>
- <testForm v-model="formData.data" :formOption="formOption" :formConfig="formConfig" :rules="rules" @onSubmit="onSubmit(20)"
- @otherBtnClick="onSubmit(10)" ref="formDom"></testForm>
- </div>
- </template>
- <script setup>
- import { ref, reactive, getCurrentInstance, onMounted } from "vue";
- import { showSuccessToast, showFailToast } from "vant";
- import { useRoute } from "vue-router";
- import testForm from "@/components/testForm/index.vue";
- const proxy = getCurrentInstance().proxy;
- const route = useRoute();
- const formDom = ref(null);
- const formData = reactive({
- data: {
- salesContractDetailsList: [],
- },
- });
- const rules = {
- customerId: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseSelectTheCustomerName"),
- },
- ],
- deliveryDate: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseSelectTheDeliveryDeadline"),
- },
- ],
- payMethod: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseSelectThePaymentMethod"),
- },
- ],
- freightPayer: [
- {
- required: true,
- message: proxy.t("salesContract.PleaseSelectTheFreightPayer"),
- },
- ],
- productId: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseSelectTheProductName"),
- },
- ],
- isCustomized: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseSelectWhetherToCustomize"),
- },
- ],
- unitPrice: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseEnterTheUnitPrice"),
- },
- ],
- quantity: [
- {
- required: true,
- message: proxy.t("salesContract.pleaseEnterTheQuantity"),
- },
- ],
- devUserId: [
- {
- required: true,
- message: "请选择研发负责人",
- },
- ],
- };
- const formOption = reactive({
- readonly: false, //用于控制整个表单是否只读
- disabled: false,
- labelAlign: "top",
- scroll: true,
- labelWidth: "62pk",
- hiddenSubmitBtn: false,
- otherBtn: true,
- otherBtnText: "暂存",
- btnConfig: {
- isNeed: true,
- prop: "salesContractDetailsList",
- plain: true,
- listTitle: proxy.t("salesContract.contractDetails"),
- listConfig: [
- {
- type: "picker",
- label: proxy.t("salesContract.productName"),
- prop: "productId",
- itemType: "onePicker",
- showPicker: false,
- readonly: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- isNeedSearch: true, //是否需要关键字过滤数据
- searchKeyword: "",
- onSearchData: (keyword) => {
- getProductData(keyword);
- },
- },
- {
- type: "picker",
- label: proxy.t("salesContract.whetherToCustomize"),
- prop: "isCustomized",
- itemType: "onePicker",
- showPicker: false,
- readonly: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [
- {
- label: proxy.t("salesContract.yes"),
- value: "1",
- },
- {
- label: proxy.t("salesContract.no"),
- value: "0",
- },
- ],
- },
- {
- type: "input",
- itemType: "number",
- label: proxy.t("salesContract.unitPrice"),
- prop: "unitPrice",
- clearable: true,
- changeFn: (index, val) => {
- changeAmount(index);
- },
- },
- {
- type: "input",
- itemType: "digit",
- label: proxy.t("salesContract.quantity"),
- prop: "quantity",
- clearable: true,
- changeFn: (index, val) => {
- changeAmount(index);
- },
- },
- {
- type: "input",
- itemType: "number",
- label: proxy.t("salesContract.amountSubtotal"),
- prop: "total",
- placeholder: proxy.t(
- "salesContract.automaticallyCalculatedBasedOnUnitPriceAndQuantity"
- ),
- readonly: true,
- },
- {
- type: "input",
- itemType: "textarea",
- label: "备注",
- prop: "productRemark",
- },
- ],
- clickFn: () => {
- if (
- formData.data.salesContractDetailsList &&
- formData.data.salesContractDetailsList.length > 0
- ) {
- formData.data.salesContractDetailsList.push({
- productId: "",
- quantity: "",
- });
- } else {
- formData.data.salesContractDetailsList = [
- {
- productId: "",
- quantity: "",
- },
- ];
- }
- },
- },
- });
- const formConfig = reactive([
- {
- type: "picker",
- label: "卖方公司",
- prop: "sellCorporationId",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- changeFn: (val, data) => {
- proxy.formChange(val, data, formData);
- changeSellId(val.selectedValues[0]);
- data.showPicker = false;
- },
- },
- {
- type: "input",
- itemType: "text",
- label: "国家",
- prop: "sellCountryName",
- },
- {
- type: "input",
- itemType: "text",
- label: "省",
- prop: "sellProvinceName",
- },
- {
- type: "input",
- itemType: "text",
- label: "城市",
- prop: "sellCityName",
- },
- {
- type: "input",
- itemType: "textarea",
- label: "详细地址",
- prop: "sellAddress",
- },
- {
- type: "picker",
- label: "收款账号",
- prop: "shroffAccountId",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- changeFn: (val, data) => {
- proxy.formChange(val, data, formData);
- changeShroffAccount(val.selectedValues[0]);
- data.showPicker = false;
- },
- },
- {
- type: "input",
- itemType: "text",
- label: "账户名",
- prop: "sellAccountName",
- },
- {
- type: "input",
- itemType: "text",
- label: "开户行",
- prop: "sellOpeningBank",
- },
- {
- type: "input",
- itemType: "text",
- label: "账号",
- prop: "sellAccountOpening",
- },
- {
- type: "input",
- itemType: "text",
- label: "银行号",
- prop: "sellInterbankNumber",
- },
- {
- type: "picker",
- label: proxy.t("salesContract.customerName"),
- prop: "customerId",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- isNeedSearch: true, //是否需要关键字过滤数据
- searchKeyword: "",
- onSearchData: (keyword) => {
- getCustomerData(keyword);
- },
- },
- {
- type: "picker",
- label: proxy.t("salesContract.deliveryDeadline"),
- prop: "deliveryDate",
- itemType: "datePicker",
- showPicker: false,
- split: "-",
- columnsType: ["year", "month", "day"],
- },
- {
- type: "picker",
- label: proxy.t("salesContract.paymentMethod"),
- prop: "payMethod",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- },
- {
- type: "picker",
- label: proxy.t("salesContract.freightPayer"),
- prop: "freightPayer",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [
- {
- label: proxy.t("salesContract.partyA"),
- value: "0",
- },
- {
- label: proxy.t("salesContract.partyB"),
- value: "1",
- },
- ],
- },
- {
- type: "input",
- itemType: "textarea",
- label: "交货期限备注",
- prop: "deliveryDateRemark",
- },
- {
- type: "input",
- itemType: "textarea",
- label: "付款方式备注",
- prop: "payMethodRemark",
- },
- {
- type: "input",
- itemType: "textarea",
- label: proxy.t("salesContract.remarks"),
- prop: "remark",
- },
- {
- type: "input",
- itemType: "number",
- label: proxy.t("salesContract.contractTotalAmount"),
- prop: "contractAmount",
- readonly: true,
- },
- {
- type: "picker",
- label: "研发负责人",
- prop: "devUserId",
- itemType: "onePicker",
- showPicker: false,
- fieldNames: {
- text: "label",
- value: "value",
- },
- data: [],
- },
- ]);
- const onClickLeft = () => history.back();
- const fundsPaymentMethod = ref([]);
- const customerData = ref([]);
- const accountList = ref([]);
- const corporationList = ref([]);
- const productData = ref([]);
- const getDict = () => {
- proxy.getDictOne(["funds_payment_method"]).then((res) => {
- fundsPaymentMethod.value = res["funds_payment_method"].data.map((x) => ({
- label: x.dictValue,
- value: x.dictKey,
- }));
- formConfig[12].data = fundsPaymentMethod.value;
- });
- proxy.post("/customer/page", { pageNum: 1, pageSize: 9999 }).then((res) => {
- customerData.value = res.data.rows.map((x) => ({
- label: x.name,
- value: x.id,
- }));
- formConfig[10].data = customerData.value;
- });
- proxy
- .post("/productInfo/page", { pageNum: 1, pageSize: 9999, definition: "1" })
- .then((res) => {
- productData.value = res.data.rows.map((x) => ({
- label: x.name + ` (${x.spec})`,
- value: x.id,
- }));
- formOption.btnConfig.listConfig[0].data = productData.value;
- });
- proxy
- .post("/accountManagement/page", { pageNum: 1, pageSize: 999 })
- .then((res) => {
- accountList.value = res.data.rows.map((item) => {
- return {
- ...item,
- label: item.alias,
- value: item.id,
- };
- });
- formConfig[5].data = accountList.value;
- });
- proxy.post("/corporation/page", { pageNum: 1, pageSize: 999 }).then((res) => {
- corporationList.value = res.data.rows.map((item) => {
- return {
- ...item,
- label: item.name,
- value: item.id,
- };
- });
- formConfig[0].data = corporationList.value;
- });
- proxy
- .post("/system/user/getUserList", {
- pageNum: 1,
- pageSize: 9999,
- roleKey: "dev",
- })
- .then((res) => {
- formConfig[18].data = res.data.map((item) => {
- return {
- ...item,
- label: item.nickName,
- value: item.userId,
- };
- });
- });
- };
- const getProductData = (keyword) => {
- proxy
- .post("/productInfo/page", { keyword, definition: "1", pageSize: 9999 })
- .then((res) => {
- productData.value = res.data.rows.map((x) => ({
- label: x.name + ` (${x.spec})`,
- value: x.id,
- }));
- formOption.btnConfig.listConfig[0].data = productData.value;
- });
- };
- const getCustomerData = (keyword) => {
- proxy.post("/customer/page", { keyword, pageSize: 9999 }).then((res) => {
- customerData.value = res.data.rows.map((x) => ({
- label: x.name,
- value: x.id,
- }));
- formConfig[10].data = customerData.value;
- });
- };
- const getDetails = (id) => {
- proxy.post("/salesContract/detail", { id }).then((res) => {
- if (res.data && res.data.contractDetailsList.length > 0) {
- res.data.salesContractDetailsList = res.data.contractDetailsList;
- } else {
- res.data.salesContractDetailsList = [];
- }
- res.data.deliveryDate = res.data.deliveryDate.slice(0, 10);
- formData.data = res.data;
- changeAmount();
- setTimeout(() => {
- formDom.value.formDataListShowLabelOne();
- }, 1000);
- });
- };
- onMounted(() => {
- getDict();
- if (route.query.id) {
- getDetails(route.query.id);
- if (route.query.status != 0) {
- formOption.readonly = true; //全部只读
- formOption.hiddenSubmitBtn = true; //隐藏提交按钮
- formOption.otherBtn = false; //隐藏其他按钮操作
- formOption.btnConfig.isNeed = false;
- }
- }
- });
- const onSubmit = (type) => {
- if (formData.data.salesContractDetailsList.length > 0) {
- if (type == 10) {
- proxy.post("/salesContract/add", formData.data).then(
- () => {
- showSuccessToast("暂存成功");
- setTimeout(() => {
- onClickLeft();
- }, 500);
- },
- (err) => {
- return showFailToast(err.message);
- }
- );
- } else {
- proxy
- .post("/flowProcess/initiate", {
- flowKey: "jxst_sales_contract_flow",
- data: formData.data,
- })
- .then(
- () => {
- showSuccessToast(proxy.t("common.operationSuccessful"));
- setTimeout(() => {
- onClickLeft();
- }, 500);
- },
- (err) => {
- return showFailToast(err.message);
- }
- );
- }
- } else {
- return showFailToast(proxy.t("salesContract.pleaseAddContractDetails"));
- }
- };
- const changeSellId = (val) => {
- if (val) {
- proxy.post("/corporation/detail", { id: val }).then((res) => {
- let detailCorporation = res.data;
- if (detailCorporation.countryName) {
- formData.data.sellCountryName = detailCorporation.countryName;
- }
- if (detailCorporation.provinceName) {
- formData.data.sellProvinceName = detailCorporation.provinceName;
- }
- if (detailCorporation.cityName) {
- formData.data.sellCityName = detailCorporation.cityName;
- }
- if (detailCorporation.address) {
- formData.data.sellAddress = detailCorporation.address;
- }
- });
- }
- };
- const changeShroffAccount = (val) => {
- if (val) {
- let data = accountList.value.filter((item) => item.value === val);
- if (data && data.length > 0) {
- formData.data.sellAccountName = data[0].name;
- formData.data.sellOpeningBank = data[0].openingBank;
- formData.data.sellInterbankNumber = data[0].interbankNumber;
- formData.data.sellAccountOpening = data[0].accountOpening;
- }
- }
- };
- const changeAmount = (index) => {
- let total = 0;
- for (let i = 0; i < formData.data.salesContractDetailsList.length; i++) {
- const element = formData.data.salesContractDetailsList[i];
- if (element.unitPrice && element.quantity) {
- element.total = parseFloat(element.unitPrice * element.quantity).toFixed(
- 2
- );
- total += Number(element.total);
- }
- }
- if (total) {
- formData.data.contractAmount = total.toFixed(2);
- }
- };
- </script>
- <style lang="scss" scoped>
- .form {
- margin-bottom: 60px;
- }
- </style>
|