index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. } = await fetchExist({ puOrg, customer, supplier, materialCode, priceType: prop.row.priceType });
  104. this.loading = false;
  105. await this.onRowAdd(this.tabName, {
  106. ...item,
  107. currency: currency,
  108. currencyCode: currencyCode,
  109. currencyName: currencyName,
  110. unit: puUnit,
  111. unitCode: puUnitCode,
  112. unitName: puUnitName,
  113. puUnit: puUnit,
  114. puUnitCode: puUnitCode,
  115. puUnitName: puUnitName,
  116. recentlyPrice,
  117. isApprovalFirst,
  118. tax: Number(ntaxrate === "0E-8" ? 0 : ntaxrate),
  119. createByName: createByName,
  120. updateByName: createByName,
  121. id: null,
  122. });
  123. }
  124. },
  125. //
  126. async changeCustomerName(prop) {
  127. console.log("prop", prop)
  128. const {
  129. puOrg,
  130. supplier,
  131. currency,
  132. currencyCode,
  133. currencyName,
  134. } = this.params;
  135. const {
  136. recentlyPrice,
  137. isApprovalFirst,
  138. purchasequantity
  139. } = await fetchExist({puOrg, supplier, materialCode: prop.row.materialCode, customer:prop.row.customer,customerName: prop.row.customerName, priceType: prop.row.priceType});
  140. prop.row.yPurchaseQuantity = purchasequantity
  141. prop.row.recentlyPrice = recentlyPrice
  142. prop.row.isApprovalFirst = isApprovalFirst
  143. },
  144. //
  145. async fetchItem(prop) {
  146. try {
  147. // try
  148. this.loading = true;
  149. const { tabName, TabColumns } = this;
  150. const { TableColumns } = TabColumns.find(
  151. ({ item: { key } }) => key === tabName
  152. );
  153. console.log('看看prop', prop)
  154. const { code, data } = await ITEM(prop, true);
  155. if (code === 200) {
  156. this.params = data;
  157. this.params.priceApplyItems = data.priceApplyItems.map((item) => ({
  158. ...this.$init.params(TableColumns),
  159. ...item,
  160. id: null,
  161. }));
  162. this.params.id = null;
  163. } else {
  164. this.visible = false;
  165. }
  166. } catch (err) {
  167. // catch
  168. console.error(err);
  169. this.visible = false;
  170. } finally {
  171. // finally
  172. this.loading = false;
  173. }
  174. },
  175. //
  176. async onOpen() {
  177. this.visible = true;
  178. const {
  179. selectData: [{ id }],
  180. } = this.$props;
  181. this.params.id = null;
  182. this.params.createBy = null;
  183. this.params.priceCode = null;
  184. this.params.createByName = null;
  185. this.params.effectiveDate = null;
  186. this.params.priceApplyOrgs = [];
  187. this.params.priceApplyItems = this.params.priceApplyItems.map((item) => ({
  188. ...item,
  189. id: null,
  190. applyId: null,
  191. createByName: null,
  192. updateByName: null,
  193. delFlag: 0,
  194. }));
  195. await this.fetchItem(id);
  196. },
  197. //
  198. async onHide() {
  199. const { TabColumns, TableColumns } = useColumns();
  200. this.visible = false;
  201. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  202. },
  203. //
  204. async onRowAdd(prop, pushParams = {}) {
  205. this.$refs.superForm.validate(async (valid) => {
  206. if (valid) {
  207. const { TabColumns } = this;
  208. const { TableColumns } = TabColumns.find(
  209. ({ item: { key } }) => key === prop
  210. );
  211. this.params[prop].push({
  212. delFlag: "0",
  213. ...this.$init.params(TableColumns),
  214. ...pushParams,
  215. });
  216. }
  217. });
  218. },
  219. //
  220. async onRowRemove(prop, scope) {
  221. const { $index } = scope;
  222. this.params[prop].splice($index, 1);
  223. },
  224. //
  225. async useSubmit(prop) {
  226. this.$refs[prop].validate(async (valid) => {
  227. console.log(this.params);
  228. if (valid) {
  229. try {
  230. this.loading = true;
  231. this.params.priceApplyOrgs = [];
  232. const { msg, code } = await SAVE(this.params);
  233. if (code === 200) {
  234. this.onHide();
  235. this.$emit("success");
  236. this.$notify.success(msg);
  237. }
  238. } catch (err) {
  239. // catch
  240. console.error(err);
  241. } finally {
  242. // finally
  243. this.loading = false;
  244. }
  245. } else {
  246. return false;
  247. }
  248. });
  249. },
  250. },
  251. created() {},
  252. mounted() {},
  253. destroyed() {},
  254. };
  255. </script>
  256. <template>
  257. <el-button
  258. v-bind="$attrs"
  259. v-on="$listeners"
  260. :disabled="disabled"
  261. @click="onOpen"
  262. >
  263. {{ title }}
  264. <el-drawer
  265. :show-close="false"
  266. :size="width"
  267. :title="title"
  268. :visible.sync="visible"
  269. append-to-body
  270. destroy-on-close
  271. @close="onHide"
  272. >
  273. <template slot="title">
  274. <span>{{ title }}</span>
  275. <el-button
  276. type="primary"
  277. :size="$attrs.size"
  278. :loading="loading"
  279. @click="useSubmit('superForm')"
  280. >
  281. 确 认
  282. </el-button>
  283. <el-button :size="$attrs.size" :loading="loading" @click="onHide">
  284. 取 消
  285. </el-button>
  286. </template>
  287. <el-super-form
  288. v-model="params"
  289. :dict="dict"
  290. :rules="rules"
  291. :size="$attrs.size"
  292. :columns="TableColumns"
  293. ref="superForm"
  294. label-width="auto"
  295. label-position="right"
  296. style="padding: 18px"
  297. >
  298. </el-super-form>
  299. <el-tabs v-model="tabName" style="padding: 0 18px 18px">
  300. <el-tab-pane
  301. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  302. :key="index"
  303. :label="item.title"
  304. :name="item.key"
  305. lazy
  306. >
  307. <div v-loading="loading" style="height: 600px; display: flex">
  308. <el-super-table
  309. v-model="params[item.key]"
  310. :dict="dict"
  311. :ref="tabName"
  312. :columns="columns"
  313. :size="$attrs.size"
  314. >
  315. <template slot="materialName" slot-scope="scope">
  316. <component
  317. v-bind="scope.attr"
  318. v-model="scope.row[scope.item.key]"
  319. :size="$attrs.size"
  320. :source.sync="scope.row"
  321. @change="changeMaterialName({ ...scope, selectData: $event })"
  322. >
  323. </component>
  324. </template>
  325. <template slot="customerName" slot-scope="scope">
  326. <component
  327. v-bind="scope.attr"
  328. v-model="scope.row[scope.item.key]"
  329. :size="$attrs.size"
  330. :source.sync="scope.row"
  331. @change="changeCustomerName({ ...scope, selectData: $event })"
  332. >
  333. </component>
  334. </template>
  335. <el-table-column fixed="right" label="操作" width="100">
  336. <template slot="header" slot-scope="scope">
  337. <el-button :size="$attrs.size" @click="onRowAdd(tabName)">
  338. 新增
  339. </el-button>
  340. </template>
  341. <template slot-scope="scope">
  342. <el-button
  343. :size="$attrs.size"
  344. @click.native.prevent="onRowRemove(tabName, scope)"
  345. >
  346. 删除
  347. </el-button>
  348. </template>
  349. </el-table-column>
  350. </el-super-table>
  351. </div>
  352. </el-tab-pane>
  353. </el-tabs>
  354. </el-drawer>
  355. </el-button>
  356. </template>
  357. <style scoped></style>