index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!-- 采购员上级采购经理匹配——详情 -->
  2. <script>
  3. import useColumns from "./columns";
  4. import { ADD, DETAILS, EDIT } from "@/api/business/purchase/match";
  5. export default {
  6. name: "MatchDetails",
  7. props: {
  8. dict: {
  9. type: Object,
  10. },
  11. addType: {
  12. type: String,
  13. default: "add",
  14. },
  15. data: {
  16. type: Array,
  17. default: () => [],
  18. },
  19. },
  20. components: {
  21. ElSuperForm: () => import("@/components/super-form/index.vue"),
  22. ElPopoverMultipleTreeSelect: () =>
  23. import("@/components/popover-tree-select/multiple.vue"),
  24. },
  25. data() {
  26. const { FormColumns } = useColumns();
  27. const params = this.$init.params(FormColumns);
  28. const rules = this.$init.rules(FormColumns);
  29. return {
  30. rules,
  31. params: {
  32. ...params,
  33. enable: "0",
  34. },
  35. FormColumns,
  36. width: "100%",
  37. visible: false,
  38. loading: false,
  39. };
  40. },
  41. computed: {
  42. title: {
  43. get() {
  44. const { addType } = this;
  45. if (addType === "add") {
  46. return "新 增";
  47. }
  48. if (addType === "edit") {
  49. return "编 辑";
  50. }
  51. return "查 看";
  52. },
  53. set() {},
  54. },
  55. innerValue: {
  56. get() {
  57. let { data } = this.$props;
  58. return data.length ? data[0] : null;
  59. },
  60. set() {},
  61. },
  62. },
  63. methods: {
  64. setVisible(prop) {
  65. this.visible = prop;
  66. },
  67. //
  68. async fetchItem(id) {
  69. try {
  70. this.loading = true;
  71. let { code, msg, data } = await DETAILS({ id });
  72. if (code === 200) {
  73. this.params = data;
  74. }
  75. } catch (error) {
  76. } finally {
  77. this.loading = false;
  78. }
  79. },
  80. beforeOpen() {
  81. let {
  82. $props: { addType },
  83. innerValue,
  84. } = this;
  85. if (addType !== "add") {
  86. this.fetchItem(innerValue.id);
  87. }
  88. },
  89. hide() {
  90. this.visible = false;
  91. this.params = { ...this.$init.params(this.FormColumns), enable: "0" };
  92. this.$emit("refresh");
  93. },
  94. useSave(prop) {
  95. console.log(this.params,"params");
  96. this.$refs[prop].$refs[prop].validate(async (valid) => {
  97. if (valid) {
  98. try {
  99. this.loading = true;
  100. let {
  101. $props: { addType },
  102. params,
  103. } = this;
  104. let { code, msg } =
  105. addType === "edit"
  106. ? await EDIT({ ...params })
  107. : await ADD({ ...params });
  108. if (code === 200) {
  109. this.$notify.success(msg);
  110. this.hide();
  111. }
  112. } catch (err) {
  113. console.error(err);
  114. } finally {
  115. this.loading = false;
  116. }
  117. } else {
  118. return false;
  119. }
  120. });
  121. },
  122. },
  123. created() {},
  124. };
  125. </script>
  126. <template>
  127. <el-drawer
  128. v-bind="$attrs"
  129. v-on="$listeners"
  130. :size="width"
  131. :visible.sync="visible"
  132. destroy-on-close
  133. :show-close="false"
  134. @close="hide"
  135. @open="beforeOpen"
  136. v-loading="loading"
  137. >
  138. <div
  139. slot="title"
  140. style="display: flex; justify-content: space-between; align-items: center"
  141. >
  142. <h3>{{ title }}</h3>
  143. <div>
  144. <el-button
  145. v-show="addType !== 'see'"
  146. type="primary"
  147. :size="$attrs.size"
  148. :loading="loading"
  149. @click="useSave('superForm')"
  150. >保 存</el-button
  151. >
  152. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  153. >取 消</el-button
  154. >
  155. </div>
  156. </div>
  157. <el-super-form
  158. v-model="params"
  159. :dict="dict"
  160. :rules="rules"
  161. :size="$attrs.size"
  162. :columns="FormColumns"
  163. ref="superForm"
  164. label-width="auto"
  165. label-position="right"
  166. style="padding: 20px"
  167. :disabled="addType === 'see'"
  168. >
  169. <template slot="classOneObjectList" slot-scope="scope">
  170. <component
  171. v-bind="scope.attr"
  172. v-model="scope.row[scope.item.key]"
  173. :size="$attrs.size"
  174. :source.sync="scope.row"
  175. :closable="addType !== 'see'"
  176. >
  177. </component
  178. ></template>
  179. </el-super-form>
  180. </el-drawer>
  181. </template>
  182. <style scoped>
  183. >>> .el-drawer__header {
  184. margin-bottom: 0;
  185. padding: 5px 20px;
  186. }
  187. </style>