addModal.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <a-modal
  3. centered
  4. class="purchaseReturn-basicInfo-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="itemSn?'编辑':'新增'"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="purchaseReturn-basicInfo-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol" >
  19. <a-form-model-item label="供应商名称" prop="supplierSn">
  20. <supplier v-model="form.supplierSn" :disabledFlag="itemSn?true:false" placeholder="请输入供应商名称"></supplier>
  21. </a-form-model-item>
  22. <a-form-model-item label="退货原因" prop="returnReason">
  23. <v-select
  24. v-model="form.returnReason"
  25. ref="returnReason"
  26. id="purchaseReturn-basicInfo-returnReason"
  27. code="SPARE_PARTS_RETURN_REASON"
  28. placeholder="请选择退货原因"
  29. allowClear></v-select>
  30. </a-form-model-item>
  31. <a-form-model-item label="补充说明" prop="explainInfo">
  32. <a-textarea
  33. id="purchaseReturn"
  34. :maxLength="60"
  35. v-model="form.explainInfo"
  36. placeholder="具体描述下退货原因"
  37. allowClear />
  38. </a-form-model-item>
  39. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)">
  40. <Upload
  41. style="height: 100%;"
  42. id="allocateBill-attachList"
  43. v-model="form.attachmentList"
  44. ref="attachList"
  45. :fileSize="10"
  46. :maxNums="10"
  47. fileType="*"
  48. uploadType="attach"
  49. :action="attachAction"
  50. @change="changeAttach"
  51. upText="上传附件"></Upload>
  52. </a-form-model-item>
  53. </a-form-model>
  54. <div class="btn-cont">
  55. <a-button id="purchaseReturn-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  56. <a-button style="margin-left: 15px;" type="primary" id="purchaseReturn-modal-save" @click="handleSave">确定</a-button>
  57. </div>
  58. </a-spin>
  59. </a-modal>
  60. </template>
  61. <script>
  62. import { commonMixin } from '@/utils/mixin'
  63. import { VSelect, Upload } from '@/components'
  64. import supplier from '@/views/common/supplier.js'
  65. import { sparePartsReturnSave, sparePartsReturnInfo } from '@/api/sparePartsReturn'
  66. export default {
  67. name: 'PurchaseReturnBasicInfoModal',
  68. mixins: [commonMixin],
  69. components: { VSelect, Upload, supplier },
  70. props: {
  71. openModal: { // 弹框显示状态
  72. type: Boolean,
  73. default: false
  74. },
  75. itemSn: {
  76. type: [Number, String],
  77. default: ''
  78. }
  79. },
  80. data () {
  81. return {
  82. isShow: this.openModal, // 是否打开弹框
  83. spinning: false,
  84. formItemLayout: {
  85. labelCol: { span: 5 },
  86. wrapperCol: { span: 16 }
  87. },
  88. form: {
  89. supplierSn: undefined, // 供应商
  90. returnReason: '', // 退货原因
  91. explainInfo: '', // 补充说明
  92. attachmentList: ''
  93. },
  94. attachList: [], // 附件
  95. rules: {
  96. supplierSn: [
  97. { required: true, message: '请选择供应商名称', trigger: 'change' }
  98. ],
  99. returnReason: [
  100. { required: true, message: '请选择退货原因', trigger: 'change' }
  101. ]
  102. },
  103. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo'
  104. }
  105. },
  106. methods: {
  107. // 附件上传
  108. changeAttach (file) {
  109. this.attachList = JSON.parse(file)
  110. this.attachList.map(item => {
  111. item.fileType = item.extName
  112. })
  113. },
  114. // 保存
  115. handleSave () {
  116. const _this = this
  117. this.$refs.ruleForm.validate(valid => {
  118. if (valid) {
  119. const form = JSON.parse(JSON.stringify(_this.form))
  120. form.attachmentList = _this.attachList
  121. _this.spinning = true
  122. debugger
  123. sparePartsReturnSave(form).then(res => {
  124. if (res.status == 200) {
  125. _this.$message.success(res.message)
  126. setTimeout(() => {
  127. _this.isShow = false
  128. _this.$emit('ok', res.data)
  129. _this.spinning = false
  130. }, 1000)
  131. } else {
  132. _this.spinning = false
  133. }
  134. })
  135. } else {
  136. return false
  137. }
  138. })
  139. },
  140. // 获取编辑详情
  141. getDetail () {
  142. sparePartsReturnInfo({ sn: this.itemSn }).then(res => {
  143. if (res.status == 200) {
  144. const resultObj = res.data
  145. this.attachList = resultObj.attachmentList
  146. const obj = {
  147. supplierSn: resultObj.supplierSn,
  148. returnReason: resultObj.returnReason, // 退货原因
  149. explainInfo: resultObj.explainInfo, // 补充说明
  150. sparePartsReturnSn: this.itemSn
  151. }
  152. this.$nextTick(() => {
  153. this.$refs.attachList.setFileList(this.attachList)
  154. })
  155. this.form = { ...this.form, ...obj }
  156. } else {
  157. this.detailsData = null
  158. }
  159. })
  160. }
  161. },
  162. watch: {
  163. // 父页面传过来的弹框状态
  164. openModal (newValue, oldValue) {
  165. this.isShow = newValue
  166. },
  167. // 重定义的弹框状态
  168. isShow (newValue, oldValue) {
  169. if (!newValue) {
  170. this.$emit('close')
  171. this.attachList = []
  172. this.supplierName = null
  173. this.$refs.ruleForm.resetFields()
  174. } else {
  175. if (this.itemSn) {
  176. this.getDetail()
  177. }
  178. }
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="less" scoped>
  184. .purchaseReturn-basicInfo-modal{
  185. .ant-modal-body {
  186. padding: 40px 40px 24px;
  187. }
  188. .btn-cont {
  189. text-align: center;
  190. margin: 35px 0 10px;
  191. }
  192. .ant-form-item:nth-child(4){
  193. margin-bottom: 0px !important;
  194. }
  195. }
  196. </style>