index.vue 11 KB

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