create.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. AddProduct,
  36. UpdateProduct
  37. } from 'API/crm/product'
  38. import CreateMixins from '../mixins/create.js'
  39. export default {
  40. name: 'CreateProduct',
  41. mixins: [CreateMixins],
  42. data() {
  43. return {
  44. moduleType: 'product',
  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. // 产品上下架
  71. if (field.fieldName === 'status') {
  72. field.sys_config = {
  73. optionsConfig: {
  74. labelField: 'name',
  75. valueField: 'value'
  76. }
  77. }
  78. }
  79. if (
  80. this.id &&
  81. field.fieldName === 'status' &&
  82. field.value
  83. ) {
  84. // 产品下上下架状态
  85. field.value = field.setting.filter(o => o.value == field.value)
  86. } else {
  87. field.value = this.mixinsFormatFieldValue(field)
  88. }
  89. })
  90. this.fieldArr = res
  91. this.setForm()
  92. })
  93. .catch(() => {
  94. })
  95. },
  96. /**
  97. * 表单值发生改变
  98. * @param {Object} data
  99. */
  100. handleValueChange(data) {
  101. // console.log('value change: ', data)
  102. },
  103. /**
  104. * 保存
  105. */
  106. handleSave() {
  107. this.loading = true
  108. this.$refs.form.getForm().then(async form => {
  109. this.baseFormatSaveData(form)
  110. console.log('save: ', form)
  111. // this.loading = false
  112. // return
  113. const request = this.id ? UpdateProduct : AddProduct
  114. request(form).then(() => {
  115. this.$toast(this.id ? '修改成功' : '添加成功')
  116. this.$refreshAndToPrev(this)
  117. }).catch(() => {
  118. this.loading = false
  119. })
  120. }).catch(() => {
  121. this.loading = false
  122. })
  123. }
  124. }
  125. }
  126. </script>
  127. <style scoped lang="scss">
  128. @import '../style/create.scss';
  129. </style>