basicInfoModal.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <a-modal
  3. centered
  4. class="allocateBill-basicInfo-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="新增"
  8. v-model="isShow"
  9. @cancle="isShow = false"
  10. width="80%">
  11. <a-form-model
  12. id="allocateBill-basicInfo-form"
  13. ref="ruleForm"
  14. :model="form"
  15. :rules="rules"
  16. :label-col="formItemLayout.labelCol"
  17. :wrapper-col="formItemLayout.wrapperCol"
  18. >
  19. <a-form-model-item label="调往对象" prop="targetType">
  20. <a-radio-group v-model="form.targetType" @change="targetTypeChange">
  21. <a-radio v-for="(item,index) in targetTypeList" :key="index" :value="item.code">{{ item.dispName }}</a-radio>
  22. </a-radio-group>
  23. </a-form-model-item>
  24. <a-form-model-item label="调往对象名称" :prop="isDealer ? 'targetSn' : 'targetName'">
  25. <a-select
  26. v-if="isDealer"
  27. show-search
  28. id="allocateBill-basicInfo-dealerName"
  29. v-model="form.targetSn"
  30. placeholder="请选择"
  31. :filter-option="false"
  32. :not-found-content="fetching ? undefined : null"
  33. @search="fetchUser"
  34. @change="handleChange"
  35. >
  36. <a-spin v-if="fetching" slot="notFoundContent" size="small" />
  37. <a-select-option v-for="item in dealerData" :key="item.dealerSn" :value="item.dealerSn">{{ item.dealerName }}</a-select-option>
  38. </a-select>
  39. <a-input v-if="!isDealer" v-model="form.targetName" placeholder="请输入调往对象名称(最多30个字符)" allowClear :maxLength="30" />
  40. </a-form-model-item>
  41. <a-form-model-item label="调拨类型" prop="allocateTypeSn">
  42. <a-select id="allocateBill-basicInfo-allocateTypeSn" v-model="form.allocateTypeSn" placeholder="请选择调拨类型" allowClear >
  43. <a-select-option v-for="item in allocateTypeList" :key="item.allocateTypeSn" :value="item.allocateTypeSn">{{ item.name }}</a-select-option>
  44. </a-select>
  45. </a-form-model-item>
  46. <a-form-model-item label="备注" prop="remark">
  47. <a-textarea id="allocateBill-basicInfo-remark" :maxLength="120" v-model="form.remark" placeholder="请输入备注(最多120个字符)" allowClear />
  48. </a-form-model-item>
  49. </a-form-model>
  50. <div class="btn-cont">
  51. <a-button type="primary" id="allocateBill-basicInfo-modal-save" @click="handleSave">保存</a-button>
  52. <a-button id="allocateBill-basicInfo-modal-back" @click="isShow = false" style="margin-left: 15px;">取消</a-button>
  53. </div>
  54. </a-modal>
  55. </template>
  56. <script>
  57. import debounce from 'lodash/debounce'
  58. import { VSelect } from '@/components'
  59. import { allocateBillSave } from '@/api/allocateBill'
  60. import { dealerQueryList } from '@/api/dealer'
  61. import { getLookUpData } from '@/api/data'
  62. import { allocateTypeAllList } from '@/api/allocateType'
  63. export default {
  64. name: 'StoreTransferOutBasicInfoModal',
  65. components: { VSelect },
  66. props: {
  67. openModal: {
  68. // 弹框显示状态
  69. type: Boolean,
  70. default: false
  71. }
  72. },
  73. data () {
  74. this.fetchUser = debounce(this.fetchUser, 800)
  75. return {
  76. isShow: this.openModal, // 是否打开弹框
  77. formItemLayout: {
  78. labelCol: { span: 6 },
  79. wrapperCol: { span: 16 }
  80. },
  81. form: {
  82. targetType: '1',
  83. targetSn: undefined,
  84. targetName: '',
  85. allocateTypeSn: undefined,
  86. remark: ''
  87. },
  88. rules: {
  89. targetType: [{ required: true, message: '请选择调往对象', trigger: 'change' }],
  90. targetSn: [{ required: true, message: '请选择调往对象名称', trigger: 'change' }],
  91. targetName: [{ required: true, message: '请输入调往对象名称', trigger: 'blur' }],
  92. allocateTypeSn: [{ required: true, message: '请选择调拨类型', trigger: 'change' }]
  93. },
  94. fetching: false,
  95. dealerData: [], // 经销商 下拉数据
  96. targetTypeList: [], // 调往对象类型
  97. allocateTypeList: [] // 调拨类型
  98. }
  99. },
  100. computed: {
  101. // 当前所选调往对象是否为经销商
  102. isDealer () {
  103. return this.form.targetType == '1'
  104. }
  105. },
  106. methods: {
  107. // 搜索经销商
  108. fetchUser (value) {
  109. console.log('fetching user', value)
  110. this.fetching = true
  111. dealerQueryList({ nameLike: value, pageNo: 1, pageSize: 20 }).then(res => {
  112. if (res.status == 200) {
  113. this.dealerData = res.data.list
  114. this.fetching = false
  115. } else {
  116. this.dealerData = []
  117. this.fetching = false
  118. }
  119. })
  120. },
  121. // 调往对象名称 change
  122. handleChange (value) {
  123. const ind = this.dealerData.findIndex(item => item.dealerSn == value)
  124. this.form.targetName = this.dealerData[ind].dealerName
  125. },
  126. // 保存
  127. handleSave () {
  128. const _this = this
  129. this.$refs.ruleForm.validate(valid => {
  130. if (valid) {
  131. const form = JSON.parse(JSON.stringify(_this.form))
  132. allocateBillSave(form).then(res => {
  133. if (res.status == 200) {
  134. _this.$message.success(res.message)
  135. setTimeout(() => {
  136. _this.isShow = false
  137. _this.$emit('ok', res.data)
  138. }, 1000)
  139. }
  140. })
  141. } else {
  142. console.log('error submit!!')
  143. return false
  144. }
  145. })
  146. },
  147. // 调往对象 change
  148. targetTypeChange (e) {
  149. this.$refs.ruleForm.resetFields()
  150. this.form.targetSn = undefined
  151. this.form.targetName = ''
  152. this.form.targetType = e.target.value
  153. },
  154. // 调往对象类型
  155. getTargetTypeList () {
  156. const _this = this
  157. getLookUpData({
  158. pageNo: 1,
  159. pageSize: 1000,
  160. lookupCode: 'TARGET_TYPE'
  161. }).then(res => {
  162. if (res.status == 200) {
  163. _this.targetTypeList = res.data.list
  164. } else {
  165. _this.targetTypeList = []
  166. }
  167. })
  168. },
  169. // 调拨类型
  170. getAllocateTypeAllList () {
  171. allocateTypeAllList().then(res => {
  172. if (res.status == 200) {
  173. this.allocateTypeList = res.data
  174. } else {
  175. this.allocateTypeList = []
  176. }
  177. })
  178. }
  179. },
  180. watch: {
  181. // 父页面传过来的弹框状态
  182. openModal (newValue, oldValue) {
  183. this.isShow = newValue
  184. },
  185. // 重定义的弹框状态
  186. isShow (newValue, oldValue) {
  187. if (!newValue) {
  188. this.$emit('close')
  189. this.$refs.ruleForm.resetFields()
  190. } else {
  191. this.getTargetTypeList()
  192. this.getAllocateTypeAllList()
  193. }
  194. }
  195. }
  196. }
  197. </script>
  198. <style lang="less">
  199. .allocateBill-basicInfo-modal {
  200. .ant-modal-body {
  201. padding: 40px 40px 24px;
  202. }
  203. .btn-cont {
  204. text-align: center;
  205. margin: 35px 0 10px;
  206. }
  207. }
  208. </style>