index.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <script>
  2. import useColumns from "./columns";
  3. import { ADD, CODE, LINKAGREEMENT } from "@/api/business/purchase/contract";
  4. import { tax, currency } from "@/components/popover-select-v2/fetch";
  5. export default {
  6. name: "AddFormModel",
  7. props: {
  8. selectData: {
  9. type: [Array],
  10. require: true,
  11. },
  12. dict: {
  13. type: Object,
  14. require: true,
  15. },
  16. title: {
  17. type: String,
  18. },
  19. },
  20. components: {
  21. ElSuperForm: () => import("@/components/super-form/index.vue"),
  22. ElSuperTable: () => import("@/components/super-table/index.vue"),
  23. ElPopoverSelectV2: () => import("@/components/popover-select-v2/index.vue"),
  24. },
  25. data() {
  26. const {
  27. TabColumns,
  28. TableColumns,
  29. TabColumns: [
  30. {
  31. item: { key: tabName },
  32. },
  33. ],
  34. } = useColumns();
  35. const rules = this.$init.rules([...TabColumns, ...TableColumns]);
  36. console.log(rules,'rules------------');
  37. const params = this.$init.params([...TabColumns, ...TableColumns]);
  38. return {
  39. loading: false,
  40. loadingText: "",
  41. rules: rules,
  42. params: params,
  43. tabName: tabName,
  44. TabColumns: TabColumns,
  45. TableColumns: TableColumns,
  46. };
  47. },
  48. computed: {},
  49. watch: {
  50. "params.isRebate": {
  51. handler: function (newValue) {
  52. if (newValue === "Y") {
  53. this.rules.rebatePolicy = [
  54. { required: true, message: "返利政策不能为空", trigger: "change" },
  55. ];
  56. } else {
  57. this.rules.rebatePolicy = null;
  58. }
  59. },
  60. immediate: true,
  61. },
  62. "params.isTarget": {
  63. handler: function (newValue) {
  64. if (newValue === "Y") {
  65. this.rules.contractTarget = [
  66. { required: true, message: "合同指标不能为空", trigger: "change" },
  67. ];
  68. } else {
  69. this.rules.contractTarget = null;
  70. }
  71. },
  72. immediate: true,
  73. },
  74. "params.effectiveDate": {
  75. handler: function (newValue) {
  76. if (!newValue) {
  77. this.params.endDate = null;
  78. }
  79. this.rules.endDate = [
  80. {
  81. validator: (rule, value, callback) => {
  82. if (!newValue) {
  83. callback(new Error("合同生效日期不能为空"));
  84. } else if (!value) {
  85. callback(new Error("合同失效日期不能为空"));
  86. } else if (
  87. new Date(value).getTime() <
  88. new Date(newValue).getTime() + 24 * 1000 * 3600
  89. ) {
  90. callback(new Error("合同失效日期必须大于合同生效日期!"));
  91. } else {
  92. callback();
  93. }
  94. },
  95. trigger: "change",
  96. },
  97. ];
  98. },
  99. immediate: true,
  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. console.log('合同参数', prop)
  113. const {
  114. selectData: { code },
  115. } = prop;
  116. const { data } = await LINKAGREEMENT(code);
  117. this.tabName = "contractAgreementList";
  118. this.params.contractAgreementList.push({
  119. ...this.getTabTableColumnParams("contractAgreementList"),
  120. ...data,
  121. });
  122. },
  123. //
  124. async changeMaterialName(prop) {
  125. const { row } = prop;
  126. const { rateCode } = row;
  127. try {
  128. // try
  129. this.loading = true;
  130. const { ntaxrate } = await tax(rateCode);
  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 open() {
  142. try {
  143. //
  144. this.loading = true;
  145. this.loadingText = "获取合同编码中";
  146. //
  147. const {
  148. user: {
  149. deptId: puDept,
  150. deptName: puDeptName,
  151. name: buyer,
  152. nickName: buyerName,
  153. orgId: puOrg,
  154. orgName: puOrgName,
  155. },
  156. } = this.$store.state;
  157. // this.params.puOrg = puOrg;
  158. // this.params.puOrgName = puOrgName;
  159. this.params.buyer = buyer;
  160. this.params.buyerName = buyerName;
  161. this.params.puDept = puDept;
  162. this.params.puDeptName = puDeptName;
  163. //
  164. const { title } = this.$props;
  165. this.params.source = title === "新增" ? "自制" : "期初补录";
  166. //
  167. const { id, code, name } = await currency("人民币");
  168. this.params.currency = id;
  169. this.params.currencyCode = code;
  170. this.params.currencyName = name;
  171. //
  172. this.params.code = await CODE();
  173. //
  174. this.loading = false;
  175. } catch (error) {
  176. this.loading = false;
  177. this.$notify.error(error);
  178. }
  179. },
  180. //
  181. async hide() {
  182. this.$emit("close");
  183. },
  184. //
  185. async useRowAdd(prop) {
  186. this.params[prop].push(this.getTabTableColumnParams(prop));
  187. },
  188. //
  189. async useRowRemove(prop, scope) {
  190. const { $index } = scope;
  191. this.params[prop].splice($index, 1);
  192. },
  193. //
  194. async useSubmit(prop) {
  195. this.$refs[prop].validate(async (valid) => {
  196. if (valid) {
  197. try {
  198. // try
  199. this.loading = true;
  200. this.loadingText = "提交合同中";
  201. const params = { ...this.params };
  202. const { msg, code } = await ADD(params);
  203. if (code === 200) {
  204. this.hide();
  205. this.$emit("submit-success");
  206. this.$notify.success(msg);
  207. }
  208. } catch (err) {
  209. // catch
  210. console.error(err);
  211. } finally {
  212. // finally
  213. this.loading = false;
  214. }
  215. } else {
  216. return false;
  217. }
  218. });
  219. },
  220. },
  221. created() {
  222. this.open();
  223. },
  224. mounted() {},
  225. destroyed() {},
  226. };
  227. </script>
  228. <template>
  229. <div
  230. v-loading="loading"
  231. :element-loading-text="loadingText"
  232. style="height: 100vh; display: flex; flex-direction: column"
  233. >
  234. <div
  235. style="
  236. height: 50px;
  237. display: flex;
  238. justify-content: space-between;
  239. align-items: center;
  240. padding: 0 18px;
  241. "
  242. >
  243. <h4 class="m-0" style="font-weight: 500; flex: 1">{{ title }}</h4>
  244. <el-button
  245. type="primary"
  246. :size="$attrs.size"
  247. :loading="loading"
  248. @click="useSubmit('superForm')"
  249. >确 认</el-button
  250. >
  251. <el-button :size="$attrs.size" :loading="loading" @click="hide"
  252. >取 消</el-button
  253. >
  254. </div>
  255. <div v-if="params.code" style="flex: 1; overflow-y: auto">
  256. <el-super-form
  257. v-model="params"
  258. :dict="dict"
  259. :rules="rules"
  260. :size="$attrs.size"
  261. :columns="TableColumns"
  262. ref="superForm"
  263. label-width="auto"
  264. label-position="right"
  265. style="padding: 18px"
  266. >
  267. <template slot="paymentAgreement" slot-scope="scope">
  268. <component
  269. v-bind="scope.attr"
  270. v-model="scope.row[scope.item.key]"
  271. :size="$attrs.size"
  272. :source.sync="scope.row"
  273. @change="changePaymentAgreement({ ...scope, selectData: $event })"
  274. >
  275. </component>
  276. </template>
  277. </el-super-form>
  278. </div>
  279. <el-tabs v-if="params.code" v-model="tabName" style="margin: 0 18px 18px">
  280. <el-tab-pane
  281. v-for="{ item, TableColumns: columns } in TabColumns"
  282. :key="item.key"
  283. :label="item.title"
  284. :name="item.key"
  285. lazy
  286. >
  287. <div style="height: 25vh; display: flex">
  288. <el-super-table
  289. v-model="params[item.key]"
  290. :dict="dict"
  291. :ref="tabName"
  292. :columns="columns"
  293. :size="$attrs.size"
  294. index
  295. >
  296. <template slot="materialName" slot-scope="scope">
  297. <component
  298. v-bind="scope.attr"
  299. v-model="scope.row[scope.item.key]"
  300. :size="$attrs.size"
  301. :source.sync="scope.row"
  302. @change="changeMaterialName(scope)"
  303. >
  304. </component>
  305. </template>
  306. <el-table-column fixed="right" label="操作" width="75">
  307. <template slot="header" slot-scope="scope">
  308. <el-button
  309. type="text"
  310. :size="$attrs.size"
  311. @click="useRowAdd(tabName)"
  312. >增行
  313. </el-button>
  314. </template>
  315. <template slot-scope="scope">
  316. <el-button
  317. type="text"
  318. :size="$attrs.size"
  319. @click.native.prevent="useRowRemove(tabName, scope)"
  320. >删行
  321. </el-button>
  322. </template>
  323. </el-table-column>
  324. </el-super-table>
  325. </div>
  326. </el-tab-pane>
  327. </el-tabs>
  328. </div>
  329. </template>