index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <script>
  2. import Column from "./column";
  3. import useData from "../hooks/data";
  4. import useWatch from "../hooks/watch";
  5. import useMethods from "../hooks/function";
  6. import { initParams } from "@/utils/init.js";
  7. import { ITEM, SAVE } from "@/api/business/purchase/apply";
  8. const { watchPuOrgName } = useWatch();
  9. export default {
  10. name: "AddDrawer",
  11. components: {
  12. ElComputedInput: () => import("@/components/computed-input/index.vue"),
  13. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  14. },
  15. data() {
  16. return {
  17. title: "新 增",
  18. ...useData(Column),
  19. };
  20. },
  21. computed: {
  22. $dicts: {
  23. get: function () {
  24. return this.$parent.$parent.$dicts;
  25. },
  26. },
  27. },
  28. watch: {
  29. "params.puOrgName": watchPuOrgName(),
  30. },
  31. methods: {
  32. //
  33. async fetchRefer(prop, type, source) {
  34. const { fetchTax, fetchUnit, fetchExist } = useMethods();
  35. if (type === "MATERIAL_PARAM") {
  36. const { puOrg, customer, supplier } = this.params;
  37. const { rateCode, unitIdName, code: materialCode } = prop;
  38. // task 1
  39. fetchTax(rateCode).then(({ ntaxrate }) => {
  40. source.tax =
  41. ntaxrate === "0E-8" ? "0.000000" : (ntaxrate * 1).toFixed(6);
  42. });
  43. // task 2
  44. fetchUnit(unitIdName).then(({ id, code, name }) => {
  45. source.unit = id;
  46. source.unitCode = code;
  47. source.unitName = name;
  48. source.puUnit = id;
  49. source.puUnitCode = code;
  50. source.puUnitName = name;
  51. });
  52. // task 3
  53. fetchExist({ puOrg, customer, supplier, materialCode }).then(
  54. ({ recentlyPrice, isApprovalFirst, isPriceAdjustment }) => {
  55. source.recentlyPrice = recentlyPrice;
  56. source.isApprovalFirst = isApprovalFirst;
  57. source.isPriceAdjustment = isPriceAdjustment;
  58. }
  59. );
  60. }
  61. },
  62. //
  63. async fetchItem(prop) {
  64. try {
  65. // try
  66. this.loading = true;
  67. const { code, data } = await ITEM(prop);
  68. if (code === 200) {
  69. this.params = data;
  70. this.params.createBy = null;
  71. this.params.priceCode = null;
  72. this.params.createByName = null;
  73. this.params.effectiveDate = null;
  74. this.params.priceApplyItems = this.params.priceApplyItems.map(
  75. (item) => ({ ...item, createByName: null, updateByName: null })
  76. );
  77. this.params.priceApplyOrgs = this.params.priceApplyOrgs.map(
  78. (item) => ({ ...item, createByName: null, updateByName: null })
  79. );
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. } catch (err) {
  85. // catch
  86. console.error(err);
  87. } finally {
  88. // finally
  89. this.loading = false;
  90. }
  91. },
  92. //
  93. async open(prop) {
  94. this.visible = prop ? await this.fetchItem(prop) : true;
  95. },
  96. //
  97. async hide() {
  98. this.visible = false;
  99. this.params = this.resetParams();
  100. this.tabName = this.tabColumns[0].key;
  101. },
  102. //
  103. async useRowAdd(prop) {
  104. const {
  105. $notify,
  106. tabColumns,
  107. params: { puOrgName, supplierName },
  108. } = this;
  109. if (!supplierName) {
  110. return $notify.info("请选择供应商");
  111. }
  112. if (!puOrgName) {
  113. return $notify.info("请选择采购组织");
  114. }
  115. const { tableColumns } = tabColumns.find(
  116. (element) => element.key === prop
  117. );
  118. this.params[prop].push(initParams(tableColumns));
  119. },
  120. //
  121. async useRowRemove(prop, scope) {
  122. const { $index } = scope;
  123. this.params[prop].splice($index, 1);
  124. },
  125. //
  126. async useSubmit(prop) {
  127. this.$refs[prop].validate(async (valid) => {
  128. if (valid) {
  129. try {
  130. // try
  131. const {
  132. priceApplyOrgs: _priceApplyOrgs,
  133. priceApplyItems: _priceApplyItems,
  134. } = this.params;
  135. const id = undefined;
  136. const priceApplyOrgs = _priceApplyOrgs.map((item) => ({
  137. ...item,
  138. id: undefined,
  139. applyId: undefined,
  140. }));
  141. const priceApplyItems = _priceApplyItems.map((item) => ({
  142. ...item,
  143. id: undefined,
  144. applyId: undefined,
  145. }));
  146. const params = {
  147. ...this.params,
  148. id,
  149. priceApplyOrgs,
  150. priceApplyItems,
  151. };
  152. const { msg, code } = await SAVE(params);
  153. if (code === 200) {
  154. this.hide();
  155. this.$emit("success");
  156. this.$notify.success(msg);
  157. }
  158. } catch (err) {
  159. // catch
  160. console.error(err);
  161. } finally {
  162. // finally
  163. this.loading = false;
  164. }
  165. } else {
  166. return false;
  167. }
  168. });
  169. },
  170. },
  171. created() {},
  172. mounted() {},
  173. destroyed() {},
  174. };
  175. </script>
  176. <template>
  177. <el-drawer
  178. :size="width"
  179. :title="title"
  180. :show-close="false"
  181. :visible.sync="visible"
  182. >
  183. <template slot="title">
  184. <span>{{ title }}</span>
  185. <span>
  186. <el-button
  187. :size="size"
  188. circle
  189. icon="el-icon-check"
  190. @click="useSubmit('ruleForm')"
  191. >
  192. </el-button>
  193. <el-button
  194. :size="size"
  195. circle
  196. type="danger"
  197. icon="el-icon-close"
  198. @click="hide"
  199. ></el-button>
  200. </span>
  201. </template>
  202. <el-form
  203. ref="ruleForm"
  204. v-loading="loading"
  205. :size="size"
  206. :rules="rules"
  207. :model="params"
  208. label-width="auto"
  209. label-position="right"
  210. style="padding: 10px"
  211. >
  212. <el-row :gutter="20" style="display: flex; flex-wrap: wrap">
  213. <el-col
  214. v-for="column in tableColumns"
  215. :key="column.item.title"
  216. :span="column.item.span || 8"
  217. >
  218. <el-form-item
  219. :prop="column.item.key"
  220. :label="column.item.title"
  221. :require="column.item.require"
  222. >
  223. <component
  224. v-bind="column.attr"
  225. v-model="params[column.item.key]"
  226. :source.sync="params"
  227. :is="column.attr.component"
  228. style="width: 100%"
  229. >
  230. <template v-if="column.attr.dictName">
  231. <el-option
  232. v-for="item in $dicts[column.attr.dictName]"
  233. :key="item.value"
  234. :label="item.label"
  235. :value="item.value"
  236. >
  237. </el-option>
  238. </template>
  239. </component>
  240. </el-form-item>
  241. </el-col>
  242. <el-col :span="24">
  243. <el-form-item label-width="0">
  244. <el-tabs v-model="tabName">
  245. <el-tab-pane
  246. v-for="(column, index) in tabColumns"
  247. :key="index"
  248. :label="column.title"
  249. :name="column.key"
  250. lazy
  251. >
  252. <el-table :size="size" :data="params[column.key]">
  253. <el-table-column label="序号">
  254. <template slot-scope="scope">
  255. {{ scope.$index + 1 }}
  256. </template>
  257. </el-table-column>
  258. <el-table-column
  259. v-for="(cColumn, cIndex) in column.tableColumns"
  260. :key="cIndex"
  261. :prop="cColumn.item.key"
  262. :label="cColumn.item.title"
  263. :width="cColumn.item.width || 250"
  264. show-overflow-tooltip
  265. >
  266. <template slot-scope="scope">
  267. <component
  268. v-if="cColumn.attr.component"
  269. v-bind="cColumn.attr"
  270. v-model="scope.row[cColumn.item.key]"
  271. :source.sync="scope.row"
  272. :is="cColumn.attr.component"
  273. @change="fetchRefer"
  274. style="width: 100%"
  275. >
  276. <template v-if="cColumn.attr.dictName">
  277. <el-option
  278. v-for="item in $dicts[cColumn.attr.dictName]"
  279. :key="item.value"
  280. :label="item.label"
  281. :value="item.value"
  282. >
  283. </el-option>
  284. </template>
  285. </component>
  286. <span v-else> {{ scope.row[cColumn.item.key] }}</span>
  287. </template>
  288. </el-table-column>
  289. <el-table-column fixed="right" label="操作" width="100">
  290. <template slot="header" slot-scope="scope">
  291. <el-button
  292. circle
  293. icon="el-icon-plus"
  294. :size="size"
  295. @click="useRowAdd(tabName)"
  296. >
  297. </el-button>
  298. </template>
  299. <template slot-scope="scope">
  300. <el-button
  301. circle
  302. icon="el-icon-minus"
  303. :size="size"
  304. @click.native.prevent="useRowRemove(tabName, scope)"
  305. >
  306. </el-button>
  307. </template>
  308. </el-table-column>
  309. </el-table>
  310. </el-tab-pane>
  311. </el-tabs>
  312. </el-form-item>
  313. </el-col>
  314. </el-row>
  315. </el-form>
  316. </el-drawer>
  317. </template>