addModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. style="max-height:650px;overflow-y: scroll;"
  14. id="promotionList-basicInfo-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol" >
  20. <a-form-model-item label="促销名称" prop="title">
  21. <a-input id="promotionList-promotionName" v-model.trim="form.title" allowClear placeholder="请输入促销名称(最多30个字符)" :maxLength="30"></a-input>
  22. </a-form-model-item>
  23. <a-form-model-item label="促销简称" prop="description">
  24. <a-input id="promotionList-description" v-model.trim="form.description" allowClear placeholder="请输入促销简称(最多20个字符)" :maxLength="20"></a-input>
  25. </a-form-model-item>
  26. <a-form-model-item label="促销时间" prop="activeDate">
  27. <a-range-picker
  28. style="width:100%"
  29. id="promotionList-basicInfo-activeDate"
  30. :disabledDate="disabledDate"
  31. v-model="form.activeDate"
  32. :format="dateFormat"
  33. :placeholder="['开始时间', '结束时间']"
  34. @change="onChangeDate"></a-range-picker>
  35. </a-form-model-item>
  36. <a-form-model-item label="费用所属部门" prop="expenseDepartmentSn">
  37. <department style="width: 100%;" @change="departementChange" id="promotionList-basicInfo-activeDate" v-model="form.expenseDepartmentSn"></department>
  38. </a-form-model-item>
  39. <a-form-model-item label="参与客户" prop="dealerScope">
  40. <a-row :gutter="15">
  41. <a-col :md="12" :sm="24">
  42. <a-select v-model="form.dealerScope" placeholder="请选择参与客户" @change="changeDealerScope" allowClear>
  43. <a-select-option value="ALL_DEALER">全部客户</a-select-option>
  44. <a-select-option value="SOME_DEALER">部分客户</a-select-option>
  45. </a-select>
  46. </a-col>
  47. <a-col :md="3" :sm="24" v-show="form.dealerScope && form.dealerScope!='ALL_DEALER' ">
  48. <a-button type="primary" :loading="spinning" @click="handleDealerModal">选择</a-button>
  49. </a-col>
  50. <a-col :md="4" :sm="24" v-show="form.dealerScope && form.dealerScope!='ALL_DEALER' ">
  51. <a-button type="primary" :loading="spinning" @click="openGuideModal=true" ghost>导入客户</a-button>
  52. </a-col>
  53. <a-col :md="5" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  54. 已{{ chooseDealerList.length }}选项
  55. </a-col>
  56. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  57. <div class="buyerBox">
  58. <a-tag closable v-for="con in chooseDealerList" :key="con.dealerSn" @close="delBuyerName(con)">
  59. {{ con.dealerName }}
  60. </a-tag>
  61. </div>
  62. </a-col>
  63. </a-row>
  64. </a-form-model-item>
  65. <a-form-model-item label="订单起订金额" prop="minOrderFlag">
  66. <a-select default-value="0" v-model="form.minOrderFlag" style="width: 180px" placeholder="请选择">
  67. <a-select-option value="0">
  68. 不限
  69. </a-select-option>
  70. <a-select-option value="1">
  71. 限制
  72. </a-select-option>
  73. </a-select>
  74. <a-input-number
  75. v-show="form.minOrderFlag && form.minOrderFlag=='1'"
  76. style="margin-left:10px;width:300px;"
  77. v-model="form.minOrderAmount"
  78. :min="0"
  79. :step="1"
  80. :max="999999"
  81. :precision="2"
  82. placeholder="请输入金额"/>
  83. </a-form-model-item>
  84. <a-form-model-item label="活动经费上限" prop="upperLimitFlag">
  85. <a-select default-value="0" v-model="form.upperLimitFlag" style="width: 180px" placeholder="请选择">
  86. <a-select-option value="0">
  87. 不限
  88. </a-select-option>
  89. <a-select-option value="1">
  90. 限制
  91. </a-select-option>
  92. </a-select>
  93. <a-input-number
  94. v-show="form.upperLimitFlag&&form.upperLimitFlag=='1'"
  95. style="margin-left:10px;width:300px;"
  96. v-model="form.upperLimitAmount"
  97. :min="0"
  98. :step="1"
  99. :max="999999"
  100. :precision="2"
  101. placeholder="请输入金额"/>
  102. </a-form-model-item>
  103. <a-form-model-item label="促销描述" prop="content">
  104. <a-textarea
  105. id="promotionList-content"
  106. :maxLength="500"
  107. :rows="5"
  108. v-model="form.content"
  109. placeholder="请输入促销描述"
  110. allowClear />
  111. </a-form-model-item>
  112. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)">
  113. <Upload
  114. style="height: 100%;"
  115. id="allocateBill-attachList"
  116. v-model="form.attachmentList"
  117. ref="attachList"
  118. :fileSize="10"
  119. :maxNums="10"
  120. fileType="*"
  121. uploadType="attach"
  122. :action="attachAction"
  123. @change="changeAttach"
  124. upText="上传附件"></Upload>
  125. </a-form-model-item>
  126. </a-form-model>
  127. <div class="btn-cont">
  128. <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  129. <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" :loading="loadingSave" @click="handleSave">确定</a-button>
  130. </div>
  131. </a-spin>
  132. <!-- 选择参与客户 -->
  133. <a-modal
  134. title="选择经销商"
  135. :visible="openDealerModal"
  136. :footer="null"
  137. centered
  138. class="lookUpCustomers-modal"
  139. @cancel="openDealerModal = false"
  140. width="60%"
  141. >
  142. <div class="dealerModalCon">
  143. <chooseDealer ref="dealerChoose" @plAdd="handleAddDealer"></chooseDealer>
  144. </div>
  145. </a-modal>
  146. <!-- 导入参与客户 -->
  147. <importDealerModa :openModal="openGuideModal" @close="openGuideModal=false" @ok="hanldeOk" />
  148. </a-modal>
  149. </template>
  150. <script>
  151. import { commonMixin } from '@/utils/mixin'
  152. import { Upload } from '@/components'
  153. import department from '@/views/expenseManagement/expenseReimbursement/department.js'
  154. import warehouse from '@/views/common/chooseWarehouse.js'
  155. import moment from 'moment'
  156. import chooseDealer from './chooseDealer'
  157. import importDealerModa from './importDealerModa.vue'
  158. import { dealerPromotionSave, dealerPromotionInfo, dealerPromotionEdit } from '@/api/promotion'
  159. export default {
  160. name: 'PromotionListBasicInfoModal',
  161. mixins: [commonMixin],
  162. components: { Upload, department, warehouse, chooseDealer, importDealerModa },
  163. props: {
  164. openModal: { // 弹框显示状态
  165. type: Boolean,
  166. default: false
  167. },
  168. itemSn: {
  169. type: [Number, String],
  170. default: ''
  171. }
  172. },
  173. data () {
  174. return {
  175. isShow: this.openModal, // 是否打开弹框
  176. spinning: false,
  177. formItemLayout: {
  178. labelCol: { span: 5 },
  179. wrapperCol: { span: 16 }
  180. },
  181. form: {
  182. title: '',
  183. activeDate: undefined,
  184. expenseDepartmentSn: undefined, // 费用所属部门
  185. description: '', // 活动简称
  186. content: '', // 活动描述
  187. attachmentList: '', // 附件
  188. promotionDealerList: [], // 参与客户
  189. dealerScope: 'SOME_DEALER', // 全部客户 部分客户
  190. minOrderFlag: '0', // 订单起订金额
  191. minOrderAmount: undefined,
  192. upperLimitFlag: '0', // 活动经费上限
  193. upperLimitAmount: undefined
  194. },
  195. openDealerModal: false,
  196. chooseDealerList: [],
  197. attachList: [], // 附件
  198. dateFormat: 'YYYY-MM-DD',
  199. rules: {
  200. title: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  201. activeDate: [{ required: true, message: '请选择促销时间', trigger: 'change' }],
  202. expenseDepartmentSn: [{ required: true, message: '请选择费用所属部门', trigger: 'change' }],
  203. dealerScope: [{ required: true, message: '请选择参与客户', trigger: 'change' }],
  204. description: [{ required: true, message: '请输入促销简称', trigger: 'blur' }],
  205. minOrderFlag: [{ required: true, message: '请选择订单起订金额', trigger: 'change' }],
  206. upperLimitFlag: [{ required: true, message: '请选择活动经费上限', trigger: 'change' }],
  207. content: [{ required: true, message: '请输入促销描述', trigger: 'blur' }]
  208. },
  209. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo',
  210. openGuideModal: false,
  211. loadingSave: false
  212. }
  213. },
  214. methods: {
  215. // 选择活动时间
  216. onChangeDate (date, dateString) {
  217. this.form.activeDate = date
  218. if (dateString[0] != '' && dateString[1] != '') {
  219. this.form.promotionDateStart = dateString[0] + ' 00:00:00'
  220. this.form.promotionDateEnd = dateString[1] + ' 23:59:59'
  221. }
  222. },
  223. // 费用所属部门
  224. departementChange () {
  225. this.$nextTick(() => {
  226. this.$refs.ruleForm.validateField('expenseDepartmentSn')
  227. })
  228. },
  229. // 附件上传
  230. changeAttach (file) {
  231. this.attachList = file ? JSON.parse(file) : []
  232. this.attachList.map(item => {
  233. item.fileType = item.extName
  234. })
  235. },
  236. // 选择参与客户
  237. handleDealerModal () {
  238. this.openDealerModal = true
  239. const _this = this
  240. if (_this.chooseDealerList.length == 0) {
  241. _this.form.promotionDealerList = []
  242. }
  243. const arr = _this.chooseDealerList.map(item => {
  244. return item.dealerSn
  245. })
  246. // 选择参与客户回显
  247. _this.$nextTick(() => {
  248. _this.$refs.dealerChoose.pageInit(arr)
  249. })
  250. },
  251. // 删除所选参与客户
  252. delBuyerName (row) {
  253. const pot = this.chooseDealerList.findIndex(con => { return con.dealerSn == row.dealerSn })
  254. this.chooseDealerList.splice(pot, 1)
  255. },
  256. // 添加经销商
  257. handleAddDealer (list) {
  258. this.chooseDealerList = list
  259. this.openDealerModal = false
  260. // 移除表单必填项
  261. this.$refs.ruleForm.clearValidate('promotionDealerList')
  262. },
  263. // 新增/编辑
  264. handleSave () {
  265. const _this = this
  266. if (_this.form.dealerScope === 'SOME_DEALER') {
  267. if (_this.chooseDealerList && _this.chooseDealerList.length > 0) {
  268. const newArr = _this.chooseDealerList.map(item => {
  269. return { dealerSn: item.dealerSn, dealerScope: _this.form.dealerScope }
  270. })
  271. _this.form.promotionDealerList = newArr
  272. } else {
  273. _this.$message.error('请选择参与客户')
  274. return
  275. }
  276. } else {
  277. _this.form.promotionDealerList = [{ dealerScope: _this.form.dealerScope }]
  278. _this.form.dealerList = []
  279. }
  280. this.$refs.ruleForm.validate(valid => {
  281. if (valid) {
  282. const form = JSON.parse(JSON.stringify(_this.form))
  283. // 判断起订金额、活动经费上限
  284. if (form.minOrderFlag == '1' && !form.minOrderAmount) {
  285. _this.$message.error('请输入订单起订限制金额数!')
  286. return
  287. }
  288. if (form.upperLimitFlag == '1' && !form.upperLimitAmount) {
  289. _this.$message.warning('请输入活动经费上限金额!')
  290. return
  291. }
  292. if (form.minOrderFlag == '0') {
  293. form.minOrderAmount = undefined
  294. }
  295. if (form.upperLimitFlag == '0') {
  296. form.upperLimitAmount = undefined
  297. }
  298. form.attachmentList = _this.attachList
  299. delete form.activeDate
  300. _this.spinning = true
  301. _this.loadingSave = true
  302. const ajaxName = _this.itemSn ? dealerPromotionEdit : dealerPromotionSave
  303. ajaxName(form).then(res => {
  304. if (res.status == 200) {
  305. _this.$message.success(res.message)
  306. setTimeout(() => {
  307. _this.isShow = false
  308. _this.$emit('ok', res.data)
  309. _this.spinning = false
  310. _this.loadingSave = false
  311. }, 1000)
  312. } else {
  313. _this.spinning = false
  314. _this.loadingSave = false
  315. }
  316. })
  317. } else {
  318. return false
  319. }
  320. })
  321. },
  322. // 选择全部客户时,清空之前选择的客户列表
  323. changeDealerScope (val) {
  324. if (val === 'ALL_DEALER') {
  325. this.chooseDealerList = []
  326. }
  327. },
  328. // 重置
  329. resetSearchForm () {
  330. this.form = {
  331. title: '',
  332. activeDate: undefined,
  333. expenseDepartmentSn: undefined, // 费用所属部门
  334. description: '', // 活动简称
  335. content: '', // 活动描述
  336. attachmentList: '', // 附件
  337. promotionDealerList: [], // 参与客户
  338. dealerScope: 'SOME_DEALER',
  339. minOrderFlag: '0', // 订单起订金额
  340. minOrderAmount: undefined,
  341. upperLimitFlag: '0', // 活动经费上限
  342. upperLimitAmount: undefined
  343. }
  344. this.attachList = []
  345. this.chooseDealerList = []
  346. this.$nextTick(() => {
  347. this.$refs.attachList.setFileList('')
  348. this.$refs.ruleForm.resetFields()
  349. })
  350. },
  351. // 获取编辑详情
  352. getDetail () {
  353. dealerPromotionInfo({ sn: this.itemSn }).then(res => {
  354. if (res.status == 200) {
  355. const data = res.data
  356. this.chooseDealerList = data.dealerList
  357. data.promotionDealerList = data.promotionDealerList
  358. data.activeDate = [data.promotionDateStart, data.promotionDateEnd]
  359. if (data.attachmentList) {
  360. this.attachList = data.attachmentList
  361. this.$nextTick(() => {
  362. this.$refs.attachList.setFileList(this.attachList)
  363. })
  364. }
  365. this.form = data
  366. }
  367. })
  368. },
  369. // 不可选日期
  370. disabledDate (date, dateStrings) {
  371. return date && date.valueOf('day') < moment().subtract(1, 'day') // 今天以后,包含今天
  372. },
  373. // 导入参与客户
  374. hanldeOk (arr) {
  375. const list = [...this.chooseDealerList, ...arr]
  376. const obj = {}
  377. this.chooseDealerList = list.reduce((cur, next) => {
  378. obj[next.dealerSn] ? '' : obj[next.dealerSn] = true && cur.push(next)
  379. return cur
  380. }, [])
  381. }
  382. },
  383. watch: {
  384. // 父页面传过来的弹框状态
  385. openModal (newValue, oldValue) {
  386. this.isShow = newValue
  387. },
  388. // 重定义的弹框状态
  389. isShow (newValue, oldValue) {
  390. if (!newValue) {
  391. this.$emit('close')
  392. this.resetSearchForm()
  393. } else {
  394. if (this.itemSn) {
  395. this.getDetail()
  396. }
  397. }
  398. }
  399. }
  400. }
  401. </script>
  402. <style lang="less" scoped>
  403. .promotionList-basicInfo-modal{
  404. .ant-modal-body {
  405. padding: 40px 40px 24px;
  406. }
  407. .buyerBox{
  408. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  409. }
  410. .btn-cont {
  411. text-align: center;
  412. margin: 35px 0 10px;
  413. }
  414. }
  415. </style>