123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <script>
- import Column from "../add/column";
- import { initRules, initParams } from "@/utils/init.js";
- import { ITEM, LIST } from "@/api/business/purchase/apply";
- export default {
- name: "SeeDrawer",
- data() {
- const {
- TabColumns,
- FormColumns,
- TabColumns: [
- {
- item: { key: tabName },
- },
- ],
- } = Column;
- const params = initParams([...TabColumns, ...FormColumns]);
- const rules = initRules(FormColumns);
- return {
- width: "50%",
- column: 2,
- title: "明 细",
- visible: false,
- loading: false,
- rules: rules,
- params: params,
- tabName,
- TabColumns,
- FormColumns,
- };
- },
- props: {
- selectData: {
- type: [Array],
- require: true,
- },
- },
- computed: {
- $dicts: {
- get() {
- return this.$parent.$parent.$parent.$dicts;
- },
- },
- disabled: {
- get() {
- const { selectData } = this;
- if (selectData.length !== 1) {
- return true;
- }
- },
- set() {},
- },
- },
- watch: {},
- methods: {
- //
- async fetchItem(prop) {
- try {
- // try
- this.loading = true;
- const { params } = this.$parent.$parent.$parent;
- const {
- total,
- rows: [{ id }],
- } = await LIST({ ...params }, { pageNum: prop, pageSize: 1 });
- const { code, data } = await ITEM(id);
- if (code === 200) {
- this.params = data;
- this.params.$index = prop;
- this.params.$total = total;
- 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, initParams } = this;
- this.visible = false;
- this.tabName = TabColumns[0].item.key;
- 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
- >
- <div
- style="
- z-index: 6666;
- position: fixed;
- right: 20px;
- top: 50%;
- transform: translateY(-50%);
- display: flex;
- flex-direction: column;
- "
- >
- <el-button
- :size="$attrs.size"
- :disabled="params.$index === 1"
- circle
- icon="el-icon-top"
- @click="fetchItem(params.$index - 1)"
- style="margin: 0 0 10px 0"
- ></el-button>
- <el-button
- :size="$attrs.size"
- :disabled="params.$index === params.$total"
- circle
- icon="el-icon-bottom"
- @click="fetchItem(params.$index + 1)"
- style="margin: 0"
- ></el-button>
- </div>
- <el-descriptions
- :size="$attrs.size"
- :column="column"
- border
- style="margin: 10px"
- >
- <el-descriptions-item
- v-if="params[item.key]"
- v-for="({ item, attr }, index) in FormColumns"
- :key="index"
- :label="item.title"
- >
- <dict-tag
- v-if="attr.is === 'el-select'"
- :size="$attrs.size"
- :value="params[item.key]"
- :options="$dicts[attr.dictName]"
- />
- <dr-file-preview
- v-else-if="attr.is === 'file-upload'"
- v-model="params[item.key]"
- ></dr-file-preview>
- <span v-else>{{ params[item.key] }}</span>
- </el-descriptions-item>
- </el-descriptions>
- <el-tabs v-model="tabName" :size="$attrs.size" style="margin: 10px">
- <el-tab-pane
- v-for="({ item, attr, TableColumns }, index) in TabColumns"
- :key="index"
- :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 }, cIndex) in TableColumns"
- :key="cIndex"
- :prop="cItem.key"
- :label="cItem.title"
- :width="cItem.width || 250"
- show-overflow-tooltip
- >
- <template slot-scope="scope">
- <dict-tag
- v-if="cAttr.is === 'el-select'"
- :size="$attrs.size"
- :value="scope.row[cItem.key]"
- :options="$dicts[cAttr.dictName]"
- />
- <span v-else>{{
- cAttr.formatter
- ? cAttr.formatter(scope.row[cItem.key])
- : scope.row[cItem.key]
- }}</span>
- </template>
- </el-table-column>
- </el-table>
- </el-tab-pane>
- </el-tabs>
- </el-drawer>
- </el-button>
- </template>
|