index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <script>
  2. import useColumns from "./columns";
  3. import {
  4. EDIT,
  5. ITEM,
  6. TABLE,
  7. ALTERATION,
  8. } from "@/api/business/purchase/contract";
  9. import { tax } from "@/components/popover-select-v2/fetch";
  10. export default {
  11. name: "EditFormModel",
  12. props: {
  13. selectData: {
  14. type: [Array],
  15. require: true,
  16. },
  17. dict: {
  18. type: Object,
  19. require: true,
  20. },
  21. title: {
  22. type: String,
  23. },
  24. },
  25. components: {
  26. ElSuperForm: () => import("@/components/super-form/index.vue"),
  27. ElSuperTable: () => import("@/components/super-table/index.vue"),
  28. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  29. },
  30. data() {
  31. const {
  32. TabColumns,
  33. TableColumns,
  34. TabColumns: [
  35. {
  36. item: { key: tabName },
  37. },
  38. ],
  39. } = useColumns();
  40. const rules = this.$init.rules(TableColumns);
  41. const params = this.$init.params([...TabColumns, ...TableColumns]);
  42. return {
  43. loading: false,
  44. loadingText: "",
  45. rules: rules,
  46. params: params,
  47. tabName: tabName,
  48. TabColumns: TabColumns,
  49. TableColumns: TableColumns,
  50. };
  51. },
  52. computed: {
  53. id: {
  54. get() {
  55. return this.$props.selectData[0].id;
  56. },
  57. set() {},
  58. },
  59. },
  60. watch: {
  61. "params.isRebate": {
  62. handler: function (newValue) {
  63. if (newValue === "Y") {
  64. this.rules.rebatePolicy = [
  65. { required: true, message: "返利政策不能为空", trigger: "change" },
  66. ];
  67. } else {
  68. this.rules.rebatePolicy = null;
  69. }
  70. },
  71. immediate: true,
  72. },
  73. "params.isTarget": {
  74. handler: function (newValue) {
  75. if (newValue === "Y") {
  76. this.rules.contractTarget = [
  77. { required: true, message: "合同指标不能为空", trigger: "change" },
  78. ];
  79. } else {
  80. this.rules.contractTarget = null;
  81. }
  82. },
  83. immediate: true,
  84. },
  85. "params.status":{
  86. handler:function(newValue){
  87. if(newValue === '2'){
  88. // 已审核
  89. this.TableColumns = this.TableColumns.map(({item,attr}) =>{
  90. return {
  91. item:{...item},
  92. attr:{
  93. ...attr,
  94. disabled: item.key !== 'puFile' ? true: false
  95. }
  96. }
  97. })
  98. }
  99. }
  100. }
  101. },
  102. methods: {
  103. //
  104. getTabTableColumnParams(prop) {
  105. const { TableColumns } = this.TabColumns.find(
  106. ({ item: { key } }) => key === prop
  107. );
  108. return this.$init.params(TableColumns);
  109. },
  110. //
  111. async changePaymentAgreement(prop) {
  112. const {
  113. selectData: { code },
  114. } = prop;
  115. const { data } = await LINKAGREEMENT(code);
  116. this.tabName = "contractAgreementList";
  117. this.params.contractAgreementList.push({
  118. ...this.getTabTableColumnParams("contractAgreementList"),
  119. ...data,
  120. });
  121. },
  122. //
  123. async changeMaterialName(prop) {
  124. const { row } = prop;
  125. const { rateCode } = row;
  126. try {
  127. // try
  128. this.loading = true;
  129. const { ntaxrate } = await tax(rateCode);
  130. // row.tax = Number(ntaxrate === "0E-8" ? 0 : ntaxrate);
  131. row.tax = ntaxrate === "0E-8" ? 0 : ntaxrate;
  132. } catch (err) {
  133. // catch
  134. console.error(err);
  135. } finally {
  136. // finally
  137. this.loading = false;
  138. }
  139. },
  140. //
  141. async fetchItem(prop) {
  142. try {
  143. // try
  144. this.loading = true;
  145. this.loadingText = "获取合同中";
  146. const { code, data } = await ITEM(prop);
  147. if (code === 200) {
  148. this.params = data;
  149. } else {
  150. }
  151. } catch (err) {
  152. // catch
  153. console.error(err);
  154. } finally {
  155. // finally
  156. this.loading = false;
  157. }
  158. },
  159. //
  160. async open() {
  161. await this.fetchItem(this.id);
  162. },
  163. //
  164. async hide() {
  165. this.$emit("close");
  166. },
  167. //
  168. async useRowAdd(prop) {
  169. this.params[prop].push(this.getTabTableColumnParams(prop));
  170. },
  171. //
  172. async useRowRemove(prop, scope) {
  173. const { REMOVE } = TABLE;
  174. const {
  175. $index,
  176. row: { id, contractId },
  177. } = scope;
  178. if (id) {
  179. try {
  180. // try
  181. this.loading = true;
  182. this.loadingText = "删除子表中";
  183. const { code } = REMOVE(id, prop);
  184. if (code === 200) {
  185. this.fetchItem(contractId);
  186. }
  187. } catch (err) {
  188. // catch
  189. console.error(err);
  190. } finally {
  191. // finally
  192. this.loading = false;
  193. }
  194. } else {
  195. this.params[prop].splice($index, 1);
  196. }
  197. },
  198. //
  199. async useRowSubmit(prop, scope) {
  200. const {
  201. row,
  202. row: { contractId },
  203. } = scope;
  204. const { id } = this.params;
  205. const { ADD, EDIT } = TABLE;
  206. try {
  207. // try
  208. this.loading = true;
  209. if (contractId) {
  210. this.loadingText = "更新子表中";
  211. await EDIT(row, prop);
  212. } else {
  213. this.loadingText = "新增信息中";
  214. await ADD({ ...row, contractId: id }, prop);
  215. }
  216. } catch (err) {
  217. // catch
  218. console.error(err);
  219. } finally {
  220. // finally
  221. this.fetchItem(id);
  222. this.loading = false;
  223. }
  224. },
  225. //
  226. async useSubmit(prop) {
  227. this.$refs[prop].validate(async (valid) => {
  228. if (valid) {
  229. try {
  230. // try
  231. this.loading = true;
  232. this.loadingText = "更新合同中";
  233. const {
  234. params,
  235. params: { status },
  236. } = this;
  237. const TASK = status === "3" ? ALTERATION : EDIT;
  238. const { msg, code } = await TASK(params);
  239. if (code === 200) {
  240. this.hide();
  241. this.$emit("submit-success");
  242. this.$notify.success(msg);
  243. }
  244. } catch (err) {
  245. // catch
  246. console.error(err);
  247. } finally {
  248. // finally
  249. this.loading = false;
  250. }
  251. } else {
  252. return false;
  253. }
  254. });
  255. },
  256. },
  257. created() {
  258. this.open();
  259. },
  260. mounted() {},
  261. destroyed() {},
  262. };
  263. </script>
  264. <template>
  265. <div
  266. v-loading="loading"
  267. :element-loading-text="loadingText"
  268. style="height: 100vh; display: flex; flex-direction: column"
  269. >
  270. <div
  271. style="
  272. height: 50px;
  273. display: flex;
  274. justify-content: space-between;
  275. align-items: center;
  276. padding: 0 18px;
  277. "
  278. >
  279. <h4 class="m-0" style="font-weight: 500; flex: 1">{{ title }}</h4>
  280. <el-button
  281. type="primary"
  282. :size="$attrs.size"
  283. :loading="loading"
  284. @click="useSubmit('superForm')"
  285. >确 认</el-button
  286. >
  287. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  288. >取 消</el-button
  289. >
  290. </div>
  291. <div v-if="params.code" style="flex: 1; overflow-y: auto">
  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. <template slot="paymentAgreement" slot-scope="scope">
  304. <component
  305. v-bind="scope.attr"
  306. v-model="scope.row[scope.item.key]"
  307. :size="$attrs.size"
  308. :source.sync="scope.row"
  309. @change="changePaymentAgreement({ ...scope, selectData: $event })"
  310. >
  311. </component> </template
  312. ></el-super-form>
  313. </div>
  314. <el-tabs v-if="params.code" v-model="tabName" style="margin: 0 18px 18px">
  315. <el-tab-pane
  316. v-for="{ item, TableColumns: columns } in TabColumns"
  317. :key="item.key"
  318. :label="item.title"
  319. :name="item.key"
  320. lazy
  321. >
  322. <div style="height: 25vh; display: flex">
  323. <el-super-table
  324. v-model="params[item.key]"
  325. :dict="dict"
  326. :ref="tabName"
  327. :columns="columns"
  328. :size="$attrs.size"
  329. index
  330. >
  331. <template slot="materialName" slot-scope="scope">
  332. <component
  333. v-bind="scope.attr"
  334. v-model="scope.row[scope.item.key]"
  335. :size="$attrs.size"
  336. :source.sync="scope.row"
  337. @change="changeMaterialName(scope)"
  338. >
  339. </component>
  340. </template>
  341. <el-table-column fixed="right" label="操作" width="100">
  342. <template slot="header" slot-scope="scope">
  343. <el-button
  344. type="text"
  345. :size="$attrs.size"
  346. @click="useRowAdd(tabName)"
  347. >增行
  348. </el-button>
  349. </template>
  350. <template slot-scope="scope">
  351. <el-button
  352. type="text"
  353. :size="$attrs.size"
  354. @click.native.prevent="useRowSubmit(tabName, scope)"
  355. >更新
  356. </el-button>
  357. <el-button
  358. type="text"
  359. :size="$attrs.size"
  360. @click.native.prevent="useRowRemove(tabName, scope)"
  361. >删行
  362. </el-button>
  363. </template>
  364. </el-table-column>
  365. </el-super-table>
  366. </div>
  367. </el-tab-pane>
  368. </el-tabs>
  369. </div>
  370. </template>