addModal.vue 10 KB

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