index.vue 11 KB

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