|
@@ -1,34 +1,124 @@
|
|
|
<script>
|
|
|
import Column from "./column";
|
|
|
-import useData from "../hooks/data";
|
|
|
-import useWatch from "../hooks/watch";
|
|
|
import useMethods from "../hooks/function";
|
|
|
+import { initRules, initParams } from "@/utils/init.js";
|
|
|
import { ITEM, SAVE } from "@/api/business/purchase/apply";
|
|
|
|
|
|
-const { watchPuOrgName: w1 } = useWatch();
|
|
|
const { fetchTax, fetchUnit, fetchExist } = useMethods();
|
|
|
|
|
|
export default {
|
|
|
name: "AddDrawer",
|
|
|
+ props: {
|
|
|
+ selectData: {
|
|
|
+ type: [Array],
|
|
|
+ require: true,
|
|
|
+ },
|
|
|
+ addType: {
|
|
|
+ type: String,
|
|
|
+ default: "add",
|
|
|
+ },
|
|
|
+ },
|
|
|
components: {
|
|
|
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);
|
|
|
return {
|
|
|
- title: "新 增",
|
|
|
- ...useData(Column),
|
|
|
+ width: "100%",
|
|
|
+ visible: false,
|
|
|
+ loading: false,
|
|
|
+ rules: rules,
|
|
|
+ params: params,
|
|
|
+ tabName,
|
|
|
+ TabColumns,
|
|
|
+ FormColumns,
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
|
$dicts: {
|
|
|
get: function () {
|
|
|
- return this.$parent.$parent.$dicts;
|
|
|
+ return this.$parent.$parent.$parent.$dicts;
|
|
|
},
|
|
|
},
|
|
|
+ title: {
|
|
|
+ get() {
|
|
|
+ const { addType } = this;
|
|
|
+ if (addType === "add") {
|
|
|
+ return "新 增";
|
|
|
+ }
|
|
|
+ if (addType === "copy") {
|
|
|
+ return "复 制";
|
|
|
+ }
|
|
|
+ if (addType === "edit") {
|
|
|
+ return "编 辑";
|
|
|
+ }
|
|
|
+ },
|
|
|
+ set() {},
|
|
|
+ },
|
|
|
+ disabled: {
|
|
|
+ get() {
|
|
|
+ const {
|
|
|
+ addType,
|
|
|
+ selectData,
|
|
|
+ selectData: [{ status } = {}],
|
|
|
+ } = this.$props;
|
|
|
+ if (addType === "add") {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (addType === "copy") {
|
|
|
+ if (selectData.length !== 1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (addType === "edit") {
|
|
|
+ if (selectData.length !== 1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (selectData.length === 1 && status === "1") {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (selectData.length === 1 && status === "2") {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ set() {},
|
|
|
+ },
|
|
|
},
|
|
|
watch: {
|
|
|
- "params.puOrgName": w1(),
|
|
|
+ "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,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
},
|
|
|
methods: {
|
|
|
//
|
|
@@ -70,29 +160,6 @@ export default {
|
|
|
const { code, data } = await ITEM(prop);
|
|
|
if (code === 200) {
|
|
|
this.params = data;
|
|
|
- this.params.id = null;
|
|
|
- this.params.createBy = null;
|
|
|
- this.params.priceCode = null;
|
|
|
- this.params.createByName = null;
|
|
|
- this.params.effectiveDate = null;
|
|
|
- this.params.priceApplyItems = this.params.priceApplyItems.map(
|
|
|
- (item) => ({
|
|
|
- ...item,
|
|
|
- id: null,
|
|
|
- applyId: null,
|
|
|
- createByName: null,
|
|
|
- updateByName: null,
|
|
|
- })
|
|
|
- );
|
|
|
- this.params.priceApplyOrgs = this.params.priceApplyOrgs.map(
|
|
|
- (item) => ({
|
|
|
- ...item,
|
|
|
- id: null,
|
|
|
- applyId: null,
|
|
|
- createByName: null,
|
|
|
- updateByName: null,
|
|
|
- })
|
|
|
- );
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
@@ -106,23 +173,52 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
//
|
|
|
- async open(prop) {
|
|
|
- this.visible = prop ? await this.fetchItem(prop) : true;
|
|
|
+ async open() {
|
|
|
+ const { addType, selectData } = this.$props;
|
|
|
+ if (addType === "add") {
|
|
|
+ this.visible = true;
|
|
|
+ }
|
|
|
+ if (addType === "copy") {
|
|
|
+ const [{ id }] = selectData;
|
|
|
+ this.visible = await this.fetchItem(id);
|
|
|
+ this.params.id = null;
|
|
|
+ this.params.createBy = null;
|
|
|
+ this.params.priceCode = null;
|
|
|
+ this.params.createByName = null;
|
|
|
+ this.params.effectiveDate = null;
|
|
|
+ this.params.priceApplyItems = this.params.priceApplyItems.map(
|
|
|
+ (item) => ({
|
|
|
+ ...item,
|
|
|
+ id: null,
|
|
|
+ applyId: null,
|
|
|
+ createByName: null,
|
|
|
+ updateByName: null,
|
|
|
+ })
|
|
|
+ );
|
|
|
+ this.params.priceApplyOrgs = this.params.priceApplyOrgs.map((item) => ({
|
|
|
+ ...item,
|
|
|
+ id: null,
|
|
|
+ applyId: null,
|
|
|
+ createByName: null,
|
|
|
+ updateByName: null,
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ if (addType === "edit") {
|
|
|
+ const [{ id }] = selectData;
|
|
|
+ this.visible = await this.fetchItem(id);
|
|
|
+ }
|
|
|
},
|
|
|
//
|
|
|
async hide() {
|
|
|
- const { TabColumns, FormColumns, initParams } = this;
|
|
|
+ const { TabColumns, FormColumns } = this;
|
|
|
this.visible = false;
|
|
|
this.tabName = TabColumns[0].item.key;
|
|
|
this.params = initParams([...TabColumns, ...FormColumns]);
|
|
|
- this.params.priceApplyOrgs = [];
|
|
|
- this.params.priceApplyItems = [];
|
|
|
},
|
|
|
//
|
|
|
async useRowAdd(prop) {
|
|
|
const {
|
|
|
$notify,
|
|
|
- initParams,
|
|
|
TabColumns,
|
|
|
params: { puOrgName, supplierName },
|
|
|
} = this;
|
|
@@ -132,13 +228,29 @@ export default {
|
|
|
if (!puOrgName) {
|
|
|
return $notify.info("请选择采购组织");
|
|
|
}
|
|
|
- const { TableColumns } = TabColumns.find(({ item }) => item.key === prop);
|
|
|
- this.params[prop].push(initParams(TableColumns));
|
|
|
+ const { TableColumns } = TabColumns.find(
|
|
|
+ ({ item: { key } }) => key === prop
|
|
|
+ );
|
|
|
+ this.params[prop].push({ ...initParams(TableColumns), delFlag: "0" });
|
|
|
},
|
|
|
//
|
|
|
async useRowRemove(prop, scope) {
|
|
|
- const { $index } = scope;
|
|
|
- this.params[prop].splice($index, 1);
|
|
|
+ const { addType } = this.$props;
|
|
|
+ const {
|
|
|
+ row: { $index },
|
|
|
+ } = scope;
|
|
|
+ if (addType === "add") {
|
|
|
+ this.params[prop].splice($index, 1);
|
|
|
+ }
|
|
|
+ if (addType === "copy") {
|
|
|
+ this.params[prop].splice($index, 1);
|
|
|
+ }
|
|
|
+ if (addType === "edit") {
|
|
|
+ this.params[prop] = this.params[prop].map((item, index) => ({
|
|
|
+ ...item,
|
|
|
+ delFlag: index === $index ? "2" : item.delFlag,
|
|
|
+ }));
|
|
|
+ }
|
|
|
},
|
|
|
//
|
|
|
async useSubmit(prop) {
|
|
@@ -146,7 +258,22 @@ export default {
|
|
|
if (valid) {
|
|
|
try {
|
|
|
// try
|
|
|
- const { msg, code } = await SAVE({ ...this.params });
|
|
|
+ this.loading = true;
|
|
|
+ const {
|
|
|
+ params,
|
|
|
+ params: { priceApplyOrgs, priceApplyItems },
|
|
|
+ } = this;
|
|
|
+ if (this.addType === "edit") {
|
|
|
+ params.priceApplyOrgs = priceApplyOrgs.filter(
|
|
|
+ (item) => item.orgName
|
|
|
+ );
|
|
|
+ params.priceApplyItems = priceApplyItems.filter(
|
|
|
+ (item) => item.materialName
|
|
|
+ );
|
|
|
+ }
|
|
|
+ console.log(this.params.priceApplyItems);
|
|
|
+ return;
|
|
|
+ const { msg, code } = await SAVE(params);
|
|
|
if (code === 200) {
|
|
|
this.hide();
|
|
|
this.$emit("success");
|
|
@@ -171,144 +298,153 @@ export default {
|
|
|
};
|
|
|
</script>
|
|
|
<template>
|
|
|
- <el-drawer
|
|
|
- :size="width"
|
|
|
- :title="title"
|
|
|
- :show-close="false"
|
|
|
- :visible.sync="visible"
|
|
|
+ <el-button
|
|
|
+ v-bind="$attrs"
|
|
|
+ v-on="$listeners"
|
|
|
+ :disabled="disabled"
|
|
|
+ @click="open"
|
|
|
>
|
|
|
- <template slot="title">
|
|
|
- <span>{{ title }}</span>
|
|
|
- <span>
|
|
|
- <el-button
|
|
|
- :size="size"
|
|
|
- circle
|
|
|
- icon="el-icon-check"
|
|
|
- @click="useSubmit('ruleForm')"
|
|
|
- >
|
|
|
- </el-button>
|
|
|
- <el-button
|
|
|
- :size="size"
|
|
|
- circle
|
|
|
- type="danger"
|
|
|
- icon="el-icon-close"
|
|
|
- @click="hide"
|
|
|
- ></el-button>
|
|
|
- </span>
|
|
|
- </template>
|
|
|
- <el-form
|
|
|
- ref="ruleForm"
|
|
|
- v-loading="loading"
|
|
|
- :size="size"
|
|
|
- :rules="rules"
|
|
|
- :model="params"
|
|
|
- label-width="auto"
|
|
|
- label-position="right"
|
|
|
- style="padding: 10px"
|
|
|
+ {{ title }}
|
|
|
+ <el-drawer
|
|
|
+ :size="width"
|
|
|
+ :title="title"
|
|
|
+ :visible.sync="visible"
|
|
|
+ append-to-body
|
|
|
+ destroy-on-close
|
|
|
>
|
|
|
- <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"
|
|
|
- >
|
|
|
- <el-form-item
|
|
|
- :prop="item.key"
|
|
|
- :label="item.title"
|
|
|
- :require="item.require"
|
|
|
+ <el-form
|
|
|
+ ref="ruleForm"
|
|
|
+ v-loading="loading"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :rules="rules"
|
|
|
+ :model="params"
|
|
|
+ label-width="auto"
|
|
|
+ label-position="right"
|
|
|
+ style="padding: 10px"
|
|
|
+ >
|
|
|
+ <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"
|
|
|
>
|
|
|
- <component
|
|
|
- v-bind="attr"
|
|
|
- v-model="params[item.key]"
|
|
|
- :source.sync="params"
|
|
|
- style="width: 100%"
|
|
|
+ <el-form-item
|
|
|
+ :prop="item.key"
|
|
|
+ :label="item.title"
|
|
|
+ :require="item.require"
|
|
|
>
|
|
|
- <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, attr, TableColumns }, index) in TabColumns"
|
|
|
- :key="index"
|
|
|
- :label="item.title"
|
|
|
- :name="item.key"
|
|
|
- lazy
|
|
|
+ <component
|
|
|
+ v-bind="attr"
|
|
|
+ v-model="params[item.key]"
|
|
|
+ :source.sync="params"
|
|
|
+ style="width: 100%"
|
|
|
>
|
|
|
- <el-table :size="size" :data="params[item.key]">
|
|
|
- <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 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
|
|
|
+ >
|
|
|
+ <el-table
|
|
|
+ :size="$attrs.size"
|
|
|
+ :data="
|
|
|
+ params[item.key]
|
|
|
+ .map((item, index) => ({ ...item, $index: index }))
|
|
|
+ .filter(({ delFlag }) => delFlag === '0')
|
|
|
+ "
|
|
|
>
|
|
|
- <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="size"
|
|
|
- @click="useRowAdd(tabName)"
|
|
|
- >
|
|
|
- </el-button>
|
|
|
- </template>
|
|
|
- <template slot-scope="scope">
|
|
|
- <el-button
|
|
|
- circle
|
|
|
- icon="el-icon-minus"
|
|
|
- :size="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-drawer>
|
|
|
+ <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>
|
|
|
+ <div style="padding: 20px; text-align: right">
|
|
|
+ <el-button :size="$attrs.size" :loading="loading" @click="hide"
|
|
|
+ >取 消</el-button
|
|
|
+ >
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ :size="$attrs.size"
|
|
|
+ :loading="loading"
|
|
|
+ @click="useSubmit('ruleForm')"
|
|
|
+ >确 认</el-button
|
|
|
+ >
|
|
|
+ </div>
|
|
|
+ </el-drawer>
|
|
|
+ </el-button>
|
|
|
</template>
|