123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <script>
- import useColumns from "./columns";
- import { initParams } from "@/utils/init.js";
- import { ITEM } from "@/api/business/purchase/contract";
- export default {
- name: "SeeDrawer",
- props: {
- selectData: {
- type: [Array],
- require: true,
- },
- },
- components: {
- ElDictTag: () => import("@/components/DictTag/index.vue"),
- ElFilePreview: () => import("@/components/file-preview/index.vue"),
- ElComputedInputV2: () => import("@/components/computed-input-v2/index.vue"),
- },
- data() {
- const {
- TabColumns,
- FormColumns,
- TabColumns: [
- {
- item: { key: tabName },
- },
- ],
- } = useColumns();
- const params = initParams([...TabColumns, ...FormColumns]);
- return {
- column: 2,
- width: "50%",
- title: "明 细",
- visible: false,
- loading: false,
- params: params,
- tabName: tabName,
- TabColumns,
- FormColumns,
- };
- },
- computed: {
- $dicts: {
- get() {
- return this.$parent.$parent.$parent.dict.type;
- },
- },
- disabled: {
- get() {
- const { selectData } = this;
- if (selectData.length !== 1) {
- return true;
- }
- },
- set() {},
- },
- },
- watch: {},
- methods: {
- async fetchItem(prop) {
- try {
- // try
- this.loading = true;
- const { code, data } = await ITEM(prop);
- if (code === 200) {
- this.params = data;
- return true;
- } else {
- return false;
- }
- } catch (err) {
- // catch
- console.error(err);
- } finally {
- // finally
- this.loading = false;
- }
- },
- //
- async open(prop) {
- this.visible = await this.fetchItem(prop);
- },
- //
- async hide() {
- const {
- TabColumns,
- FormColumns,
- TabColumns: [
- {
- item: { key: tabName },
- },
- ],
- } = useColumns();
- this.visible = false;
- this.tabName = tabName;
- this.params = initParams([...TabColumns, ...FormColumns]);
- },
- },
- created() {},
- mounted() {},
- destroyed() {},
- };
- </script>
- <template>
- <el-button
- v-bind="$attrs"
- v-on="$listeners"
- :disabled="disabled"
- @click="open(selectData[0])"
- >
- {{ title }}
- <el-drawer
- :size="width"
- :title="title"
- :visible.sync="visible"
- append-to-body
- >
- <el-descriptions
- :size="$attrs.size"
- :column="column"
- border
- style="margin: 10px"
- >
- <el-descriptions-item
- v-if="params[item.key]"
- v-for="{ item, attr } in FormColumns"
- :key="item.key"
- :label="item.title"
- :labelStyle="{ width: '150px' }"
- :contentStyle="{ width: 'auto' }"
- >
- <component
- v-if="attr.is === 'el-dict-tag'"
- v-bind="attr"
- v-model="params[item.key]"
- :size="$attrs.size"
- :options="$dicts[attr.dictName]"
- ></component>
- <component
- v-else-if="attr.is === 'el-file-preview'"
- v-bind="attr"
- v-model="params[item.key]"
- ></component>
- <component
- v-else-if="attr.is === 'el-computed-input-v2'"
- v-bind="attr"
- v-model="params[item.key]"
- ></component>
- <component is="span" v-else>{{ params[item.key] }}</component>
- </el-descriptions-item>
- </el-descriptions>
- <el-tabs v-model="tabName" :size="$attrs.size" style="margin: 10px">
- <el-tab-pane
- v-for="{ item, TableColumns } in TabColumns"
- :key="item.key"
- :name="item.key"
- :label="item.title"
- lazy
- >
- <el-table :size="$attrs.size" :data="params[item.key]">
- <el-table-column
- v-for="{ item: cItem, attr: cAttr } in TableColumns"
- :key="cItem.key"
- :prop="cItem.key"
- :label="cItem.title"
- :width="cItem.width || 300"
- show-overflow-tooltip
- >
- <template slot-scope="scope">
- <component
- v-if="cAttr.is === 'el-dict-tag'"
- v-bind="cAttr"
- v-model="scope.row[cItem.key]"
- :size="$attrs.size"
- :options="$dicts[cAttr.dictName]"
- ></component>
- <component
- v-else-if="cAttr.is === 'el-file-preview'"
- v-bind="cAttr"
- v-model="scope.row[cItem.key]"
- ></component>
- <component
- v-else-if="cAttr.is === 'el-computed-input-v2'"
- v-bind="cAttr"
- v-model="scope.row[cItem.key]"
- ></component>
- <component is="span" v-else>{{
- scope.row[cItem.key] || "--"
- }}</component>
- </template>
- </el-table-column>
- </el-table>
- </el-tab-pane>
- </el-tabs>
- </el-drawer>
- </el-button>
- </template>
|