index.vue 8.3 KB

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