index.vue 9.7 KB

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