index.vue 11 KB

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