index.vue 5.1 KB

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