index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <script>
  2. import useColumns from "./columns";
  3. import { initParams } from "@/utils/init.js";
  4. import { ITEM } from "@/api/business/purchase/contract";
  5. export default {
  6. name: "SeeDrawer",
  7. props: {
  8. selectData: {
  9. type: [Array],
  10. require: true,
  11. },
  12. },
  13. components: {
  14. ElDictTag: () => import("@/components/DictTag/index.vue"),
  15. ElFilePreview: () => import("@/components/file-preview/index.vue"),
  16. ElComputedInputV2: () => import("@/components/computed-input-v2/index.vue"),
  17. },
  18. data() {
  19. const {
  20. TabColumns,
  21. FormColumns,
  22. TabColumns: [
  23. {
  24. item: { key: tabName },
  25. },
  26. ],
  27. } = useColumns();
  28. const params = initParams([...TabColumns, ...FormColumns]);
  29. return {
  30. column: 2,
  31. width: "50%",
  32. title: "明 细",
  33. visible: false,
  34. loading: false,
  35. params: params,
  36. tabName: tabName,
  37. TabColumns,
  38. FormColumns,
  39. };
  40. },
  41. computed: {
  42. $dicts: {
  43. get() {
  44. return this.$parent.$parent.$parent.dict.type;
  45. },
  46. },
  47. disabled: {
  48. get() {
  49. const { selectData } = this;
  50. if (selectData.length !== 1) {
  51. return true;
  52. }
  53. },
  54. set() {},
  55. },
  56. },
  57. watch: {},
  58. methods: {
  59. async fetchItem(prop) {
  60. try {
  61. // try
  62. this.loading = true;
  63. const { code, data } = await ITEM(prop);
  64. if (code === 200) {
  65. this.params = data;
  66. return true;
  67. } else {
  68. return false;
  69. }
  70. } catch (err) {
  71. // catch
  72. console.error(err);
  73. } finally {
  74. // finally
  75. this.loading = false;
  76. }
  77. },
  78. //
  79. async open(prop) {
  80. this.visible = await this.fetchItem(prop);
  81. },
  82. //
  83. async hide() {
  84. const {
  85. TabColumns,
  86. FormColumns,
  87. TabColumns: [
  88. {
  89. item: { key: tabName },
  90. },
  91. ],
  92. } = useColumns();
  93. this.visible = false;
  94. this.tabName = tabName;
  95. this.params = initParams([...TabColumns, ...FormColumns]);
  96. },
  97. },
  98. created() {},
  99. mounted() {},
  100. destroyed() {},
  101. };
  102. </script>
  103. <template>
  104. <el-button
  105. v-bind="$attrs"
  106. v-on="$listeners"
  107. :disabled="disabled"
  108. @click="open(selectData[0])"
  109. >
  110. {{ title }}
  111. <el-drawer
  112. :size="width"
  113. :title="title"
  114. :visible.sync="visible"
  115. append-to-body
  116. >
  117. <el-descriptions
  118. :size="$attrs.size"
  119. :column="column"
  120. border
  121. style="margin: 10px"
  122. >
  123. <el-descriptions-item
  124. v-if="params[item.key]"
  125. v-for="{ item, attr } in FormColumns"
  126. :key="item.key"
  127. :label="item.title"
  128. :labelStyle="{ width: '150px' }"
  129. :contentStyle="{ width: 'auto' }"
  130. >
  131. <component
  132. v-if="attr.is === 'el-dict-tag'"
  133. v-bind="attr"
  134. v-model="params[item.key]"
  135. :size="$attrs.size"
  136. :options="$dicts[attr.dictName]"
  137. ></component>
  138. <component
  139. v-else-if="attr.is === 'el-file-preview'"
  140. v-bind="attr"
  141. v-model="params[item.key]"
  142. ></component>
  143. <component
  144. v-else-if="attr.is === 'el-computed-input-v2'"
  145. v-bind="attr"
  146. v-model="params[item.key]"
  147. ></component>
  148. <component is="span" v-else>{{ params[item.key] }}</component>
  149. </el-descriptions-item>
  150. </el-descriptions>
  151. <el-tabs v-model="tabName" :size="$attrs.size" style="margin: 10px">
  152. <el-tab-pane
  153. v-for="{ item, TableColumns } in TabColumns"
  154. :key="item.key"
  155. :name="item.key"
  156. :label="item.title"
  157. lazy
  158. >
  159. <el-table :size="$attrs.size" :data="params[item.key]">
  160. <el-table-column
  161. v-for="{ item: cItem, attr: cAttr } in TableColumns"
  162. :key="cItem.key"
  163. :prop="cItem.key"
  164. :label="cItem.title"
  165. :width="cItem.width || 300"
  166. show-overflow-tooltip
  167. >
  168. <template slot-scope="scope">
  169. <component
  170. v-if="cAttr.is === 'el-dict-tag'"
  171. v-bind="cAttr"
  172. v-model="scope.row[cItem.key]"
  173. :size="$attrs.size"
  174. :options="$dicts[cAttr.dictName]"
  175. ></component>
  176. <component
  177. v-else-if="cAttr.is === 'el-file-preview'"
  178. v-bind="cAttr"
  179. v-model="scope.row[cItem.key]"
  180. ></component>
  181. <component
  182. v-else-if="cAttr.is === 'el-computed-input-v2'"
  183. v-bind="cAttr"
  184. v-model="scope.row[cItem.key]"
  185. ></component>
  186. <component is="span" v-else>{{
  187. scope.row[cItem.key] || "--"
  188. }}</component>
  189. </template>
  190. </el-table-column>
  191. </el-table>
  192. </el-tab-pane>
  193. </el-tabs>
  194. </el-drawer>
  195. </el-button>
  196. </template>