index.vue 9.0 KB

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