create.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view class="uni-app">
  3. <view class="status-bar" />
  4. <view class="main-container">
  5. <wk-nav-bar :title="navTitle">
  6. <!-- #ifndef MP-WEIXIN -->
  7. <button class="button white-btn" @click="handleSave">
  8. 保存
  9. </button>
  10. <!-- #endif -->
  11. </wk-nav-bar>
  12. <view class="container">
  13. <view class="scroll-content">
  14. <wk-form
  15. ref="form"
  16. :fields="fieldArr"
  17. :batch-id="batchId"
  18. @change="handleValueChange" />
  19. <view class="empty-box" />
  20. </view>
  21. </view>
  22. <!-- #ifdef MP-WEIXIN -->
  23. <view class="footer-btn-group">
  24. <button class="button" @click="handleSave">
  25. 保存
  26. </button>
  27. </view>
  28. <!-- #endif -->
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import {
  34. QueryFieldList,
  35. AddCustomer,
  36. UpdateCustomer
  37. } from 'API/crm/customer'
  38. import CreateMixins from '../mixins/create.js'
  39. export default {
  40. name: 'CreateCustomer',
  41. mixins: [CreateMixins],
  42. data() {
  43. return {
  44. moduleType: 'customer',
  45. }
  46. },
  47. onLoad() {
  48. this.getFieldList()
  49. },
  50. methods: {
  51. getFieldList() {
  52. const params = { type: 1 }
  53. if (this.id) params.id = this.id
  54. QueryFieldList(params)
  55. .then(res => {
  56. res.forEach(field => {
  57. // 自动编号为非必填
  58. if (field.autoGeneNumber === 1) {
  59. field.isNull = 0
  60. }
  61. if (!this.$isEmpty(field.authLevel)) {
  62. // 判断字段权限,如果没有权限则直接禁止修改
  63. field.disabled = this.getDisabledStatusByAuth(field)
  64. if (field.disabled) {
  65. if (field.sys_config) {
  66. field.sys_config.disabledMsg = ''
  67. }
  68. }
  69. }
  70. field.value = this.mixinsFormatFieldValue(field)
  71. })
  72. this.fieldArr = res
  73. this.setForm()
  74. })
  75. .catch(() => {
  76. })
  77. },
  78. /**
  79. * 表单值发生改变
  80. * @param {Object} data
  81. */
  82. handleValueChange(data) {
  83. // console.log('value change: ', data)
  84. },
  85. /**
  86. * 保存
  87. */
  88. handleSave() {
  89. this.loading = true
  90. this.$refs.form.getForm().then(async form => {
  91. // if (this.id == form.entity.superiorCustomerId) {
  92. // this.$toast('上级客户不能为当前客户')
  93. // this.loading = false
  94. // return
  95. // }
  96. this.baseFormatSaveData(form)
  97. console.log('save: ', form)
  98. // this.loading = false
  99. // return
  100. const request = this.id ? UpdateCustomer : AddCustomer
  101. request(form).then(() => {
  102. this.$toast(this.id ? '修改成功' : '添加成功')
  103. this.$refreshAndToPrev(this)
  104. }).catch(() => {
  105. this.loading = false
  106. })
  107. }).catch(() => {
  108. this.loading = false
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style scoped lang="scss">
  115. @import '../style/create.scss';
  116. </style>