erpBaseModal.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. :width="560"
  9. :footer="null"
  10. @cancel="cancel"
  11. >
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="chooseCustom-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <a-row :gutter="15">
  22. <a-col :span="20">
  23. <a-form-model-item label="业务单号" prop="bizNo">
  24. <a-input
  25. id="base-bizNo"
  26. :disabled="bizSn"
  27. v-model.trim="form.bizNo"
  28. @change="fetchUser"
  29. allowClear
  30. placeholder="请输入业务单号"/>
  31. </a-form-model-item>
  32. </a-col>
  33. </a-row>
  34. <a-row :gutter="15">
  35. <a-col :span="20">
  36. <a-form-model-item label="客户名称" prop="dealerSn">
  37. {{ dealerData&&dealerData.dealerName||'--' }}
  38. </a-form-model-item>
  39. </a-col>
  40. </a-row>
  41. <a-form-model-item :wrapper-col="{ span: 12, offset: 6 }" style="text-align: center;">
  42. <a-button @click="cancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
  43. <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">保存</a-button>
  44. </a-form-model-item>
  45. </a-form-model>
  46. </a-spin>
  47. </a-modal>
  48. </template>
  49. <script>
  50. import { commonMixin } from '@/utils/mixin'
  51. import { VSelect } from '@/components'
  52. import debounce from 'lodash/debounce'
  53. import warehouse from '@/views/common/chooseWarehouse.js'
  54. import { bizRemoveConfigCreate, bizRemoveConfigModify, bizRemoveConfigDetail, salesReturnDetailByNo } from '@/api/bizRemove'
  55. export default {
  56. name: 'ErpBaseModal',
  57. mixins: [commonMixin],
  58. components: { VSelect, warehouse },
  59. props: {
  60. show: [Boolean]
  61. },
  62. data () {
  63. this.lastFetchId = 0
  64. this.fetchUser = debounce(this.fetchUser, 800)
  65. return {
  66. opened: this.show,
  67. spinning: false,
  68. title: '新增配置',
  69. confirmLoading: false,
  70. formItemLayout: {
  71. labelCol: { span: 8 },
  72. wrapperCol: { span: 16 }
  73. },
  74. form: {
  75. bizNo: '',
  76. dealerSn: undefined,
  77. configType: 'SALES_RETURN_SYNC',
  78. bizSn: undefined, // bizsn
  79. salesReturnSyncErp: '1'
  80. },
  81. rules: {
  82. bizNo: [{ required: true, message: '请输入业务单号', trigger: ['change', 'blur'] }],
  83. dealerSn: [{ required: true, message: '请选择客户', trigger: ['change', 'blur'] }],
  84. salesReturnSyncErp: [{ required: true, message: '请选择', trigger: ['change', 'blur'] }]
  85. },
  86. fetching: false,
  87. dealerData: null,
  88. bizSn: undefined
  89. }
  90. },
  91. methods: {
  92. fetchUser () {
  93. if (!this.form.bizNo) return
  94. this.lastFetchId += 1
  95. const fetchId = this.lastFetchId
  96. this.dealerData = null
  97. this.spinning = true
  98. this.fetching = true
  99. salesReturnDetailByNo({ bizNo: this.form.bizNo, configType: 'SALES_RETURN_SYNC' }).then(res => {
  100. if (fetchId !== this.lastFetchId) {
  101. return
  102. }
  103. if (res.data) {
  104. this.dealerData = res.data
  105. this.form.dealerSn = res.data.dealerSn
  106. this.form.bizSn = res.data.bizSn
  107. } else {
  108. this.dealerData = null
  109. this.form.dealerSn = undefined
  110. this.form.bizSn = undefined
  111. }
  112. this.fetching = false
  113. this.spinning = false
  114. })
  115. },
  116. // 保存
  117. handleSubmit (e) {
  118. e.preventDefault()
  119. const _this = this
  120. this.$refs.ruleForm.validate(valid => {
  121. if (valid) {
  122. // 保存
  123. _this.salesSaveFun()
  124. } else {
  125. return false
  126. }
  127. })
  128. },
  129. // 新建业务单
  130. salesSaveFun () {
  131. const _this = this
  132. const form = this.form
  133. const funs = !this.bizSn ? bizRemoveConfigCreate : bizRemoveConfigModify
  134. _this.spinning = true
  135. funs(form).then(res => {
  136. if (res.status == 200) {
  137. _this.$message.success(res.message)
  138. _this.$emit('ok', res.data)
  139. _this.cancel()
  140. }
  141. _this.spinning = false
  142. })
  143. },
  144. cancel () {
  145. this.opened = false
  146. this.form = {
  147. configType: 'SALES_RETURN_SYNC',
  148. bizNo: '',
  149. dealerSn: undefined,
  150. bizSn: undefined, // bizsn
  151. salesReturnSyncErp: '1'
  152. }
  153. this.bizSn = undefined
  154. this.dealerData = null
  155. this.$refs.ruleForm.resetFields()
  156. this.$emit('cancel')
  157. },
  158. getDetail () {
  159. bizRemoveConfigDetail({ bizSn: this.bizSn, configType: 'SALES_RETURN_SYNC' }).then(res => {
  160. const { bizSn, bizNo, dealerSn, dealerName } = res.data
  161. this.dealerData = { dealerName: dealerName }
  162. this.form = Object.assign(this.form, {
  163. bizNo: bizNo,
  164. dealerSn: dealerSn,
  165. bizSn: bizSn,
  166. salesReturnSyncErp: '1'
  167. })
  168. })
  169. },
  170. edit (row) {
  171. if (row && row.bizSn) {
  172. this.title = '编辑配置'
  173. this.bizSn = row.bizSn
  174. this.getDetail()
  175. } else {
  176. this.title = '新增配置'
  177. this.bizSn = undefined
  178. }
  179. }
  180. },
  181. watch: {
  182. show (newValue, oldValue) {
  183. this.opened = newValue
  184. }
  185. }
  186. }
  187. </script>