addModal.vue 16 KB

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