updateActiveModal.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <a-modal
  3. v-model="opened"
  4. :title="title"
  5. centered
  6. :maskClosable="false"
  7. :width="total?'450px':'300px'"
  8. :footer="null"
  9. @cancel="cancel"
  10. >
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <!-- 批量操作 -->
  13. <div style="padding: 0 30px;" v-if="salesBillDetailSnList.length">
  14. <div>
  15. <span>产品范围:</span>
  16. <aRadioGroup v-model="productType">
  17. <aRadio :style="radioStyle0" value="0">选中产品</aRadio>
  18. <aRadio :style="radioStyle0" value="1">全部产品</aRadio>
  19. </aRadioGroup>
  20. </div>
  21. <div>
  22. <span>规则范围:</span>
  23. <aRadioGroup v-model="ruleType" @change="(e)=>{upActiveValArr=[];upActiveVal=null}">
  24. <aRadio :style="radioStyle0" value="0">选中规则</aRadio>
  25. <aRadio :style="radioStyle0" value="1">全部规则</aRadio>
  26. </aRadioGroup>
  27. </div>
  28. </div>
  29. <div v-if="ruleType==0">
  30. <div style="padding: 10px 30px;" v-if="total">
  31. <!-- 非叠加活动 -->
  32. <div>
  33. <aRadioGroup v-model="upActiveVal" @change="(e)=>{upActiveValArr=[]}">
  34. <aRadio :style="radioStyle" value="-1" v-if="pageType">
  35. 不参加促销
  36. </aRadio>
  37. <div v-if="noStackActiveList&&noStackActiveList.length">
  38. <strong >非叠加活动</strong>
  39. </div>
  40. <aRadio
  41. :style="radioStyle"
  42. v-for="(item,sindex) in noStackActiveList"
  43. :key="item.id"
  44. :value="item.salesPromoSn">
  45. {{ sindex+1 }}、{{ item.promotionRule.promotionRuleTypeDictValue }} — {{ item.promotion.title }}({{ item.promotionRule.description }})
  46. </aRadio>
  47. </aRadioGroup>
  48. </div>
  49. <!-- 叠加活动 -->
  50. <div v-if="stackActiveList&&stackActiveList.length">
  51. <div>
  52. <strong >叠加活动</strong>
  53. </div>
  54. <a-checkbox-group v-model="upActiveValArr" @change="(e)=>{upActiveVal=null}">
  55. <a-checkbox
  56. :style="radioStyle"
  57. v-for="(item,sindex) in stackActiveList"
  58. :value="item.salesPromoSn"
  59. :key="item.id">
  60. {{ sindex+1 }}、{{ item.promotionRule.promotionRuleTypeDictValue }} — {{ item.promotion.title }}({{ item.promotionRule.description }})
  61. </a-checkbox>
  62. </a-checkbox-group>
  63. </div>
  64. </div>
  65. <div style="padding: 10px 30px;text-align:center;" v-else>
  66. 没有可参与的【启用状态】的促销规则
  67. </div>
  68. </div>
  69. <div style="padding: 30px 0 0;text-align: center;">
  70. <a-button @click="cancel" style="margin-right: 15px" :type="total?'default':'primary'" id="chooseCustom-btn-back">{{ total?'取消':'知道了' }}</a-button>
  71. <a-button v-if="total" type="primary" :loading="confirmLoading" @click="salesBillDetailSnList.length?handleBatchSubmit():handleSubmit()" id="chooseCustom-btn-submit">确定</a-button>
  72. </div>
  73. </a-spin>
  74. </a-modal>
  75. </template>
  76. <script>
  77. import { commonMixin } from '@/utils/mixin'
  78. import { salesPromoMatchProduct } from '@/api/salesNew'
  79. export default {
  80. name: 'SetWarehouse',
  81. mixins: [commonMixin],
  82. props: {
  83. show: [Boolean],
  84. pageType: {// 判断是转促销弹窗
  85. type: Boolean,
  86. default: false
  87. }
  88. },
  89. data () {
  90. return {
  91. opened: this.show,
  92. spinning: false,
  93. confirmLoading: false,
  94. upActiveVal: null,
  95. upActiveValArr: [],
  96. radioStyle: "display:block;height: '30px';lineHeight: '30px';padding:5px 0;margin:0;",
  97. radioStyle0: "height: '30px';lineHeight: '30px';padding:5px 0;margin:0;",
  98. activeList: [],
  99. editRow: null,
  100. salesBillDetailSnList: [],
  101. productType: '0',
  102. ruleType: '0'
  103. }
  104. },
  105. computed: {
  106. title () {
  107. if (this.total == 0) {
  108. return '提示'
  109. }
  110. if (this.salesBillDetailSnList.length) {
  111. return '批量匹配促销'
  112. }
  113. return this.pageType ? '确定换促销活动?' : '确定参加促销活动?'
  114. },
  115. total () {
  116. return this.pageType ? 1 : this.activeList.length
  117. },
  118. // 叠加活动
  119. stackActiveList () {
  120. if (this.salesBillDetailSnList.length) {
  121. return this.activeList.filter(item => item.promotionRule && item.promotionRule.stackFlag == 1 && item.enabledFlag == 1)
  122. }
  123. return this.activeList.filter(item => item.stackFlag == 1)
  124. },
  125. // 非叠加活动
  126. noStackActiveList () {
  127. if (this.salesBillDetailSnList.length) {
  128. return this.activeList.filter(item => item.promotionRule && item.promotionRule.stackFlag == 0 && item.enabledFlag == 1)
  129. }
  130. return this.activeList.filter(item => item.stackFlag == 0)
  131. }
  132. },
  133. methods: {
  134. getActiveList (data, record) {
  135. this.editRow = record
  136. this.spinning = true
  137. salesPromoMatchProduct(data).then(res => {
  138. this.activeList = res.data || []
  139. // 回显选中项
  140. if (record && record.promoRuleSnList) {
  141. if (record.stackFlag == 0) { // 非叠加
  142. const pos = res.data.findIndex(item => item.promoRuleSn == record.promoRuleSnList[0])
  143. this.upActiveVal = pos >= 0 ? res.data[pos].salesPromoSn : '-1'
  144. } else { // 叠加
  145. const resultSnArr = res.data.filter(item => record.promoRuleSnList.includes(item.promoRuleSn)) // 过滤出promoRuleSn在promoRuleSnList中的对象
  146. .map(item => item.salesPromoSn) // 映射出这些对象的salesPromoSn属性
  147. this.upActiveValArr = resultSnArr
  148. }
  149. } else {
  150. this.upActiveVal = this.pageType ? '-1' : null
  151. }
  152. this.spinning = false
  153. })
  154. },
  155. // 批量操作
  156. setBatchData (productSn, activeList) {
  157. this.activeList = activeList
  158. this.salesBillDetailSnList = productSn
  159. },
  160. // 保存
  161. handleSubmit (e) {
  162. const _this = this
  163. console.log(_this.upActiveVal, this.upActiveValArr.length)
  164. if (_this.upActiveVal || this.upActiveValArr.length) {
  165. let salesPromoSnList = []
  166. // 不参与
  167. if (this.upActiveVal == '-1') {
  168. salesPromoSnList = []
  169. } else {
  170. salesPromoSnList = this.upActiveVal ? [this.upActiveVal] : this.upActiveValArr
  171. }
  172. _this.confirmLoading = true
  173. _this.$emit('ok', salesPromoSnList, _this.editRow)
  174. } else {
  175. _this.$message.info('请选择活动规则!')
  176. }
  177. },
  178. // 批量操作
  179. handleBatchSubmit (e) {
  180. const _this = this
  181. // 选中规则
  182. if (_this.ruleType == 0) {
  183. if (_this.upActiveVal || this.upActiveValArr.length) {
  184. let salesPromoSnList = []
  185. // 不参与
  186. if (this.upActiveVal == '-1') {
  187. salesPromoSnList = []
  188. } else {
  189. salesPromoSnList = this.upActiveVal ? [this.upActiveVal] : this.upActiveValArr
  190. }
  191. _this.confirmLoading = true
  192. _this.$emit('batchOk', { salesPromoSnList, salesBillDetailSnList: this.productType == 0 ? this.salesBillDetailSnList : undefined })
  193. } else {
  194. _this.$message.info('请选择活动规则!')
  195. }
  196. } else {
  197. // 全部规则
  198. _this.confirmLoading = true
  199. const salesPromoSnList = this.activeList.map(item => item.salesPromoSn)
  200. _this.$emit('batchOk', { salesPromoSnList, salesBillDetailSnList: this.productType == 0 ? this.salesBillDetailSnList : undefined })
  201. }
  202. },
  203. resetData () {
  204. this.upActiveVal = null
  205. this.upActiveValArr = []
  206. this.salesBillDetailSnList = []
  207. this.productType = '0'
  208. this.ruleType = '0'
  209. },
  210. cancel () {
  211. if (!this.confirmLoading) {
  212. this.opened = false
  213. this.resetData()
  214. this.$emit('cancel')
  215. } else {
  216. this.$message.info('正在更换促销,请勿关闭!')
  217. }
  218. }
  219. },
  220. watch: {
  221. show (newValue, oldValue) {
  222. this.opened = newValue
  223. if (!newValue) {
  224. this.upActiveVal = null
  225. }
  226. }
  227. }
  228. }
  229. </script>