addModal.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. sparePartsReturnSave(form).then(res => {
  123. if (res.status == 200) {
  124. _this.$message.success(res.message)
  125. setTimeout(() => {
  126. _this.isShow = false
  127. _this.$emit('ok', res.data)
  128. _this.spinning = false
  129. }, 1000)
  130. } else {
  131. _this.spinning = false
  132. }
  133. })
  134. } else {
  135. return false
  136. }
  137. })
  138. },
  139. // 获取编辑详情
  140. getDetail () {
  141. sparePartsReturnInfo({ sn: this.itemSn }).then(res => {
  142. if (res.status == 200) {
  143. const resultObj = res.data
  144. this.attachList = resultObj.attachmentList
  145. const obj = {
  146. supplierSn: resultObj.supplierSn,
  147. returnReason: resultObj.returnReason, // 退货原因
  148. explainInfo: resultObj.explainInfo, // 补充说明
  149. sparePartsReturnSn: this.itemSn
  150. }
  151. this.$nextTick(() => {
  152. this.$refs.attachList.setFileList(this.attachList)
  153. })
  154. this.form = { ...this.form, ...obj }
  155. } else {
  156. this.detailsData = null
  157. }
  158. })
  159. }
  160. },
  161. watch: {
  162. // 父页面传过来的弹框状态
  163. openModal (newValue, oldValue) {
  164. this.isShow = newValue
  165. },
  166. // 重定义的弹框状态
  167. isShow (newValue, oldValue) {
  168. if (!newValue) {
  169. this.$emit('close')
  170. this.attachList = []
  171. this.supplierName = null
  172. this.$refs.ruleForm.resetFields()
  173. } else {
  174. if (this.itemSn) {
  175. this.getDetail()
  176. }
  177. }
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="less" scoped>
  183. .purchaseReturn-basicInfo-modal{
  184. .ant-modal-body {
  185. padding: 40px 40px 24px;
  186. }
  187. .btn-cont {
  188. text-align: center;
  189. margin: 35px 0 10px;
  190. }
  191. .ant-form-item:nth-child(4){
  192. margin-bottom: 0px !important;
  193. }
  194. }
  195. </style>