index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <script>
  2. import useColumns from "./columns";
  3. import { EXIST } from "@/api/business/purchase/catalogue";
  4. import { ITEM, 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: "CopyDrawer",
  20. props: {
  21. dict: {
  22. type: Object,
  23. },
  24. selectData: {
  25. type: [Array],
  26. require: true,
  27. },
  28. },
  29. components: {
  30. ElSuperForm: () => import("@/components/super-form/index.vue"),
  31. ElSuperTable: () => import("@/components/super-table/index.vue"),
  32. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  33. },
  34. data() {
  35. const {
  36. TabColumns,
  37. TableColumns,
  38. TabColumns: [
  39. {
  40. item: { key: tabName },
  41. },
  42. ],
  43. } = useColumns();
  44. const rules = this.$init.rules([...TabColumns, ...TableColumns]);
  45. const params = this.$init.params([...TabColumns, ...TableColumns]);
  46. return {
  47. title: "复 制",
  48. width: "100%",
  49. visible: false,
  50. loading: false,
  51. rules: rules,
  52. params: params,
  53. tabName: tabName,
  54. TabColumns: TabColumns,
  55. TableColumns: TableColumns,
  56. };
  57. },
  58. computed: {
  59. disabled: {
  60. get() {
  61. const {
  62. selectData: { length },
  63. } = this.$props;
  64. if (length !== 1) {
  65. return true;
  66. }
  67. },
  68. set() {},
  69. },
  70. },
  71. watch: {},
  72. methods: {
  73. //
  74. async changeMaterialName(prop) {
  75. const { selectData } = prop;
  76. const {
  77. puOrg,
  78. customer,
  79. supplier,
  80. currency,
  81. currencyCode,
  82. currencyName,
  83. } = this.params;
  84. const { nickName: createByName } = this.$store.state.user;
  85. if (selectData.length) {
  86. this.params[this.tabName].splice(-1);
  87. }
  88. for (const item of selectData) {
  89. this.loading = true;
  90. const { tax: taxName, unitName, code: materialCode } = item;
  91. // task 1
  92. const { ntaxrate } = await tax(taxName);
  93. // task 2
  94. const {
  95. id: puUnit,
  96. code: puUnitCode,
  97. name: puUnitName,
  98. } = await unit(unitName);
  99. // task 3
  100. const {
  101. recentlyPrice = "0",
  102. isApprovalFirst = "N",
  103. purchasequantity
  104. } = await fetchExist({ puOrg, customer, supplier, materialCode, priceType: prop.row.priceType });
  105. this.loading = false;
  106. await this.onRowAdd(this.tabName, {
  107. ...item,
  108. currency: currency,
  109. currencyCode: currencyCode,
  110. currencyName: currencyName,
  111. unit: puUnit,
  112. unitCode: puUnitCode,
  113. unitName: puUnitName,
  114. puUnit: puUnit,
  115. puUnitCode: puUnitCode,
  116. puUnitName: puUnitName,
  117. recentlyPrice,
  118. isApprovalFirst,
  119. yPurchaseQuantity: purchasequantity,
  120. tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
  121. createByName: createByName,
  122. updateByName: createByName,
  123. id: null,
  124. });
  125. }
  126. },
  127. //
  128. async changeCustomerName(prop) {
  129. console.log("prop", prop)
  130. const {
  131. puOrg,
  132. supplier,
  133. currency,
  134. currencyCode,
  135. currencyName,
  136. } = this.params;
  137. const {
  138. recentlyPrice,
  139. isApprovalFirst,
  140. purchasequantity
  141. } = await fetchExist({puOrg, supplier, materialCode: prop.row.materialCode, customer:prop.row.customer,customerName: prop.row.customerName, priceType: prop.row.priceType});
  142. prop.row.yPurchaseQuantity = purchasequantity
  143. prop.row.recentlyPrice = recentlyPrice
  144. prop.row.isApprovalFirst = isApprovalFirst
  145. },
  146. //
  147. async fetchItem(prop) {
  148. try {
  149. // try
  150. this.loading = true;
  151. const { tabName, TabColumns } = this;
  152. const { TableColumns } = TabColumns.find(
  153. ({ item: { key } }) => key === tabName
  154. );
  155. console.log('看看prop', prop)
  156. const { code, data } = await ITEM(prop, true);
  157. if (code === 200) {
  158. this.params = data;
  159. this.params.priceApplyItems = data.priceApplyItems.map((item) => ({
  160. ...this.$init.params(TableColumns),
  161. ...item,
  162. id: null,
  163. }));
  164. this.params.id = null;
  165. } else {
  166. this.visible = false;
  167. }
  168. } catch (err) {
  169. // catch
  170. console.error(err);
  171. this.visible = false;
  172. } finally {
  173. // finally
  174. this.loading = false;
  175. }
  176. },
  177. //
  178. async onOpen() {
  179. this.visible = true;
  180. const {
  181. selectData: [{ id }],
  182. } = this.$props;
  183. this.params.id = null;
  184. this.params.createBy = null;
  185. this.params.priceCode = null;
  186. this.params.createByName = null;
  187. this.params.effectiveDate = null;
  188. this.params.priceApplyOrgs = [];
  189. this.params.priceApplyItems = this.params.priceApplyItems.map((item) => ({
  190. ...item,
  191. id: null,
  192. applyId: null,
  193. createByName: null,
  194. updateByName: null,
  195. delFlag: 0,
  196. }));
  197. await this.fetchItem(id);
  198. },
  199. //
  200. async onHide() {
  201. const { TabColumns, TableColumns } = useColumns();
  202. this.visible = false;
  203. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  204. this.$emit("success");
  205. },
  206. //
  207. async onRowAdd(prop, pushParams = {}) {
  208. this.$refs.superForm.validate(async (valid) => {
  209. if (valid) {
  210. const { TabColumns } = this;
  211. const { TableColumns } = TabColumns.find(
  212. ({ item: { key } }) => key === prop
  213. );
  214. this.params[prop].push({
  215. delFlag: "0",
  216. ...this.$init.params(TableColumns),
  217. ...pushParams,
  218. });
  219. }
  220. });
  221. },
  222. //
  223. async onRowRemove(prop, scope) {
  224. const { $index } = scope;
  225. this.params[prop].splice($index, 1);
  226. },
  227. //
  228. async useSubmit(prop) {
  229. this.$refs[prop].validate(async (valid) => {
  230. console.log(this.params);
  231. if (valid) {
  232. try {
  233. this.loading = true;
  234. this.params.priceApplyOrgs = [];
  235. const { msg, code } = await SAVE(this.params);
  236. if (code === 200) {
  237. this.onHide();
  238. this.$emit("success");
  239. this.$notify.success(msg);
  240. }
  241. } catch (err) {
  242. // catch
  243. console.error(err);
  244. } finally {
  245. // finally
  246. this.loading = false;
  247. }
  248. } else {
  249. return false;
  250. }
  251. });
  252. },
  253. },
  254. created() {},
  255. mounted() {},
  256. destroyed() {},
  257. };
  258. </script>
  259. <template>
  260. <el-button
  261. v-bind="$attrs"
  262. v-on="$listeners"
  263. :disabled="disabled"
  264. @click="onOpen"
  265. >
  266. {{ title }}
  267. <el-drawer
  268. :show-close="false"
  269. :size="width"
  270. :title="title"
  271. :visible.sync="visible"
  272. append-to-body
  273. destroy-on-close
  274. @close="onHide"
  275. >
  276. <template slot="title">
  277. <span>{{ title }}</span>
  278. <el-button
  279. type="primary"
  280. :size="$attrs.size"
  281. :loading="loading"
  282. @click="useSubmit('superForm')"
  283. >
  284. 确 认
  285. </el-button>
  286. <el-button :size="$attrs.size" :loading="loading" @click="onHide">
  287. 取 消
  288. </el-button>
  289. </template>
  290. <el-super-form
  291. v-model="params"
  292. :dict="dict"
  293. :rules="rules"
  294. :size="$attrs.size"
  295. :columns="TableColumns"
  296. ref="superForm"
  297. label-width="auto"
  298. label-position="right"
  299. style="padding: 18px"
  300. >
  301. </el-super-form>
  302. <el-tabs v-model="tabName" style="padding: 0 18px 18px">
  303. <el-tab-pane
  304. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  305. :key="index"
  306. :label="item.title"
  307. :name="item.key"
  308. lazy
  309. >
  310. <div v-loading="loading" style="height: 250px; display: flex">
  311. <el-super-table
  312. v-model="params[item.key]"
  313. :dict="dict"
  314. :ref="tabName"
  315. :columns="columns"
  316. :size="$attrs.size"
  317. >
  318. <template slot="materialName" slot-scope="scope">
  319. <component
  320. v-bind="scope.attr"
  321. v-model="scope.row[scope.item.key]"
  322. :size="$attrs.size"
  323. :source.sync="scope.row"
  324. @change="changeMaterialName({ ...scope, selectData: $event })"
  325. >
  326. </component>
  327. </template>
  328. <template slot="customerName" slot-scope="scope">
  329. <component
  330. v-bind="scope.attr"
  331. v-model="scope.row[scope.item.key]"
  332. :size="$attrs.size"
  333. :source.sync="scope.row"
  334. @change="changeCustomerName({ ...scope, selectData: $event })"
  335. >
  336. </component>
  337. </template>
  338. <el-table-column fixed="right" label="操作" width="100">
  339. <template slot="header" slot-scope="scope">
  340. <el-button :size="$attrs.size" @click="onRowAdd(tabName)">
  341. 新增
  342. </el-button>
  343. </template>
  344. <template slot-scope="scope">
  345. <el-button
  346. :size="$attrs.size"
  347. @click.native.prevent="onRowRemove(tabName, scope)"
  348. >
  349. 删除
  350. </el-button>
  351. </template>
  352. </el-table-column>
  353. </el-super-table>
  354. </div>
  355. </el-tab-pane>
  356. </el-tabs>
  357. </el-drawer>
  358. </el-button>
  359. </template>
  360. <style scoped></style>