contractDetail.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // 合同模板-新增合同
  2. // 2019年6月20日 00:44:21 by jlx
  3. import {
  4. getTypeList
  5. } from '@/model/procurement/spare'
  6. import {
  7. createContract,
  8. updateContract,
  9. getContractDetail
  10. } from '@/model/procurement/basic'
  11. import Tinymce from '@/components/Tinymce'
  12. import MDinput from '@/components/MDinput'
  13. import Sticky from '@/components/Sticky' // 粘性header组件
  14. import { EventBus } from 'base-core-lib'
  15. export default {
  16. components: {
  17. Tinymce,
  18. MDinput,
  19. Sticky
  20. },
  21. data () {
  22. return {
  23. // 合同啊表单数据
  24. contractForm: {
  25. compId: sessionStorage.getItem('ws-pf_compId'),
  26. // 合同ID
  27. contractId: '',
  28. // 合同模板名称
  29. contractTitle: '',
  30. // 合同类型
  31. contractTypeId: '',
  32. // 合同内容
  33. contractContent: ''
  34. },
  35. // 合同模板类型数据
  36. contractList: [],
  37. // 表单验证
  38. rulesVendor: {
  39. contractTypeId: [{
  40. required: true
  41. }],
  42. contractTitle: [{
  43. required: true
  44. }]
  45. },
  46. }
  47. },
  48. created () {
  49. this.contractId = this.$route.query.contractId
  50. // 根据获取合同模板
  51. this.getSelectContract()
  52. if (this.contractId.length > 0) {
  53. this.getContractByContractId()
  54. }
  55. },
  56. computed: {
  57. getLanguage () {
  58. return this.$store.getters.language
  59. }
  60. },
  61. methods: {
  62. // 根据获取合同模板
  63. getSelectContract () {
  64. // 获取数据
  65. getTypeList({
  66. compId: sessionStorage.getItem('ws-pf_compId'),
  67. constCode: 'CONTRACT_INQUIRY'
  68. }).toPromise().then(response => {
  69. this.contractList = response
  70. })
  71. },
  72. // 根据合同ID获取合同明细信息
  73. getContractByContractId () {
  74. getContractDetail({
  75. contractId: this.contractId
  76. }).toPromise().then(response => {
  77. this.contractForm = response
  78. })
  79. },
  80. // 保存
  81. save () {
  82. // 新增
  83. this.$refs['dataForm'].validate(valid => {
  84. if (valid) {
  85. if (this.contractForm.contractContent.length == 0) {
  86. EventBus.$emit('error', this.$t('message.message3'))
  87. return
  88. }
  89. // ([\u4e00-\u9fa50-9 -~A-Za-z]+)<\/span>
  90. this.contractForm.contractContent = this.contractForm.contractContent.replace(/<span style="color: #ff0000;">([\u4e00-\u9fa50-9 A-Za-z]+)</g, `<input type="text" placeholder="请输入" onblur="this.setAttribute('value', this.value)" /><`)
  91. if (this.contractForm.contractId.length == 0) {
  92. createContract(this.contractForm).toPromise().then(response => {
  93. EventBus.$emit('success', this.$t('message.message1'))
  94. this.back()
  95. })
  96. } else {
  97. updateContract(this.contractForm).toPromise().then(response => {
  98. EventBus.$emit('success', this.$t('message.message1'))
  99. this.back()
  100. })
  101. }
  102. } else {
  103. EventBus.$emit('error', this.$t('showMessage.asterisksArereQuired'))
  104. }
  105. })
  106. },
  107. // 返回列表页面
  108. back () {
  109. this.$router.go(-1) // 返回上一层
  110. }
  111. }
  112. }