index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. priceApply: {
  78. get() {
  79. this.params.priceApplyItems = this.params.priceApplyItems.map(
  80. (item, index) => ({
  81. ...item,
  82. $index: index,
  83. })
  84. );
  85. return {
  86. priceApplyItems: this.params.priceApplyItems.filter(
  87. ({ delFlag }) => delFlag !== "2"
  88. ),
  89. };
  90. },
  91. set() {},
  92. },
  93. },
  94. watch: {},
  95. methods: {
  96. //
  97. changeMaterialName(prop) {
  98. const { row } = prop;
  99. const { puOrg, customer, supplier } = this.params;
  100. const { tax: taxName, unitName, code: materialCode } = row;
  101. // task 1
  102. tax(taxName).then((res) => {
  103. const { ntaxrate } = res;
  104. row.tax = ntaxrate === "0E-8" ? "0.000000" : (ntaxrate * 1).toFixed(6);
  105. });
  106. // task 2
  107. unit(unitName).then((res) => {
  108. const { id, code, name } = res;
  109. row.unit = id;
  110. row.unitCode = code;
  111. row.unitName = name;
  112. row.puUnit = id;
  113. row.puUnitCode = code;
  114. row.puUnitName = name;
  115. });
  116. // task 3
  117. currency("人民币").then((res) => {
  118. const { id, code, name } = res;
  119. row.currency = id;
  120. row.currencyCode = code;
  121. row.currencyName = name;
  122. });
  123. // task 4
  124. fetchExist({ puOrg, customer, supplier, materialCode }).then((res) => {
  125. const { recentlyPrice, isApprovalFirst, isPriceAdjustment } = res;
  126. row.recentlyPrice = recentlyPrice;
  127. if (isApprovalFirst) {
  128. row.isApprovalFirst = isApprovalFirst == 0 ? "Y" : "N";
  129. }
  130. if (isPriceAdjustment) {
  131. row.isPriceAdjustment = isPriceAdjustment == 0 ? "Y" : "N";
  132. }
  133. });
  134. },
  135. //
  136. async fetchItem(prop) {
  137. try {
  138. // try
  139. this.loading = true;
  140. const { tabName, TabColumns } = this;
  141. const { TableColumns } = TabColumns.find(
  142. ({ item: { key } }) => key === tabName
  143. );
  144. const { code, data } = await ITEM(prop);
  145. if (code === 200) {
  146. this.params = data;
  147. this.params.priceApplyItems = data.priceApplyItems.map((item) => ({
  148. ...this.$init.params(TableColumns),
  149. ...item,
  150. }));
  151. return true;
  152. } else {
  153. return false;
  154. }
  155. } catch (err) {
  156. // catch
  157. console.error(err);
  158. } finally {
  159. // finally
  160. this.loading = false;
  161. }
  162. },
  163. //
  164. async onOpen() {
  165. const {
  166. selectData: [{ id }],
  167. } = this.$props;
  168. this.visible = await this.fetchItem(id);
  169. },
  170. //
  171. async onHide() {
  172. const { TabColumns, TableColumns } = useColumns();
  173. this.visible = false;
  174. this.params = this.$init.params([...TabColumns, ...TableColumns]);
  175. },
  176. //
  177. async onRowAdd(prop) {
  178. const {
  179. $notify,
  180. TabColumns,
  181. params: { puOrgName, supplierName },
  182. } = this;
  183. if (!supplierName) {
  184. return $notify.info("请选择供应商");
  185. }
  186. if (!puOrgName) {
  187. return $notify.info("请选择采购组织");
  188. }
  189. const { TableColumns } = TabColumns.find(
  190. ({ item: { key } }) => key === prop
  191. );
  192. this.params[prop].push({
  193. delFlag: "0",
  194. ...this.$init.params(TableColumns),
  195. });
  196. },
  197. //
  198. async onRowRemove(prop, scope) {
  199. const {
  200. row: { $index },
  201. } = scope;
  202. this.params[prop] = this.params[prop].map((item, index) => ({
  203. ...item,
  204. delFlag: index === $index ? "2" : item.delFlag,
  205. }));
  206. },
  207. //
  208. async useSubmit(prop) {
  209. this.$refs[prop].validate(async (valid) => {
  210. console.log(this.params);
  211. if (valid) {
  212. try {
  213. this.loading = true;
  214. this.params.priceApplyItems = this.params.priceApplyItems.filter(
  215. (item) => item.materialName
  216. );
  217. const { msg, code } = await SAVE(this.params);
  218. if (code === 200) {
  219. this.onHide();
  220. this.$emit("success");
  221. this.$notify.success(msg);
  222. }
  223. } catch (err) {
  224. // catch
  225. console.error(err);
  226. } finally {
  227. // finally
  228. this.loading = false;
  229. }
  230. } else {
  231. return false;
  232. }
  233. });
  234. },
  235. },
  236. created() {},
  237. mounted() {},
  238. destroyed() {},
  239. };
  240. </script>
  241. <template>
  242. <el-button
  243. v-bind="$attrs"
  244. v-on="$listeners"
  245. :disabled="disabled"
  246. @click="onOpen"
  247. >
  248. {{ title }}
  249. <el-drawer
  250. :show-close="false"
  251. :size="width"
  252. :title="title"
  253. :visible.sync="visible"
  254. append-to-body
  255. destroy-on-close
  256. @close="onHide"
  257. >
  258. <template slot="title">
  259. <span>{{ title }}</span>
  260. <el-button
  261. type="primary"
  262. :size="$attrs.size"
  263. :loading="loading"
  264. @click="useSubmit('superForm')"
  265. >
  266. 确 认
  267. </el-button>
  268. <el-button :size="$attrs.size" :loading="loading" @click="onHide">
  269. 取 消
  270. </el-button>
  271. </template>
  272. <el-super-form
  273. v-model="params"
  274. :dict="dict"
  275. :rules="rules"
  276. :size="$attrs.size"
  277. :columns="TableColumns"
  278. ref="superForm"
  279. label-width="auto"
  280. label-position="right"
  281. style="padding: 20px"
  282. >
  283. <template slot="puOrgName" slot-scope="scope">
  284. <component
  285. v-bind="scope.attr"
  286. v-model="scope.row[scope.item.key]"
  287. :size="$attrs.size"
  288. :source.sync="scope.row"
  289. @change="changePuOrgName({ ...scope, select: $event })"
  290. >
  291. </component
  292. ></template>
  293. </el-super-form>
  294. <el-tabs v-model="tabName" style="padding: 0 20px 20px">
  295. <el-tab-pane
  296. v-for="({ item, TableColumns: columns }, index) in TabColumns"
  297. :key="index"
  298. :label="item.title"
  299. :name="item.key"
  300. lazy
  301. >
  302. <el-super-table
  303. v-model="priceApply[item.key]"
  304. :dict="dict"
  305. :ref="tabName"
  306. :columns="columns"
  307. :size="$attrs.size"
  308. style="padding: 20px 10px;height: 400px;"
  309. >
  310. <template slot="materialName" slot-scope="scope">
  311. <component
  312. v-bind="scope.attr"
  313. v-model="scope.row[scope.item.key]"
  314. :size="$attrs.size"
  315. :source.sync="scope.row"
  316. @change="changeMaterialName(scope)"
  317. >
  318. </component>
  319. </template>
  320. <el-table-column fixed="right" label="操作" width="100">
  321. <template slot="header" slot-scope="scope">
  322. <el-button :size="$attrs.size" @click="onRowAdd(tabName)">
  323. 新增
  324. </el-button>
  325. </template>
  326. <template slot-scope="scope">
  327. <el-button
  328. :size="$attrs.size"
  329. @click.native.prevent="onRowRemove(tabName, scope)"
  330. >
  331. 删除
  332. </el-button>
  333. </template>
  334. </el-table-column>
  335. </el-super-table>
  336. </el-tab-pane>
  337. </el-tabs>
  338. </el-drawer>
  339. </el-button>
  340. </template>
  341. <style scoped>
  342. ::v-deep .el-table__row.is-hidden {
  343. display: none;
  344. }
  345. </style>