index.vue 11 KB

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