addModal.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <a-modal
  3. centered
  4. class="promotion-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="isEdit?'编辑':'新增'"
  8. v-model="isShow"
  9. @cancel="isShow = false"
  10. :width="900">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="promotion-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol"
  19. >
  20. <a-form-model-item label="促销名称" prop="name">
  21. <a-input v-model="form.name" placeholder="请输入促销名称(最多30个字符)" :maxLength="30"></a-input>
  22. </a-form-model-item>
  23. <a-form-model-item label="促销时间" prop="time">
  24. <a-range-picker
  25. style="width:100%"
  26. v-model="form.time"
  27. :format="dateFormat"
  28. :disabled-date="disabledDate"
  29. @change="dateChange"
  30. :placeholder="['开始时间', '结束时间']" />
  31. </a-form-model-item>
  32. <a-form-model-item label="参与经销商" prop="promoBuyerList">
  33. <a-row :gutter="15">
  34. <!-- <a-col :md="15" :sm="24">
  35. <a-select
  36. v-model="form.buyerLimitEnable"
  37. placeholder="请选择参与经销商"
  38. >
  39. <a-select-option :value="0">全部经销商</a-select-option>
  40. <a-select-option :value="1">部分经销商</a-select-option>
  41. </a-select>
  42. </a-col> -->
  43. <a-col :md="5" :sm="24">
  44. <a-button type="primary" :loading="spinning" @click="handleDealerModal">选择经销商</a-button>
  45. </a-col>
  46. <a-col :md="6" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  47. 已{{ chooseDealerList.length }}选项
  48. </a-col>
  49. <a-col :md="24" :sm="24" v-show="chooseDealerList && chooseDealerList.length>0">
  50. <div class="buyerBox">
  51. <a-tag closable v-for="con in chooseDealerList" :key="con.buyerSn" @close="delBuyerName(con)">
  52. {{ con.buyerName }}
  53. </a-tag>
  54. </div>
  55. </a-col>
  56. </a-row>
  57. </a-form-model-item>
  58. <a-form-model-item style="margin-bottom:10px;" label="促销描述" prop="description" :wrapperCol="{ span: 16 }" :labelCol="{ span: 4 }">
  59. <a-textarea
  60. :rows="5"
  61. id="promotion-remark"
  62. :maxLength="500"
  63. v-model="form.description"
  64. placeholder="请输入备注(最多500个字符)"
  65. allowClear />
  66. </a-form-model-item>
  67. </a-form-model>
  68. <div class="btn-cont">
  69. <a-button id="promotion-modal-back" @click="isShow = false" >取消</a-button>
  70. <a-button type="primary" style="margin-left: 15px;" :loading="spinning" id="promotion-modal-save" @click="handleSave">确定</a-button>
  71. </div>
  72. </a-spin>
  73. <!-- 选择经销商 -->
  74. <a-modal
  75. title="选择经销商"
  76. :visible="openDealerModal"
  77. :footer="null"
  78. centered
  79. class="lookUpCustomers-modal"
  80. @cancel="openDealerModal = false"
  81. width="60%"
  82. >
  83. <div class="dealerModalCon">
  84. <chooseDealer ref="dealerChoose" @plAdd="handleAddDealer"></chooseDealer>
  85. </div>
  86. </a-modal>
  87. </a-modal>
  88. </template>
  89. <script>
  90. import { commonMixin } from '@/utils/mixin'
  91. import { promoTerminalSave, promoTerminalDetail } from '@/api/promoTerminal'
  92. import chooseDealer from './chooseDealer'
  93. import moment from 'moment'
  94. export default {
  95. name: 'PromotionAddModal',
  96. mixins: [commonMixin],
  97. components: { chooseDealer },
  98. props: {
  99. openModal: {
  100. // 弹框显示状态
  101. type: Boolean,
  102. default: false
  103. },
  104. itemId: {
  105. // 弹框显示状态
  106. type: String,
  107. default: ''
  108. }
  109. },
  110. data () {
  111. return {
  112. isShow: this.openModal, // 是否打开弹框
  113. openDealerModal: false,
  114. spinning: false,
  115. formItemLayout: {
  116. labelCol: { span: 4 },
  117. wrapperCol: { span: 16 }
  118. },
  119. form: {
  120. promoActiveSn: undefined,
  121. name: '',
  122. time: [],
  123. activeDateStart: undefined,
  124. activeDateEnd: undefined,
  125. activeDateEnable: '1',
  126. buyerLimitEnable: '1',
  127. description: '',
  128. promoBuyerList: []
  129. },
  130. rules: {
  131. promoBuyerList: [{ required: true, message: '请选择参与经销商', trigger: 'change' }],
  132. time: [{ required: true, message: '请选择促销时间', trigger: 'change' }],
  133. name: [{ required: true, message: '请输入促销名称', trigger: 'blur' }],
  134. description: [{ required: true, message: '请输入促销描述', trigger: 'blur' }]
  135. },
  136. dateFormat: 'YYYY-MM-DD',
  137. isEdit: false,
  138. chooseDealerList: []// 选择经销商列表
  139. }
  140. },
  141. methods: {
  142. disabledDate (current) {
  143. return current && current < moment().startOf('day')
  144. },
  145. handleDealerModal () {
  146. this.openDealerModal = true
  147. const _this = this
  148. if (_this.chooseDealerList.length == 0) {
  149. _this.form.promoBuyerList = []
  150. }
  151. const arr = _this.chooseDealerList.map(item => {
  152. return item.buyerSn
  153. })
  154. // 选择经销商回显
  155. _this.$nextTick(() => {
  156. _this.$refs.dealerChoose.pageInit(arr)
  157. })
  158. },
  159. // 日期 change
  160. dateChange (date, dateStrings) {
  161. if (dateStrings && dateStrings[0]) {
  162. this.form.time = dateStrings
  163. this.form.activeDateStart = date.length ? dateStrings[0] : ''
  164. this.form.activeDateEnd = date.length ? dateStrings[1] : ''
  165. } else {
  166. this.form.time = []
  167. }
  168. },
  169. // 添加经销商
  170. handleAddDealer (list) {
  171. this.chooseDealerList = list.map(con => {
  172. return {
  173. buyerSn: con.dealerSn,
  174. buyerName: con.dealerName
  175. }
  176. })
  177. const newArr = list.map(item => {
  178. return {
  179. buyerSn: item.dealerSn
  180. }
  181. })
  182. this.form.promoBuyerList = newArr
  183. this.openDealerModal = false
  184. // 移除表单必填项
  185. this.$refs.ruleForm.clearValidate('promoBuyerList')
  186. },
  187. // 获取编辑详情
  188. getEditInfo () {
  189. promoTerminalDetail({ sn: this.itemId }).then(res => {
  190. if (res.status == 200) {
  191. const data = res.data
  192. this.chooseDealerList = data.promoBuyerList
  193. data.promoBuyerList = data.promoBuyerList.map(item => {
  194. return {
  195. buyerSn: item.buyerSn
  196. }
  197. })
  198. data.time = [data.activeDateStart, data.activeDateEnd]
  199. this.form = data
  200. }
  201. })
  202. },
  203. // 删除所选经销商
  204. delBuyerName (row) {
  205. const pot = this.chooseDealerList.findIndex(con => { return con.buyerSn == row.buyerSn })
  206. this.chooseDealerList.splice(pot, 1)
  207. },
  208. // 保存促销
  209. handleSave () {
  210. const _this = this
  211. this.$refs.ruleForm.validate(valid => {
  212. if (valid) {
  213. const form = JSON.parse(JSON.stringify(_this.form))
  214. delete form.time
  215. _this.spinning = true
  216. promoTerminalSave(form).then(res => {
  217. if (res.status == 200) {
  218. _this.$message.success(res.message)
  219. _this.isShow = false
  220. _this.$emit('ok', res.data)
  221. }
  222. _this.spinning = false
  223. })
  224. } else {
  225. _this.spinning = false
  226. return false
  227. }
  228. })
  229. }
  230. },
  231. watch: {
  232. // 父页面传过来的弹框状态
  233. openModal (newValue, oldValue) {
  234. this.isShow = newValue
  235. },
  236. // 重定义的弹框状态
  237. isShow (newValue, oldValue) {
  238. if (!newValue) {
  239. this.$emit('close')
  240. this.$refs.ruleForm.resetFields()
  241. this.form = {
  242. promoActiveSn: undefined,
  243. name: '',
  244. time: [],
  245. activeDateStart: undefined,
  246. activeDateEnd: undefined,
  247. activeDateEnable: '1',
  248. buyerLimitEnable: '1',
  249. description: '',
  250. promoBuyerList: []
  251. }
  252. this.isEdit = false
  253. this.chooseDealerList = []
  254. } else {
  255. this.isEdit = !!this.itemId
  256. if (this.itemId) {
  257. this.getEditInfo()
  258. }
  259. }
  260. }
  261. }
  262. }
  263. </script>
  264. <style lang="less">
  265. .promotion-modal {
  266. .ant-modal-body {
  267. padding: 40px 40px 24px;
  268. }
  269. .buyerBox{
  270. border:1px solid #d9d9d9;margin-top:10px;border-radius:4px;padding:4px 10px;background:#f2f2f2;max-height:130px;overflow-y:scroll;
  271. }
  272. .btn-cont {
  273. text-align: center;
  274. margin: 35px 0 10px;
  275. }
  276. }
  277. </style>