index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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, customerName: ""});
  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. },
  183. mounted() {
  184. },
  185. destroyed() {
  186. },
  187. };
  188. </script>
  189. <template>
  190. <el-button v-bind="$attrs" v-on="$listeners" @click="onOpen">
  191. {{ title }}
  192. <el-drawer
  193. :show-close="false"
  194. :size="width"
  195. :title="title"
  196. :visible.sync="visible"
  197. append-to-body
  198. destroy-on-close
  199. @close="onHide"
  200. >
  201. <template slot="title">
  202. <span>{{ title }}</span>
  203. <el-button
  204. type="primary"
  205. :size="$attrs.size"
  206. :loading="loading"
  207. @click="useSubmit('superForm')"
  208. >
  209. 确 认
  210. </el-button>
  211. <el-button :size="$attrs.size" :loading="loading" @click="onHide">
  212. 取 消
  213. </el-button>
  214. </template>
  215. <el-super-form
  216. v-model="params"
  217. :dict="dict"
  218. :rules="rules"
  219. :size="$attrs.size"
  220. :columns="TableColumns"
  221. ref="superForm"
  222. label-width="auto"
  223. label-position="right"
  224. style="padding: 18px"
  225. >
  226. </el-super-form>
  227. <el-tabs v-model="tabName" style="padding: 0 18px 18px">
  228. <el-tab-pane
  229. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  230. :key="index"
  231. :label="item.title"
  232. :name="item.key"
  233. lazy
  234. >
  235. <div v-loading="loading" style="height: 600px; display: flex">
  236. <el-super-table
  237. v-model="params[item.key]"
  238. :dict="dict"
  239. :ref="tabName"
  240. :columns="columns"
  241. :size="$attrs.size"
  242. >
  243. <template slot="materialName" slot-scope="scope">
  244. <component
  245. v-bind="scope.attr"
  246. v-model="scope.row[scope.item.key]"
  247. :size="$attrs.size"
  248. :source.sync="scope.row"
  249. @change="changeMaterialName({ ...scope, selectData: $event })"
  250. >
  251. </component>
  252. </template>
  253. <el-table-column fixed="right" label="操作" width="100">
  254. <template slot="header" slot-scope="scope">
  255. <el-button
  256. type="text"
  257. :size="$attrs.size"
  258. @click="onRowAdd(tabName)"
  259. >
  260. 新增
  261. </el-button>
  262. </template>
  263. <template slot-scope="scope">
  264. <el-button
  265. type="text"
  266. :size="$attrs.size"
  267. @click.native.prevent="onRowRemove(tabName, scope)"
  268. >
  269. 删除
  270. </el-button>
  271. </template>
  272. </el-table-column>
  273. </el-super-table>
  274. </div>
  275. </el-tab-pane>
  276. </el-tabs>
  277. </el-drawer>
  278. </el-button>
  279. </template>
  280. <style scoped></style>