123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- <script>
- import { Columns, TabColumns } from "../column";
- import {
- EDIT,
- ITEM,
- TABLELIST,
- TABLEROMOVE,
- } from "@/api/business/purchase/contract";
- import { initDicts, initRules, initParams } from "@/utils/init";
- export default {
- name: "EditDialog",
- dicts: Array.from(
- new Set([
- ...initDicts(Columns),
- ...initDicts(TabColumns.map((item) => item.tableColumns))
- .flat()
- .filter((cItem) => cItem.inputType === "Select"),
- ])
- ),
- data() {
- return {
- size: "mini",
- visible: false,
- loading: false,
- columns: Columns,
- rules: initRules(Columns),
- params: {
- ...initParams(Columns),
- contractItemList: [],
- contractClauseList: [],
- contractExpenseList: [],
- contractApplyOrgList: [],
- contractAgreementList: [],
- },
- tabColumns: TabColumns,
- tabName: "contractItemList",
- };
- },
- computed: {},
- watch: {
- "params.contractType": function (newProp) {
- this.tabColumns = TabColumns.filter((element) =>
- newProp === "1" ? element.key !== "contractItemList" : element
- );
- this.tabName = this.tabColumns[0].key;
- },
- },
- methods: {
- //
- open(prop) {
- this.visible = true;
- this.fetchItem(prop);
- },
- //
- hide() {
- this.visible = false;
- this.params = initParams(Columns);
- this.tabName = this.tabColumns[0].key;
- },
- //
- async fetchItem(prop) {
- try {
- this.loading = true;
- const { code, msg, data } = await ITEM(prop);
- if (code === 200) {
- this.params = data;
- this.$notify.success({ title: msg });
- this.tabName = this.tabColumns[0].key;
- this.fetchTable(this.params.code, this.tabName);
- } else {
- this.$notify.warning({ title: msg });
- }
- } catch (err) {
- //
- } finally {
- this.loading = false;
- }
- },
- //
- async fetchTable(prop, name) {
- try {
- this.loading = true;
- const { code, msg, rows } = await TABLELIST({ contractId: prop }, name);
- if (code === 200) {
- this.params[name] = rows;
- this.$notify.success({ title: msg });
- } else {
- this.$notify.warning({ title: msg });
- }
- } catch (err) {
- //
- } finally {
- this.loading = false;
- }
- },
- //
- rowAdd(prop) {
- const tab = this.tabColumns.find((element) => element.key === prop);
- this.params[prop].push(initParams(tab.tableColumns));
- },
- //
- async rowDelete(prop, { row: { id }, $index }) {
- try {
- this.loading = true;
- const { code, msg } = await TABLEROMOVE(id, prop);
- if (code === 200) {
- this.params[prop].splice($index, 1);
- this.$notify.success({ title: msg });
- } else {
- this.$notify.warning({ title: msg });
- }
- } catch (err) {
- //
- } finally {
- this.loading = false;
- }
- },
- //
- submit(prop) {
- this.$refs[prop].validate(async (valid) => {
- if (valid) {
- try {
- const createById = this.params.buyer;
- const createByName = this.params.buyerName;
- const updateById = this.$store.state.user.id;
- const updateByName = this.$store.state.user.name;
- const { code, msg } = await EDIT({
- createById,
- createByName,
- updateById,
- updateByName,
- ...this.params,
- });
- if (code === 200) {
- this.hide();
- this.$emit("success");
- this.$notify.success({ title: msg });
- } else {
- this.$notify.warning({ title: msg });
- }
- } catch (err) {
- //
- } finally {
- //
- }
- } else {
- return false;
- }
- });
- },
- },
- created() {},
- mounted() {},
- destroyed() {},
- };
- </script>
- <template>
- <el-dialog :visible.sync="visible" title="编辑" fullscreen @close="hide">
- <el-form
- ref="ruleForm"
- v-loading="loading"
- :size="size"
- :rules="rules"
- :model="params"
- label-width="auto"
- label-position="right"
- >
- <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
- <el-col
- v-for="(column, index) in columns"
- :key="index"
- :span="column.span || 6"
- >
- <el-form-item :prop="column.key" :label="column.title">
- <el-input
- v-if="column.inputType === 'Input'"
- v-model="params[column.key]"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- style="width: 100%"
- ></el-input>
- <dr-popover-select
- v-if="column.inputType === 'PopoverSelect'"
- v-model="params[column.key]"
- :source.sync="params"
- :title="column.title"
- :type="column.referName"
- :disabled="column.disabled"
- :readonly="column.readonly"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- :data-mapping="column.dataMapping"
- >
- </dr-popover-select>
- <el-input
- v-if="column.inputType === 'Textarea'"
- v-model="params[column.key]"
- type="textarea"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- style="width: 100%"
- ></el-input>
- <el-input-number
- v-if="column.inputType === 'InputNumber'"
- v-model="params[column.key]"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- :controls-position="column.controlsPosition"
- style="width: 100%"
- ></el-input-number>
- <el-select
- v-if="column.inputType === 'Select'"
- v-model="params[column.key]"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- style="width: 100%"
- >
- <el-option
- v-for="item in dict.type[column.referName]"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- <el-date-picker
- v-if="column.inputType === 'DatePicker'"
- v-model="params[column.key]"
- :type="column.type"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- :picker-options="column.pickerOptions"
- style="width: 100%"
- >
- </el-date-picker>
- <file-upload
- v-if="column.inputType === 'Upload'"
- v-model="params[column.key]"
- :file-type="column.fileType"
- ></file-upload>
- </el-form-item>
- </el-col>
- </el-row>
- <el-form-item label-width="0">
- <el-tabs
- v-model="tabName"
- tab-position="left"
- style="width: 100%"
- @tab-click="fetchTable(params.code, tabName)"
- >
- <el-tab-pane
- v-for="(column, index) in tabColumns"
- :key="index"
- :label="column.title"
- :name="column.key"
- >
- <el-table :data="params[column.key]" style="width: 100%">
- <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.key"
- :label="cColumn.title"
- :width="cColumn.width"
- >
- <template slot-scope="scope">
- <el-input
- v-if="cColumn.inputType === 'Input'"
- v-model="scope.row[cColumn.key]"
- :size="size"
- :disabled="cColumn.disabled"
- :clearable="cColumn.clearable"
- :placeholder="cColumn.placeholder"
- style="width: 100%"
- ></el-input>
- <dr-computed-input
- v-if="cColumn.inputType === 'ComputedInput'"
- v-model="scope.row[cColumn.key]"
- :source="scope.row"
- :computed="cColumn.computed"
- :placeholder="cColumn.placeholder"
- style="width: 100%"
- ></dr-computed-input>
- <dr-popover-select
- v-else-if="cColumn.inputType === 'PopoverSelect'"
- v-model="scope.row[cColumn.key]"
- :size="size"
- :title="cColumn.title"
- :source.sync="scope.row"
- :type="cColumn.referName"
- :disabled="cColumn.disabled"
- :readonly="cColumn.readonly"
- :clearable="cColumn.clearable"
- :placeholder="cColumn.placeholder"
- :data-mapping="cColumn.dataMapping"
- >
- </dr-popover-select>
- <el-input-number
- v-else-if="cColumn.inputType === 'InputNumber'"
- v-model="scope.row[cColumn.key]"
- :size="size"
- :disabled="cColumn.disabled"
- :clearable="cColumn.clearable"
- :placeholder="cColumn.placeholder"
- :controls-position="cColumn.controlsPosition"
- style="width: 100%"
- ></el-input-number>
- <el-select
- v-else-if="cColumn.inputType === 'Select'"
- v-model="scope.row[cColumn.key]"
- :disabled="cColumn.disabled"
- :clearable="cColumn.clearable"
- :placeholder="cColumn.placeholder"
- style="width: 100%"
- >
- <el-option
- v-for="item in dict.type[cColumn.referName]"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- <span v-else> {{ scope.row[cColumn.key] }}</span>
- </template>
- </el-table-column>
- <el-table-column fixed="right" label="操作" width="75">
- <template slot="header" slot-scope="scope">
- <el-button
- circle
- icon="el-icon-plus"
- :size="size"
- @click="rowAdd(tabName)"
- >
- </el-button>
- </template>
- <template slot-scope="scope">
- <el-button
- circle
- icon="el-icon-minus"
- :size="size"
- @click.native.prevent="
- rowDelete(params[tabName], scope.$index)
- "
- >
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-tab-pane>
- </el-tabs>
- </el-form-item>
- <el-form-item label-width="0" style="text-align: right">
- <el-button :size="size" @click="hide">取 消</el-button>
- <el-button :size="size" @click="submit('ruleForm')"> 更 新 </el-button>
- </el-form-item>
- </el-form>
- </el-dialog>
- </template>
|