addModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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="请选择参与客户">
  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="content">
  66. <a-textarea
  67. id="promotionList-content"
  68. :maxLength="500"
  69. :rows="5"
  70. v-model="form.content"
  71. placeholder="请输入促销描述"
  72. allowClear />
  73. </a-form-model-item>
  74. <a-form-model-item label="附件" help="(支持图片、word、excel、PDF等格式,最多10个附件)">
  75. <Upload
  76. style="height: 100%;"
  77. id="allocateBill-attachList"
  78. v-model="form.attachmentList"
  79. ref="attachList"
  80. :fileSize="10"
  81. :maxNums="10"
  82. fileType="*"
  83. uploadType="attach"
  84. :action="attachAction"
  85. @change="changeAttach"
  86. upText="上传附件"></Upload>
  87. </a-form-model-item>
  88. </a-form-model>
  89. <div class="btn-cont">
  90. <a-button id="promotionList-basicInfo-modal-back" @click="isShow = false">取消</a-button>
  91. <a-button style="margin-left: 15px;" type="primary" id="promotionList-modal-save" @click="handleSave">确定</a-button>
  92. </div>
  93. </a-spin>
  94. <!-- 选择参与客户 -->
  95. <a-modal
  96. title="选择经销商"
  97. :visible="openDealerModal"
  98. :footer="null"
  99. centered
  100. class="lookUpCustomers-modal"
  101. @cancel="openDealerModal = false"
  102. width="60%"
  103. >
  104. <div class="dealerModalCon">
  105. <chooseDealer ref="dealerChoose" pageType="dealerPromotion" @plAdd="handleAddDealer"></chooseDealer>
  106. </div>
  107. </a-modal>
  108. <!-- 导入参与客户 -->
  109. <importDealerModa :openModal="openGuideModal" @close="openGuideModal=false" @ok="hanldeOk" />
  110. </a-modal>
  111. </template>
  112. <script>
  113. import { commonMixin } from '@/utils/mixin'
  114. import { Upload } from '@/components'
  115. import department from '@/views/expenseManagement/expenseReimbursement/department.js'
  116. import warehouse from '@/views/common/chooseWarehouse.js'
  117. import moment from 'moment'
  118. import chooseDealer from '../promotionManagement/chooseDealer'
  119. import importDealerModa from './importDealerModa.vue'
  120. import { dealerPromotionSave, dealerPromotionInfo, dealerPromotionEdit } from '@/api/promotion'
  121. export default {
  122. name: 'PromotionListBasicInfoModal',
  123. mixins: [commonMixin],
  124. components: { Upload, department, warehouse, chooseDealer, importDealerModa },
  125. props: {
  126. openModal: { // 弹框显示状态
  127. type: Boolean,
  128. default: false
  129. },
  130. itemSn: {
  131. type: [Number, String],
  132. default: ''
  133. }
  134. },
  135. data () {
  136. return {
  137. isShow: this.openModal, // 是否打开弹框
  138. spinning: false,
  139. formItemLayout: {
  140. labelCol: { span: 5 },
  141. wrapperCol: { span: 16 }
  142. },
  143. form: {
  144. title: '',
  145. activeDate: undefined,
  146. expenseDepartmentSn: undefined, // 费用所属部门
  147. description: '', // 活动简称
  148. content: '', // 活动描述
  149. attachmentList: '', // 附件
  150. dealerSnList: [], // 参与客户
  151. dealerScope: 'SOME_DEALER' // 全部客户 部分客户
  152. },
  153. openDealerModal: false,
  154. chooseDealerList: [],
  155. attachList: [], // 附件
  156. dateFormat: 'YYYY-MM-DD',
  157. rules: {
  158. title: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  159. activeDate: [{ required: true, message: '请选择促销时间', trigger: 'change' } ],
  160. expenseDepartmentSn: [{ required: true, message: '请选择费用所属部门', trigger: 'change' }],
  161. dealerScope: [{ required: true, message: '请选择参与客户', trigger: 'change' }],
  162. description: [{ required: true, message: '请输入促销简称', trigger: 'blur' }],
  163. content: [{ required: true, message: '请输入促销描述', trigger: 'blur' }]
  164. },
  165. attachAction: process.env.VUE_APP_API_BASE_URL + '/uploadGetFileInfo',
  166. openGuideModal: false
  167. }
  168. },
  169. methods: {
  170. // 选择活动时间
  171. onChangeDate (date, dateString) {
  172. this.form.activeDate = date
  173. if (dateString[0] != '' && dateString[1] != '') {
  174. this.form.promotionDateStart = dateString[0] + ' 00:00:00'
  175. this.form.promotionDateEnd = dateString[1] + ' 23:59:59'
  176. }
  177. },
  178. // 费用所属部门
  179. departementChange () {
  180. this.$nextTick(() => {
  181. this.$refs.ruleForm.validateField('expenseDepartmentSn')
  182. })
  183. },
  184. // 附件上传
  185. changeAttach (file) {
  186. this.attachList = JSON.parse(file)
  187. this.attachList.map(item => {
  188. item.fileType = item.extName
  189. })
  190. },
  191. // 选择参与客户
  192. handleDealerModal () {
  193. this.openDealerModal = true
  194. const _this = this
  195. if (_this.chooseDealerList.length == 0) {
  196. _this.form.dealerSnList = []
  197. }
  198. const arr = _this.chooseDealerList.map(item => {
  199. return item.dealerSn
  200. })
  201. // 选择参与客户回显
  202. _this.$nextTick(() => {
  203. _this.$refs.dealerChoose.pageInit(arr)
  204. })
  205. },
  206. // 删除所选参与客户
  207. delBuyerName (row) {
  208. const pot = this.chooseDealerList.findIndex(con => { return con.dealerSn == row.dealerSn })
  209. this.chooseDealerList.splice(pot, 1)
  210. },
  211. // 添加经销商
  212. handleAddDealer (list) {
  213. this.chooseDealerList = list
  214. this.openDealerModal = false
  215. // 移除表单必填项
  216. this.$refs.ruleForm.clearValidate('dealerSnList')
  217. },
  218. // 新增/编辑
  219. handleSave () {
  220. const _this = this
  221. const newArr = this.chooseDealerList.map(item => {
  222. return item.dealerSn
  223. })
  224. _this.form.dealerSnList = newArr
  225. this.$refs.ruleForm.validate(valid => {
  226. if (valid) {
  227. const form = JSON.parse(JSON.stringify(_this.form))
  228. form.attachmentList = _this.attachList
  229. delete form.activeDate
  230. _this.spinning = true
  231. const ajaxName = _this.itemSn ? dealerPromotionEdit : dealerPromotionSave
  232. ajaxName(form).then(res => {
  233. if (res.status == 200) {
  234. _this.$message.success(res.message)
  235. setTimeout(() => {
  236. _this.isShow = false
  237. _this.$emit('ok', res.data)
  238. _this.spinning = false
  239. }, 1000)
  240. } else {
  241. _this.spinning = false
  242. }
  243. })
  244. } else {
  245. return false
  246. }
  247. })
  248. },
  249. // 重置
  250. resetSearchForm () {
  251. this.form = {
  252. title: '',
  253. activeDate: undefined,
  254. expenseDepartmentSn: undefined, // 费用所属部门
  255. description: '', // 活动简称
  256. content: '', // 活动描述
  257. attachmentList: '', // 附件
  258. dealerSnList: [], // 参与客户
  259. dealerScope: 'SOME_DEALER'
  260. }
  261. this.attachList = []
  262. this.chooseDealerList = []
  263. this.$nextTick(() => {
  264. this.$refs.attachList.setFileList('')
  265. this.$refs.ruleForm.resetFields()
  266. })
  267. },
  268. // 获取编辑详情
  269. getDetail () {
  270. dealerPromotionInfo({ sn: this.itemSn }).then(res => {
  271. if (res.status == 200) {
  272. const data = res.data
  273. this.chooseDealerList = data.dealerList
  274. data.dealerSnList = data.dealerSnList
  275. data.activeDate = [data.promotionDateStart, data.promotionDateEnd]
  276. if (data.attachmentList) {
  277. this.attachList = data.attachmentList
  278. this.$nextTick(() => {
  279. this.$refs.attachList.setFileList(this.attachList)
  280. })
  281. }
  282. this.form = data
  283. }
  284. })
  285. },
  286. // 不可选日期
  287. disabledDate (date, dateStrings) {
  288. return date && date.valueOf('day') < moment().subtract(1, 'day') // 今天以后,包含今天
  289. },
  290. // 导入参与客户
  291. hanldeOk (arr) {
  292. this.chooseDealerList = this.chooseDealerList.concat(arr)
  293. }
  294. },
  295. watch: {
  296. // 父页面传过来的弹框状态
  297. openModal (newValue, oldValue) {
  298. this.isShow = newValue
  299. },
  300. // 重定义的弹框状态
  301. isShow (newValue, oldValue) {
  302. if (!newValue) {
  303. this.$emit('close')
  304. this.resetSearchForm()
  305. } else {
  306. if (this.itemSn) {
  307. this.getDetail()
  308. }
  309. }
  310. }
  311. }
  312. }
  313. </script>
  314. <style lang="less" scoped>
  315. .promotionList-basicInfo-modal{
  316. .ant-modal-body {
  317. padding: 40px 40px 24px;
  318. }
  319. .buyerBox{
  320. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  321. }
  322. .btn-cont {
  323. text-align: center;
  324. margin: 35px 0 10px;
  325. }
  326. }
  327. </style>