addModal.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotionList-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="promotionList-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. <a-input id="promotionList-promotionName" v-model.trim="form.promotionName" allowClear placeholder="请输入促销名称(最多30个字符)" :maxLength="30"></a-input>
  21. </a-form-model-item>
  22. <a-form-model-item label="促销时间" prop="supplierSn">
  23. <a-range-picker
  24. style="width:100%"
  25. id="promotionList-basicInfo-activeDate"
  26. :disabledDate="disabledDate"
  27. v-model="form.activeDate"
  28. :format="dateFormat"
  29. :placeholder="['开始时间', '结束时间']"></a-range-picker>
  30. </a-form-model-item>
  31. <a-form-model-item label="费用所属部门" prop="returnReason">
  32. <v-select
  33. v-model="form.returnReason"
  34. ref="returnReason"
  35. id="promotionList-basicInfo-returnReason"
  36. code="SPARE_PARTS_RETURN_REASON"
  37. placeholder="请选择费用所属部门"
  38. allowClear></v-select>
  39. </a-form-model-item>
  40. <a-form-model-item label="参与客户" prop="supplierSn">
  41. <a-row :gutter="15">
  42. <a-col :md="5" :sm="24">
  43. <a-button type="primary" :loading="spinning" @click="handleDealerModal">选择</a-button>
  44. </a-col>
  45. <a-col :md="6" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  46. 已{{ chooseDealerList.length }}选项
  47. </a-col>
  48. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  49. <div class="buyerBox">
  50. <a-tag closable v-for="con in chooseDealerList" :key="con.buyerSn" @close="delBuyerName(con)">
  51. {{ con.buyerName }}
  52. </a-tag>
  53. </div>
  54. </a-col>
  55. </a-row>
  56. </a-form-model-item>
  57. <a-form-model-item label="促销描述" prop="explainInfo">
  58. <a-textarea
  59. id="promotionList"
  60. :maxLength="500"
  61. :rows="5"
  62. v-model="form.explainInfo"
  63. placeholder="请输入促销描述"
  64. allowClear />
  65. </a-form-model-item>
  66. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)">
  67. <Upload
  68. style="height: 100%;"
  69. id="allocateBill-attachList"
  70. v-model="form.attachmentList"
  71. ref="attachList"
  72. :fileSize="10"
  73. :maxNums="10"
  74. fileType="*"
  75. uploadType="attach"
  76. :action="attachAction"
  77. @change="changeAttach"
  78. upText="上传附件"></Upload>
  79. </a-form-model-item>
  80. </a-form-model>
  81. <div class="btn-cont">
  82. <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  83. <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" @click="handleSave">确定</a-button>
  84. </div>
  85. </a-spin>
  86. <!-- 选择参与客户 -->
  87. <a-modal
  88. title="选择经销商"
  89. :visible="openDealerModal"
  90. :footer="null"
  91. centered
  92. class="lookUpCustomers-modal"
  93. @cancel="openDealerModal = false"
  94. width="60%"
  95. >
  96. <div class="dealerModalCon">
  97. <chooseDealer ref="dealerChoose" @plAdd="handleAddDealer"></chooseDealer>
  98. </div>
  99. </a-modal>
  100. </a-modal>
  101. </template>
  102. <script>
  103. import { commonMixin } from '@/utils/mixin'
  104. import { VSelect, Upload } from '@/components'
  105. import supplier from '@/views/common/supplier.js'
  106. import warehouse from '@/views/common/chooseWarehouse.js'
  107. import moment from 'moment'
  108. import chooseDealer from '../promotionManagement/chooseDealer'
  109. import { sparePartsReturnSave, sparePartsReturnInfo } from '@/api/sparePartsReturn'
  110. export default {
  111. name: 'PromotionListBasicInfoModal',
  112. mixins: [commonMixin],
  113. components: { VSelect, Upload, supplier, warehouse, chooseDealer },
  114. props: {
  115. openModal: { // 弹框显示状态
  116. type: Boolean,
  117. default: false
  118. },
  119. itemSn: {
  120. type: [Number, String],
  121. default: ''
  122. }
  123. },
  124. data () {
  125. return {
  126. isShow: this.openModal, // 是否打开弹框
  127. spinning: false,
  128. formItemLayout: {
  129. labelCol: { span: 5 },
  130. wrapperCol: { span: 16 }
  131. },
  132. form: {
  133. promotionName: '',
  134. activeDate: undefined,
  135. supplierSn: undefined, // 供应商
  136. returnReason: '', // 退货原因
  137. explainInfo: '', // 补充说明
  138. warehouseSn: undefined,
  139. attachmentList: ''
  140. },
  141. openDealerModal: false,
  142. chooseDealerList: [],
  143. attachList: [], // 附件
  144. dateFormat: 'YYYY-MM-DD',
  145. rules: {
  146. supplierSn: [
  147. { required: true, message: '请选择供应商名称', trigger: 'change' }
  148. ],
  149. returnReason: [
  150. { required: true, message: '请选择退货原因', trigger: 'change' }
  151. ],
  152. warehouseSn: [{ required: true, message: '请选择退货仓库', trigger: 'change' }]
  153. },
  154. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo'
  155. }
  156. },
  157. methods: {
  158. // 附件上传
  159. changeAttach (file) {
  160. this.attachList = JSON.parse(file)
  161. this.attachList.map(item => {
  162. item.fileType = item.extName
  163. })
  164. },
  165. // 选择参与客户
  166. handleDealerModal () {
  167. this.openDealerModal = true
  168. const _this = this
  169. if (_this.chooseDealerList.length == 0) {
  170. _this.form.promoBuyerList = []
  171. }
  172. const arr = _this.chooseDealerList.map(item => {
  173. return item.buyerSn
  174. })
  175. // 选择经销商回显
  176. _this.$nextTick(() => {
  177. _this.$refs.dealerChoose.pageInit(arr)
  178. })
  179. },
  180. // 添加经销商
  181. handleAddDealer (list) {
  182. this.chooseDealerList = list.map(con => {
  183. return {
  184. buyerSn: con.dealerSn,
  185. buyerName: con.dealerName
  186. }
  187. })
  188. this.openDealerModal = false
  189. // 移除表单必填项
  190. this.$refs.ruleForm.clearValidate('promoBuyerList')
  191. },
  192. // 保存
  193. handleSave () {
  194. const _this = this
  195. this.$refs.ruleForm.validate(valid => {
  196. if (valid) {
  197. const form = JSON.parse(JSON.stringify(_this.form))
  198. form.attachmentList = _this.attachList
  199. _this.spinning = true
  200. sparePartsReturnSave(form).then(res => {
  201. if (res.status == 200) {
  202. _this.$message.success(res.message)
  203. setTimeout(() => {
  204. _this.isShow = false
  205. _this.$emit('ok', res.data)
  206. _this.spinning = false
  207. }, 1000)
  208. } else {
  209. _this.spinning = false
  210. }
  211. })
  212. } else {
  213. return false
  214. }
  215. })
  216. },
  217. // 获取编辑详情
  218. getDetail () {
  219. sparePartsReturnInfo({ sn: this.itemSn }).then(res => {
  220. if (res.status == 200) {
  221. const resultObj = res.data
  222. this.attachList = resultObj.attachmentList
  223. const obj = {
  224. supplierSn: resultObj.supplierSn,
  225. returnReason: resultObj.returnReason, // 退货原因
  226. explainInfo: resultObj.explainInfo, // 补充说明
  227. warehouseSn: resultObj.warehouseSn,
  228. sparePartsReturnSn: this.itemSn
  229. }
  230. this.$nextTick(() => {
  231. this.$refs.attachList.setFileList(this.attachList)
  232. })
  233. this.form = { ...this.form, ...obj }
  234. } else {
  235. this.detailsData = null
  236. }
  237. })
  238. },
  239. // 不可选日期
  240. disabledDate (date, dateStrings) {
  241. return date && date.valueOf('day') < moment().subtract(1, 'day') // 今天以后,包含今天
  242. }
  243. },
  244. watch: {
  245. // 父页面传过来的弹框状态
  246. openModal (newValue, oldValue) {
  247. this.isShow = newValue
  248. },
  249. // 重定义的弹框状态
  250. isShow (newValue, oldValue) {
  251. if (!newValue) {
  252. this.$emit('close')
  253. this.attachList = []
  254. this.supplierName = null
  255. this.$nextTick(() => {
  256. this.$refs.attachList.setFileList('')
  257. this.$refs.ruleForm.resetFields()
  258. })
  259. } else {
  260. if (this.itemSn) {
  261. this.getDetail()
  262. } else {
  263. // 默认仓库
  264. this.form.warehouseSn = this.isShowWarehouse ? undefined : this.defWarehouse && this.defWarehouse.warehouseSn
  265. }
  266. }
  267. }
  268. }
  269. }
  270. </script>
  271. <style lang="less" scoped>
  272. .promotionList-basicInfo-modal{
  273. .ant-modal-body {
  274. padding: 40px 40px 24px;
  275. }
  276. .buyerBox{
  277. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  278. }
  279. .btn-cont {
  280. text-align: center;
  281. margin: 35px 0 10px;
  282. }
  283. }
  284. </style>