index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <script>
  2. import useColumns from "./columns";
  3. import { EXIST } from "@/api/business/purchase/catalogue";
  4. import { SAVE } from "@/api/business/purchase/apply";
  5. import { tax, unit, currency } from "@/components/popover-select-v2/fetch";
  6. const fetchExist = async (prop) => {
  7. try {
  8. // try
  9. const { code, data } = await EXIST(prop);
  10. if (code === 200) return data;
  11. } catch (err) {
  12. // catch
  13. console.error(err);
  14. } finally {
  15. // finally
  16. }
  17. };
  18. export default {
  19. name: "AddDrawer",
  20. props: {
  21. dict: {
  22. type: Object,
  23. },
  24. },
  25. components: {
  26. ElSuperForm: () => import("@/components/super-form/index.vue"),
  27. ElSuperTable: () => import("@/components/super-table/index.vue"),
  28. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  29. },
  30. data() {
  31. const {
  32. TabColumns,
  33. TableColumns,
  34. TabColumns: [
  35. {
  36. item: { key: tabName },
  37. },
  38. ],
  39. } = useColumns();
  40. const rules = this.$init.rules([...TabColumns, ...TableColumns]);
  41. const params = this.$init.params([...TabColumns, ...TableColumns]);
  42. return {
  43. title: "新 增",
  44. width: "100%",
  45. visible: false,
  46. loading: false,
  47. rules: rules,
  48. params: params,
  49. tabName: tabName,
  50. TabColumns: TabColumns,
  51. TableColumns: TableColumns,
  52. };
  53. },
  54. computed: {},
  55. watch: {},
  56. methods: {
  57. //
  58. async changeMaterialName(prop) {
  59. const { selectData } = prop;
  60. const {
  61. puOrg,
  62. customer,
  63. supplier,
  64. currency,
  65. currencyCode,
  66. currencyName,
  67. } = this.params;
  68. const { nickName: createByName } = this.$store.state.user;
  69. if (selectData.length) {
  70. this.params[this.tabName].splice(-1);
  71. }
  72. for (const item of selectData) {
  73. this.loading = true;
  74. const { tax: taxName, unitName, code: materialCode } = item;
  75. // task 1
  76. const { ntaxrate } = await tax(taxName);
  77. // task 2
  78. const {
  79. id: puUnit,
  80. code: puUnitCode,
  81. name: puUnitName,
  82. } = await unit(unitName);
  83. // task 3
  84. const {
  85. recentlyPrice = "0",
  86. isApprovalFirst = "N",
  87. isPriceAdjustment = "N",
  88. } = await fetchExist({ puOrg, customer, supplier, materialCode });
  89. this.loading = false;
  90. await this.onRowAdd(this.tabName, {
  91. ...item,
  92. currency: currency,
  93. currencyCode: currencyCode,
  94. currencyName: currencyName,
  95. unit: puUnit,
  96. unitCode: puUnitCode,
  97. unitName: puUnitName,
  98. puUnit: puUnit,
  99. puUnitCode: puUnitCode,
  100. puUnitName: puUnitName,
  101. recentlyPrice,
  102. isApprovalFirst,
  103. isPriceAdjustment,
  104. tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
  105. createByName: createByName,
  106. updateByName: createByName,
  107. id: null,
  108. });
  109. }
  110. },
  111. //
  112. async onOpen() {
  113. this.visible = true;
  114. const {
  115. deptId: puDept,
  116. deptName: puDeptName,
  117. name: buyer,
  118. nickName: buyerName,
  119. } = this.$store.state.user;
  120. const { id, code, name } = await currency("人民币");
  121. this.params.currency = id;
  122. this.params.currencyCode = code;
  123. this.params.currencyName = name;
  124. this.params.buyer = buyer;
  125. this.params.buyerName = buyerName;
  126. this.params.puDept = puDept;
  127. this.params.puDeptName = puDeptName;
  128. },
  129. //
  130. async onHide() {
  131. const { TabColumns, TableColumns } = useColumns();
  132. this.visible = false;
  133. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  134. },
  135. //
  136. async onRowAdd(prop, pushParams = {}) {
  137. this.$refs.superForm.validate(async (valid) => {
  138. if (valid) {
  139. const { TabColumns } = this;
  140. const { TableColumns } = TabColumns.find(
  141. ({ item: { key } }) => key === prop
  142. );
  143. this.params[prop].push({
  144. delFlag: "0",
  145. ...this.$init.params(TableColumns),
  146. ...pushParams,
  147. });
  148. }
  149. });
  150. },
  151. //
  152. async onRowRemove(prop, scope) {
  153. const { $index } = scope;
  154. this.params[prop].splice($index, 1);
  155. },
  156. //
  157. async useSubmit(prop) {
  158. this.$refs[prop].validate(async (valid) => {
  159. if (valid) {
  160. try {
  161. this.loading = true;
  162. const { msg, code } = await SAVE(this.params);
  163. if (code === 200) {
  164. this.onHide();
  165. this.$emit("success");
  166. this.$notify.success(msg);
  167. }
  168. } catch (err) {
  169. // catch
  170. console.error(err);
  171. } finally {
  172. // finally
  173. this.loading = false;
  174. }
  175. } else {
  176. return false;
  177. }
  178. });
  179. },
  180. },
  181. created() {},
  182. mounted() {},
  183. destroyed() {},
  184. };
  185. </script>
  186. <template>
  187. <el-button v-bind="$attrs" v-on="$listeners" @click="onOpen">
  188. {{ title }}
  189. <el-drawer
  190. :show-close="false"
  191. :size="width"
  192. :title="title"
  193. :visible.sync="visible"
  194. append-to-body
  195. destroy-on-close
  196. @close="onHide"
  197. >
  198. <template slot="title">
  199. <span>{{ title }}</span>
  200. <el-button
  201. type="primary"
  202. :size="$attrs.size"
  203. :loading="loading"
  204. @click="useSubmit('superForm')"
  205. >
  206. 确 认
  207. </el-button>
  208. <el-button :size="$attrs.size" :loading="loading" @click="onHide">
  209. 取 消
  210. </el-button>
  211. </template>
  212. <el-super-form
  213. v-model="params"
  214. :dict="dict"
  215. :rules="rules"
  216. :size="$attrs.size"
  217. :columns="TableColumns"
  218. ref="superForm"
  219. label-width="auto"
  220. label-position="right"
  221. style="padding: 18px"
  222. >
  223. </el-super-form>
  224. <el-tabs v-model="tabName" style="padding: 0 18px 18px">
  225. <el-tab-pane
  226. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  227. :key="index"
  228. :label="item.title"
  229. :name="item.key"
  230. lazy
  231. >
  232. <div v-loading="loading" style="height: 600px; display: flex">
  233. <el-super-table
  234. v-model="params[item.key]"
  235. :dict="dict"
  236. :ref="tabName"
  237. :columns="columns"
  238. :size="$attrs.size"
  239. >
  240. <template slot="materialName" slot-scope="scope">
  241. <component
  242. v-bind="scope.attr"
  243. v-model="scope.row[scope.item.key]"
  244. :size="$attrs.size"
  245. :source.sync="scope.row"
  246. @change="changeMaterialName({ ...scope, selectData: $event })"
  247. >
  248. </component>
  249. </template>
  250. <el-table-column fixed="right" label="操作" width="100">
  251. <template slot="header" slot-scope="scope">
  252. <el-button
  253. type="text"
  254. :size="$attrs.size"
  255. @click="onRowAdd(tabName)"
  256. >
  257. 新增
  258. </el-button>
  259. </template>
  260. <template slot-scope="scope">
  261. <el-button
  262. type="text"
  263. :size="$attrs.size"
  264. @click.native.prevent="onRowRemove(tabName, scope)"
  265. >
  266. 删除
  267. </el-button>
  268. </template>
  269. </el-table-column>
  270. </el-super-table>
  271. </div>
  272. </el-tab-pane>
  273. </el-tabs>
  274. </el-drawer>
  275. </el-button>
  276. </template>
  277. <style scoped></style>