updateActiveModal.vue 8.3 KB

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