123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- <script>
- import Column from "./column";
- import useData from "../hooks/data";
- import useWatch from "../hooks/watch";
- import useMethods from "../hooks/function";
- import { initParams } from "@/utils/init.js";
- import { ITEM, SAVE } from "@/api/business/purchase/apply";
- const { watchPuOrgName } = useWatch();
- export default {
- name: "AddDrawer",
- components: {
- ElComputedInput: () => import("@/components/computed-input/index.vue"),
- ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
- },
- data() {
- return {
- title: "新 增",
- ...useData(Column),
- };
- },
- computed: {
- $dicts: {
- get: function () {
- return this.$parent.$parent.$dicts;
- },
- },
- },
- watch: {
- "params.puOrgName": watchPuOrgName(),
- },
- methods: {
- //
- async fetchRefer(prop, type, source) {
- const { fetchTax, fetchUnit, fetchExist } = useMethods();
- if (type === "MATERIAL_PARAM") {
- const { puOrg, customer, supplier } = this.params;
- const { rateCode, unitIdName, code: materialCode } = prop;
- // task 1
- fetchTax(rateCode).then(({ ntaxrate }) => {
- source.tax =
- ntaxrate === "0E-8" ? "0.000000" : (ntaxrate * 1).toFixed(6);
- });
- // task 2
- fetchUnit(unitIdName).then(({ id, code, name }) => {
- 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(
- ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
- source.recentlyPrice = recentlyPrice;
- source.isApprovalFirst = isApprovalFirst;
- source.isPriceAdjustment = isPriceAdjustment;
- }
- );
- }
- },
- //
- async fetchItem(prop) {
- try {
- // try
- this.loading = true;
- const { code, data } = await ITEM(prop);
- if (code === 200) {
- this.params = data;
- 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, createByName: null, updateByName: null })
- );
- this.params.priceApplyOrgs = this.params.priceApplyOrgs.map(
- (item) => ({ ...item, createByName: null, updateByName: null })
- );
- return true;
- } else {
- return false;
- }
- } catch (err) {
- // catch
- console.error(err);
- } finally {
- // finally
- this.loading = false;
- }
- },
- //
- async open(prop) {
- this.visible = prop ? await this.fetchItem(prop) : true;
- },
- //
- async hide() {
- this.visible = false;
- this.params = this.resetParams();
- this.tabName = this.tabColumns[0].key;
- },
- //
- async useRowAdd(prop) {
- const {
- $notify,
- tabColumns,
- params: { puOrgName, supplierName },
- } = this;
- if (!supplierName) {
- return $notify.info("请选择供应商");
- }
- if (!puOrgName) {
- return $notify.info("请选择采购组织");
- }
- const { tableColumns } = tabColumns.find(
- (element) => element.key === prop
- );
- this.params[prop].push(initParams(tableColumns));
- },
- //
- async useRowRemove(prop, scope) {
- const { $index } = scope;
- this.params[prop].splice($index, 1);
- },
- //
- async useSubmit(prop) {
- this.$refs[prop].validate(async (valid) => {
- if (valid) {
- try {
- // try
- const {
- priceApplyOrgs: _priceApplyOrgs,
- priceApplyItems: _priceApplyItems,
- } = this.params;
- const id = undefined;
- const priceApplyOrgs = _priceApplyOrgs.map((item) => ({
- ...item,
- id: undefined,
- applyId: undefined,
- }));
- const priceApplyItems = _priceApplyItems.map((item) => ({
- ...item,
- id: undefined,
- applyId: undefined,
- }));
- const params = {
- ...this.params,
- id,
- priceApplyOrgs,
- priceApplyItems,
- };
- const { msg, code } = await SAVE(params);
- if (code === 200) {
- this.hide();
- this.$emit("success");
- this.$notify.success(msg);
- }
- } catch (err) {
- // catch
- console.error(err);
- } finally {
- // finally
- this.loading = false;
- }
- } else {
- return false;
- }
- });
- },
- },
- created() {},
- mounted() {},
- destroyed() {},
- };
- </script>
- <template>
- <el-drawer
- :size="width"
- :title="title"
- :show-close="false"
- :visible.sync="visible"
- >
- <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"
- >
- <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
- <el-col
- v-for="column in tableColumns"
- :key="column.item.title"
- :span="column.item.span || 8"
- >
- <el-form-item
- :prop="column.item.key"
- :label="column.item.title"
- :require="column.item.require"
- >
- <component
- v-bind="column.attr"
- v-model="params[column.item.key]"
- :source.sync="params"
- :is="column.attr.component"
- style="width: 100%"
- >
- <template v-if="column.attr.dictName">
- <el-option
- v-for="item in $dicts[column.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="(column, index) in tabColumns"
- :key="index"
- :label="column.title"
- :name="column.key"
- lazy
- >
- <el-table :size="size" :data="params[column.key]">
- <el-table-column label="序号">
- <template slot-scope="scope">
- {{ scope.$index + 1 }}
- </template>
- </el-table-column>
- <el-table-column
- v-for="(cColumn, cIndex) in column.tableColumns"
- :key="cIndex"
- :prop="cColumn.item.key"
- :label="cColumn.item.title"
- :width="cColumn.item.width || 250"
- show-overflow-tooltip
- >
- <template slot-scope="scope">
- <component
- v-if="cColumn.attr.component"
- v-bind="cColumn.attr"
- v-model="scope.row[cColumn.item.key]"
- :source.sync="scope.row"
- :is="cColumn.attr.component"
- @change="fetchRefer"
- style="width: 100%"
- >
- <template v-if="cColumn.attr.dictName">
- <el-option
- v-for="item in $dicts[cColumn.attr.dictName]"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </template>
- </component>
- <span v-else> {{ scope.row[cColumn.item.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>
- </template>
|