index.vue 9.7 KB

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