index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <script>
  2. import { TableColumns } from "./column";
  3. import { initDicts } from "@/utils/init.js";
  4. import { FIRSTDIRECT, ADD } from "@/api/business/purchase/task";
  5. export default {
  6. name: "FirstDirectPurchaseDrawer",
  7. dicts: [...initDicts(TableColumns)],
  8. props: {
  9. selectData: {
  10. type: [Array],
  11. require: true,
  12. },
  13. },
  14. components: {
  15. ElSuperTable: () => import("@/components/super-table/index.vue"),
  16. ElDictTag: () => import("@/components/DictTag/index.vue"),
  17. ElComputedInputV2: () => import("@/components/computed-input-v2/index.vue"),
  18. },
  19. data() {
  20. return {
  21. title: "订单生成",
  22. width: "100%",
  23. column: 1,
  24. visible: false,
  25. loading: false,
  26. tableColumns: TableColumns,
  27. data: [],
  28. };
  29. },
  30. computed: {
  31. disabled: {
  32. get() {
  33. return !this.selectData.length;
  34. },
  35. set() {},
  36. },
  37. },
  38. watch: {},
  39. methods: {
  40. //
  41. async open(prop) {
  42. this.visible = await this.fetchItem(prop);
  43. },
  44. //
  45. hide() {
  46. this.visible = false;
  47. },
  48. //
  49. async fetchItem(prop) {
  50. try {
  51. // try
  52. this.loading = true;
  53. const { code, data } = await FIRSTDIRECT(prop);
  54. if (code === 200) {
  55. this.data = data.map((item) => ({
  56. ...item,
  57. orderPriceVos: item.orderPriceVos.map((cItem) => ({
  58. ...item,
  59. ...cItem,
  60. })),
  61. }));
  62. return true;
  63. } else {
  64. return false;
  65. }
  66. } catch (err) {
  67. // catch
  68. console.error(err);
  69. } finally {
  70. // finally
  71. this.loading = false;
  72. }
  73. },
  74. //
  75. async submit(prop) {
  76. const params = prop
  77. .map((item) => ({
  78. ...item,
  79. orderPriceVos: item.orderPriceVos.filter(
  80. (citem) => citem.purchaseQuantity
  81. ),
  82. }))
  83. .filter((item) => item.orderPriceVos.length);
  84. try {
  85. // try
  86. const { msg, code } = await ADD(params);
  87. if (code === 200) {
  88. this.hide();
  89. this.$emit("success");
  90. this.$notify.success({ title: msg, duration: 3000 });
  91. }
  92. } catch (err) {
  93. // catch
  94. } finally {
  95. // finally
  96. }
  97. },
  98. },
  99. created() {},
  100. mounted() {},
  101. destroyed() {},
  102. };
  103. </script>
  104. <template>
  105. <el-button
  106. v-bind="$attrs"
  107. v-on="$listeners"
  108. :disabled="disabled"
  109. @click="open(selectData)"
  110. >
  111. {{ title }}
  112. <el-drawer
  113. :show-close="false"
  114. :size="width"
  115. :title="title"
  116. :visible.sync="visible"
  117. append-to-body
  118. >
  119. <template slot="title">
  120. <span>{{ title }}</span>
  121. <el-button
  122. :size="$attrs.size"
  123. :loading="loading"
  124. @click="visible = false"
  125. >取 消</el-button
  126. >
  127. <el-button
  128. type="primary"
  129. :size="$attrs.size"
  130. :loading="loading"
  131. @click="submit(data)"
  132. >确 认</el-button
  133. >
  134. </template>
  135. <div v-for="(item, index) in data" :key="index" class="m-4">
  136. <h3 class="mb-4">
  137. <span style="margin-right: 10px">{{ item.materialName }}</span>
  138. <span style="color: tomato">{{ item.puQty }}</span>
  139. (<span style="color: tomato">{{
  140. item.puQty - (item.executeQty || 0)
  141. }}</span
  142. >) <span> {{ item.puUnitName }}</span>
  143. </h3>
  144. <el-super-table
  145. v-model="item.orderPriceVos"
  146. :columns="tableColumns"
  147. :size="$attrs.size"
  148. :dict="dict"
  149. >
  150. <template slot="purchaseQuantity" slot-scope="scope">
  151. <component
  152. v-bind="scope.attr"
  153. v-model="scope.row[scope.item.key]"
  154. :size="$attrs.size"
  155. :max="scope.attr.max(scope.row)"
  156. >
  157. </component>
  158. </template>
  159. </el-super-table>
  160. </div>
  161. </el-drawer>
  162. </el-button>
  163. </template>
  164. <style scoped></style>