|
@@ -1,14 +1,64 @@
|
|
|
<script>
|
|
|
-import Column from "./column";
|
|
|
-import useMethods from "../hooks/function";
|
|
|
-import { initRules, initParams } from "@/utils/init.js";
|
|
|
+import { TabColumns, TableColumns } from "./columns";
|
|
|
+import { REFER } from "@/components/popover-select/api";
|
|
|
+import { EXIST } from "@/api/business/purchase/catalogue";
|
|
|
import { ITEM, SAVE } from "@/api/business/purchase/apply";
|
|
|
|
|
|
-const { fetchTax, fetchUnit, fetchExist } = useMethods();
|
|
|
+const fetchTax = async (prop) => {
|
|
|
+ try {
|
|
|
+ // try
|
|
|
+ const { code, rows } = await REFER({
|
|
|
+ search: prop,
|
|
|
+ type: "TAX_RATE_PARAM",
|
|
|
+ });
|
|
|
+ if (code === 200) {
|
|
|
+ return rows[0] || {};
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ // catch
|
|
|
+ console.error(err);
|
|
|
+ } finally {
|
|
|
+ // finally
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const fetchUnit = async (prop) => {
|
|
|
+ try {
|
|
|
+ // try
|
|
|
+ const { code, rows } = await REFER({
|
|
|
+ search: prop,
|
|
|
+ type: "UNIT_PARAM",
|
|
|
+ });
|
|
|
+ if (code === 200) {
|
|
|
+ return rows[0] || {};
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ // catch
|
|
|
+ console.error(err);
|
|
|
+ } finally {
|
|
|
+ // finally
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const fetchExist = async (prop) => {
|
|
|
+ try {
|
|
|
+ // try
|
|
|
+ const { code, data } = await EXIST(prop);
|
|
|
+ if (code === 200) return data;
|
|
|
+ } catch (err) {
|
|
|
+ // catch
|
|
|
+ console.error(err);
|
|
|
+ } finally {
|
|
|
+ // finally
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
export default {
|
|
|
name: "AddDrawer",
|
|
|
props: {
|
|
|
+ dict: {
|
|
|
+ type: Object,
|
|
|
+ },
|
|
|
selectData: {
|
|
|
type: [Array],
|
|
|
require: true,
|
|
@@ -19,38 +69,31 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
components: {
|
|
|
+ ElSuperForm: () => import("@/components/super-form/index.vue"),
|
|
|
+ ElSuperTable: () => import("@/components/super-table/index.vue"),
|
|
|
ElComputedInput: () => import("@/components/computed-input/index.vue"),
|
|
|
ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
|
|
|
},
|
|
|
data() {
|
|
|
- const {
|
|
|
- TabColumns,
|
|
|
- FormColumns,
|
|
|
- TabColumns: [
|
|
|
- {
|
|
|
- item: { key: tabName },
|
|
|
- },
|
|
|
- ],
|
|
|
- } = Column;
|
|
|
- const params = initParams([...TabColumns, ...FormColumns]);
|
|
|
- const rules = initRules(FormColumns);
|
|
|
+ const [
|
|
|
+ {
|
|
|
+ item: { key: tabName },
|
|
|
+ },
|
|
|
+ ] = TabColumns;
|
|
|
+ const rules = this.$init.rules([...TabColumns, ...TableColumns]);
|
|
|
+ const params = this.$init.params([...TabColumns, ...TableColumns]);
|
|
|
return {
|
|
|
width: "100%",
|
|
|
visible: false,
|
|
|
loading: false,
|
|
|
rules: rules,
|
|
|
params: params,
|
|
|
- tabName,
|
|
|
- TabColumns,
|
|
|
- FormColumns,
|
|
|
+ tabName: tabName,
|
|
|
+ TabColumns: TabColumns,
|
|
|
+ TableColumns: TableColumns,
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
- $dicts: {
|
|
|
- get: function () {
|
|
|
- return this.$parent.$parent.$parent.$dicts;
|
|
|
- },
|
|
|
- },
|
|
|
title: {
|
|
|
get() {
|
|
|
const { addType } = this;
|
|
@@ -95,64 +138,84 @@ export default {
|
|
|
},
|
|
|
set() {},
|
|
|
},
|
|
|
- },
|
|
|
- watch: {
|
|
|
- "params.puOrgName": {
|
|
|
- handler: async function (newProp) {
|
|
|
- const index = this.params.priceApplyOrgs.findIndex(
|
|
|
- (item) => item.orgName === newProp
|
|
|
- );
|
|
|
- if (index === -1 && newProp) {
|
|
|
- const {
|
|
|
- id: org,
|
|
|
- code: orgCode,
|
|
|
- name: orgName,
|
|
|
- } = await fetchOrg(this.params.puOrgName);
|
|
|
- await this.params.priceApplyOrgs.push({
|
|
|
- org,
|
|
|
- orgCode,
|
|
|
- orgName,
|
|
|
- createByName: undefined,
|
|
|
- updateByName: undefined,
|
|
|
- });
|
|
|
- }
|
|
|
+ priceApply: {
|
|
|
+ get() {
|
|
|
+ const {
|
|
|
+ params: { priceApplyOrgs, priceApplyItems },
|
|
|
+ } = this;
|
|
|
+ return {
|
|
|
+ priceApplyOrgs: priceApplyOrgs.filter(
|
|
|
+ ({ delFlag }) => delFlag !== "2"
|
|
|
+ ),
|
|
|
+ priceApplyItems: priceApplyItems.filter(
|
|
|
+ ({ delFlag }) => delFlag !== "2"
|
|
|
+ ),
|
|
|
+ };
|
|
|
},
|
|
|
- deep: true,
|
|
|
+ set() {},
|
|
|
},
|
|
|
},
|
|
|
+ watch: {},
|
|
|
methods: {
|
|
|
//
|
|
|
- async fetchRefer(row, prop = {}) {
|
|
|
- const { source, referName } = prop;
|
|
|
- if (referName === "MATERIAL_PARAM") {
|
|
|
- const { puOrg, customer, supplier } = this.params;
|
|
|
- const { rateCode, unitIdName, code: materialCode } = row;
|
|
|
- // task 1
|
|
|
- fetchTax(rateCode).then((res) => {
|
|
|
- const { ntaxrate } = res;
|
|
|
- source.tax =
|
|
|
- ntaxrate === "0E-8" ? "0.000000" : (ntaxrate * 1).toFixed(6);
|
|
|
- });
|
|
|
- // task 2
|
|
|
- fetchUnit(unitIdName).then((res) => {
|
|
|
- const { id, code, name } = res;
|
|
|
- source.unit = id;
|
|
|
- source.unitCode = code;
|
|
|
- source.unitName = name;
|
|
|
- source.puUnit = id;
|
|
|
- source.puUnitCode = code;
|
|
|
- source.puUnitName = name;
|
|
|
- });
|
|
|
- // task 3
|
|
|
- fetchExist({ puOrg, customer, supplier, materialCode }).then((res) => {
|
|
|
- const { recentlyPrice, isApprovalFirst, isPriceAdjustment } = res;
|
|
|
- source.recentlyPrice = recentlyPrice;
|
|
|
- source.isApprovalFirst = isApprovalFirst;
|
|
|
- source.isPriceAdjustment = isPriceAdjustment;
|
|
|
+ rowClassName(prop) {
|
|
|
+ const {
|
|
|
+ row: { delFlag },
|
|
|
+ } = prop;
|
|
|
+ if (delFlag === "2") {
|
|
|
+ return "is-hidden";
|
|
|
+ } else {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //
|
|
|
+ changePuOrgName(prop) {
|
|
|
+ const {
|
|
|
+ select: { id: org, code: orgCode, name: orgName },
|
|
|
+ } = prop;
|
|
|
+ const index = this.params.priceApplyOrgs.findIndex(
|
|
|
+ (item) => item.org === org
|
|
|
+ );
|
|
|
+ if (index === -1) {
|
|
|
+ this.params.priceApplyOrgs.push({
|
|
|
+ org,
|
|
|
+ orgCode,
|
|
|
+ orgName,
|
|
|
+ createByName: undefined,
|
|
|
+ updateByName: undefined,
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
//
|
|
|
+ changeMaterialName(prop) {
|
|
|
+ const { row } = prop;
|
|
|
+ const { puOrg, customer, supplier } = this.params;
|
|
|
+ const { rateCode, unitIdName, code: materialCode } = row;
|
|
|
+ // task 1
|
|
|
+ fetchTax(rateCode).then((res) => {
|
|
|
+ const { ntaxrate } = res;
|
|
|
+ row.tax = ntaxrate === "0E-8" ? "0.000000" : (ntaxrate * 1).toFixed(6);
|
|
|
+ });
|
|
|
+ // task 2
|
|
|
+ fetchUnit(unitIdName).then((res) => {
|
|
|
+ const { id, code, name } = res;
|
|
|
+ row.unit = id;
|
|
|
+ row.unitCode = code;
|
|
|
+ row.unitName = name;
|
|
|
+ row.puUnit = id;
|
|
|
+ row.puUnitCode = code;
|
|
|
+ row.puUnitName = name;
|
|
|
+ });
|
|
|
+ // task 3
|
|
|
+ fetchExist({ puOrg, customer, supplier, materialCode }).then((res) => {
|
|
|
+ const { recentlyPrice, isApprovalFirst, isPriceAdjustment } = res;
|
|
|
+ row.recentlyPrice = recentlyPrice;
|
|
|
+ row.isApprovalFirst = isApprovalFirst;
|
|
|
+ row.isPriceAdjustment = isPriceAdjustment;
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+ //
|
|
|
async fetchItem(prop) {
|
|
|
try {
|
|
|
// try
|
|
@@ -206,14 +269,28 @@ export default {
|
|
|
if (addType === "edit") {
|
|
|
const [{ id }] = selectData;
|
|
|
this.visible = await this.fetchItem(id);
|
|
|
+ this.params.priceApplyItems = this.params.priceApplyItems.map(
|
|
|
+ (item, index) => ({
|
|
|
+ ...item,
|
|
|
+ $index: index,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ this.params.priceApplyOrgs = this.params.priceApplyOrgs.map(
|
|
|
+ (item, index) => ({
|
|
|
+ ...item,
|
|
|
+ $index: index,
|
|
|
+ })
|
|
|
+ );
|
|
|
}
|
|
|
},
|
|
|
//
|
|
|
async hide() {
|
|
|
- const { TabColumns, FormColumns } = this;
|
|
|
+ const { TabColumns, TableColumns } = this;
|
|
|
this.visible = false;
|
|
|
this.tabName = TabColumns[0].item.key;
|
|
|
- this.params = initParams([...TabColumns, ...FormColumns]);
|
|
|
+ this.params = this.$init.params([...TabColumns, ...TableColumns]);
|
|
|
+ this.params.priceApplyOrgs = [];
|
|
|
+ this.params.priceApplyItems = [];
|
|
|
},
|
|
|
//
|
|
|
async useRowAdd(prop) {
|
|
@@ -231,7 +308,11 @@ export default {
|
|
|
const { TableColumns } = TabColumns.find(
|
|
|
({ item: { key } }) => key === prop
|
|
|
);
|
|
|
- this.params[prop].push({ ...initParams(TableColumns), delFlag: "0" });
|
|
|
+ this.params[prop].push({
|
|
|
+ delFlag: "0",
|
|
|
+ $index: this.params[prop].length,
|
|
|
+ ...this.$init.params(TableColumns),
|
|
|
+ });
|
|
|
},
|
|
|
//
|
|
|
async useRowRemove(prop, scope) {
|
|
@@ -254,10 +335,9 @@ export default {
|
|
|
},
|
|
|
//
|
|
|
async useSubmit(prop) {
|
|
|
- this.$refs[prop].validate(async (valid) => {
|
|
|
+ this.$refs[prop].$refs[prop].validate(async (valid) => {
|
|
|
if (valid) {
|
|
|
try {
|
|
|
- // try
|
|
|
this.loading = true;
|
|
|
const {
|
|
|
params,
|
|
@@ -271,8 +351,6 @@ export default {
|
|
|
(item) => item.materialName
|
|
|
);
|
|
|
}
|
|
|
- console.log(this.params.priceApplyItems);
|
|
|
- return;
|
|
|
const { msg, code } = await SAVE(params);
|
|
|
if (code === 200) {
|
|
|
this.hide();
|
|
@@ -311,128 +389,84 @@ export default {
|
|
|
:visible.sync="visible"
|
|
|
append-to-body
|
|
|
destroy-on-close
|
|
|
+ @close="hide"
|
|
|
>
|
|
|
- <el-form
|
|
|
- ref="ruleForm"
|
|
|
- v-loading="loading"
|
|
|
- :size="$attrs.size"
|
|
|
+ <el-super-form
|
|
|
+ v-model="params"
|
|
|
+ :dict="dict"
|
|
|
:rules="rules"
|
|
|
- :model="params"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :columns="TableColumns"
|
|
|
+ ref="superForm"
|
|
|
label-width="auto"
|
|
|
label-position="right"
|
|
|
- style="padding: 10px"
|
|
|
+ style="padding: 20px"
|
|
|
>
|
|
|
- <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
|
|
|
- <el-col
|
|
|
- v-for="({ item, attr }, index) in FormColumns"
|
|
|
- :key="index"
|
|
|
- :span="item.span || 8"
|
|
|
+ <template slot="puOrgName" slot-scope="scope">
|
|
|
+ <component
|
|
|
+ v-bind="scope.attr"
|
|
|
+ v-model="scope.row[scope.item.key]"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :source.sync="scope.row"
|
|
|
+ @change="changePuOrgName({ ...scope, select: $event })"
|
|
|
>
|
|
|
- <el-form-item
|
|
|
- :prop="item.key"
|
|
|
- :label="item.title"
|
|
|
- :require="item.require"
|
|
|
- >
|
|
|
+ </component
|
|
|
+ ></template>
|
|
|
+ </el-super-form>
|
|
|
+ <el-tabs v-model="tabName" style="padding: 0 20px 20px">
|
|
|
+ <el-tab-pane
|
|
|
+ v-for="({ item, TableColumns: columns }, index) in TabColumns"
|
|
|
+ :key="index"
|
|
|
+ :label="item.title"
|
|
|
+ :name="item.key"
|
|
|
+ lazy
|
|
|
+ >
|
|
|
+ <el-super-table
|
|
|
+ v-model="priceApply[item.key]"
|
|
|
+ :dict="dict"
|
|
|
+ :ref="tabName"
|
|
|
+ :columns="columns"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :row-class-name="rowClassName"
|
|
|
+ >
|
|
|
+ <template slot="materialName" slot-scope="scope">
|
|
|
<component
|
|
|
- v-bind="attr"
|
|
|
- v-model="params[item.key]"
|
|
|
- :source.sync="params"
|
|
|
- style="width: 100%"
|
|
|
+ v-bind="scope.attr"
|
|
|
+ v-model="scope.row[scope.item.key]"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :source.sync="scope.row"
|
|
|
+ @change="changeMaterialName(scope)"
|
|
|
>
|
|
|
- <template v-if="attr.dictName">
|
|
|
- <el-option
|
|
|
- v-for="item in $dicts[attr.dictName]"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
- >
|
|
|
- </el-option>
|
|
|
- </template>
|
|
|
</component>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
- <el-col :span="24">
|
|
|
- <el-form-item label-width="0">
|
|
|
- <el-tabs v-model="tabName">
|
|
|
- <el-tab-pane
|
|
|
- v-for="({ item, TableColumns }, index) in TabColumns"
|
|
|
- :key="index"
|
|
|
- :label="item.title"
|
|
|
- :name="item.key"
|
|
|
- lazy
|
|
|
+ </template>
|
|
|
+ <el-table-column
|
|
|
+ slot="operation"
|
|
|
+ fixed="right"
|
|
|
+ label="操作"
|
|
|
+ width="100"
|
|
|
+ >
|
|
|
+ <template slot="header" slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ circle
|
|
|
+ icon="el-icon-plus"
|
|
|
+ :size="$attrs.size"
|
|
|
+ @click="useRowAdd(tabName)"
|
|
|
>
|
|
|
- <el-table
|
|
|
- :size="$attrs.size"
|
|
|
- :data="
|
|
|
- params[item.key]
|
|
|
- .map((item, index) => ({ ...item, $index: index }))
|
|
|
- .filter(({ delFlag }) => delFlag === '0')
|
|
|
- "
|
|
|
- >
|
|
|
- <el-table-column label="序号">
|
|
|
- <template slot-scope="scope">
|
|
|
- {{ scope.$index + 1 }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column
|
|
|
- v-for="(
|
|
|
- { item: cItem, attr: cAttr }, cIndex
|
|
|
- ) in TableColumns"
|
|
|
- :key="cIndex"
|
|
|
- :prop="cItem.key"
|
|
|
- :label="cItem.title"
|
|
|
- :width="cItem.width || 250"
|
|
|
- show-overflow-tooltip
|
|
|
- >
|
|
|
- <template slot-scope="scope">
|
|
|
- <component
|
|
|
- v-if="cAttr.is"
|
|
|
- v-bind="cAttr"
|
|
|
- v-model="scope.row[cItem.key]"
|
|
|
- :source.sync="scope.row"
|
|
|
- @change="fetchRefer"
|
|
|
- style="width: 100%"
|
|
|
- >
|
|
|
- <template v-if="cAttr.dictName">
|
|
|
- <el-option
|
|
|
- v-for="item in $dicts[cAttr.dictName]"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
- >
|
|
|
- </el-option>
|
|
|
- </template>
|
|
|
- </component>
|
|
|
- <span v-else> {{ scope.row[cItem.key] }}</span>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column fixed="right" label="操作" width="100">
|
|
|
- <template slot="header" slot-scope="scope">
|
|
|
- <el-button
|
|
|
- circle
|
|
|
- icon="el-icon-plus"
|
|
|
- :size="$attrs.size"
|
|
|
- @click="useRowAdd(tabName)"
|
|
|
- >
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- <template slot-scope="scope">
|
|
|
- <el-button
|
|
|
- circle
|
|
|
- icon="el-icon-minus"
|
|
|
- :size="$attrs.size"
|
|
|
- @click.native.prevent="useRowRemove(tabName, scope)"
|
|
|
- >
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </el-tab-pane>
|
|
|
- </el-tabs>
|
|
|
- </el-form-item>
|
|
|
- </el-col>
|
|
|
- </el-row>
|
|
|
- </el-form>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button
|
|
|
+ circle
|
|
|
+ icon="el-icon-minus"
|
|
|
+ :size="$attrs.size"
|
|
|
+ @click.native.prevent="useRowRemove(tabName, scope)"
|
|
|
+ >
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-super-table>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
<div style="padding: 20px; text-align: right">
|
|
|
<el-button :size="$attrs.size" :loading="loading" @click="hide"
|
|
|
>取 消</el-button
|
|
@@ -441,10 +475,16 @@ export default {
|
|
|
type="primary"
|
|
|
:size="$attrs.size"
|
|
|
:loading="loading"
|
|
|
- @click="useSubmit('ruleForm')"
|
|
|
+ @click="useSubmit('superForm')"
|
|
|
>确 认</el-button
|
|
|
>
|
|
|
</div>
|
|
|
</el-drawer>
|
|
|
</el-button>
|
|
|
</template>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+::v-deep .el-table__row.is-hidden {
|
|
|
+ display: none;
|
|
|
+}
|
|
|
+</style>
|