chooseBrandModal.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseBrand-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="选择产品品牌"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <div class="chooseBrand-con">
  12. <div>
  13. <a-checkbox :checked="checkAll" :disabled="disabledList.length>0" @change="onCheckAllChange">全选</a-checkbox>
  14. <span v-if="pageType==='1'">
  15. <a-checkbox :checked="checkOwn" @change="onCheckOwnChange">自主品牌</a-checkbox>
  16. <a-checkbox :checked="checkAgent" @change="onCheckAgentChange">代理品牌</a-checkbox>
  17. </span>
  18. </div>
  19. <a-divider style="margin:10px 0;" />
  20. <a-row style="height: 400px;overflow-y: scroll;">
  21. <a-col :span="6" v-for="(item,index) in brandList" :key="item.brandSn">
  22. <a-checkbox :checked="item.checked" :disabled="item.isDisabled" @change="e=>onChange(e,index)">
  23. {{ item.brandName }}
  24. </a-checkbox>
  25. </a-col>
  26. </a-row>
  27. <!-- 按钮 -->
  28. <div class="btn-con">
  29. <a-button
  30. id="chooseBrand-cancel"
  31. class="button-cancel"
  32. @click="isShow=false"
  33. style="padding: 0 30px;">取消</a-button>
  34. <a-button
  35. type="primary"
  36. id="chooseBrand-submit"
  37. @click="handleSave"
  38. style="padding: 0 30px;margin-left: 15px;">保存</a-button>
  39. </div>
  40. </div>
  41. </a-modal>
  42. </template>
  43. <script>
  44. import { productBrandQuery } from '@/api/productBrand'
  45. export default {
  46. name: 'ChooseBrandModal',
  47. props: {
  48. openModal: { // 弹框显示状态
  49. type: Boolean,
  50. default: false
  51. },
  52. chooseData: {
  53. type: Array,
  54. default: () => {
  55. return []
  56. }
  57. },
  58. pageType: { // 弹框显示状态
  59. type: [String, Number],
  60. default: ''
  61. }
  62. },
  63. data () {
  64. return {
  65. isShow: this.openModal, // 是否打开弹框
  66. checkAll: false, // 全选
  67. checkOwn: false, // 自主品牌
  68. checkAgent: false, // 代理品牌
  69. checkedList: [], // 选中项
  70. checkedRowList: [], // 选中项
  71. brandList: [], // 品牌数据
  72. brandOwnList: [],
  73. brandAgentList: [],
  74. disabledList: []
  75. }
  76. },
  77. methods: {
  78. // 保存
  79. handleSave () {
  80. const _this = this
  81. this.checkedRowList = []
  82. _this.brandList.map(item => {
  83. if (item.checked) {
  84. _this.checkedRowList.push(item)
  85. }
  86. })
  87. if (this.checkedRowList.length < 1) {
  88. this.$message.warning('请在列表勾选后再进行操作!')
  89. return
  90. }
  91. this.$emit('ok', this.checkedRowList)
  92. this.isShow = false
  93. },
  94. // change
  95. onChange (e, pos) {
  96. this.brandList[pos].checked = e.target.checked
  97. // 全选
  98. const isCheckAllFlag = this.brandList.every(item => item.checked)
  99. if (isCheckAllFlag) {
  100. this.checkAll = true
  101. } else {
  102. this.checkAll = false
  103. }
  104. // 自主
  105. const isCheckOwnFlag = this.brandList.every(item => {
  106. if (item.brandType == 1) {
  107. return item.checked
  108. }
  109. })
  110. if (isCheckOwnFlag) {
  111. this.checkOwn = true
  112. } else {
  113. this.checkOwn = false
  114. }
  115. // 代理
  116. const isCheckAgentFlag = this.brandList.every(item => {
  117. if (item.brandType == 2) {
  118. return item.checked
  119. }
  120. })
  121. if (isCheckAgentFlag) {
  122. this.checkAgent = true
  123. } else {
  124. this.checkAgent = false
  125. }
  126. this.$forceUpdate()
  127. },
  128. // 全选
  129. onCheckAllChange (e) {
  130. const _this = this
  131. this.checkAll = e.target.checked
  132. this.checkOwn = false
  133. this.checkAgent = false
  134. if (e.target.checked) {
  135. this.brandList.forEach(item => {
  136. item.checked = true
  137. })
  138. } else {
  139. this.brandList.map(con => {
  140. con.checked = false
  141. })
  142. }
  143. },
  144. onCheckOwnChange (e) {
  145. const _this = this
  146. this.checkAll = false
  147. this.checkOwn = e.target.checked
  148. this.checkAgent = false
  149. const disArr = _this.chooseData.map(item => item.goodsSn)
  150. if (e.target.checked) {
  151. this.brandList.forEach(item => {
  152. item.checked = false
  153. if (item.brandType == 1) {
  154. item.checked = true
  155. }
  156. if (this.disabledList && this.disabledList.length > 0) {
  157. if (this.disabledList.includes(item.brandSn)) {
  158. item.checked = false
  159. }
  160. }
  161. if (this.chooseData && this.chooseData.length > 0) {
  162. if (disArr.includes(item.brandSn)) {
  163. item.checked = true
  164. }
  165. }
  166. })
  167. } else {
  168. this.brandList.forEach(con => {
  169. if (con.brandType == 1) {
  170. con.checked = false
  171. }
  172. if (this.disabledList && this.disabledList.length > 0) {
  173. if (this.disabledList.includes(con.brandSn)) {
  174. con.checked = false
  175. }
  176. }
  177. if (this.chooseData && this.chooseData.length > 0) {
  178. if (disArr.includes(con.brandSn)) {
  179. con.checked = true
  180. }
  181. }
  182. })
  183. }
  184. },
  185. onCheckAgentChange (e) {
  186. const _this = this
  187. this.checkAll = false
  188. this.checkOwn = false
  189. this.checkAgent = e.target.checked
  190. const disArr = _this.chooseData.map(item => item.goodsSn)
  191. if (e.target.checked) {
  192. this.brandList.forEach(item => {
  193. item.checked = false
  194. if (item.brandType == 2) {
  195. item.checked = true
  196. }
  197. if (this.disabledList && this.disabledList.length > 0) {
  198. if (this.disabledList.includes(item.brandSn)) {
  199. item.checked = false
  200. }
  201. }
  202. if (this.chooseData && this.chooseData.length > 0) {
  203. if (disArr.includes(item.brandSn)) {
  204. item.checked = true
  205. }
  206. }
  207. })
  208. } else {
  209. this.brandList.forEach(con => {
  210. if (con.brandType == 2) {
  211. con.checked = false
  212. }
  213. if (this.disabledList && this.disabledList.length > 0) {
  214. if (this.disabledList.includes(con.brandSn)) {
  215. con.checked = false
  216. }
  217. }
  218. if (this.chooseData && this.chooseData.length > 0) {
  219. if (disArr.includes(con.brandSn)) {
  220. con.checked = true
  221. }
  222. }
  223. })
  224. }
  225. },
  226. // 获取品牌数据
  227. getBrandList () {
  228. const _this = this
  229. productBrandQuery({}).then(res => {
  230. if (res.status == 200) {
  231. if (_this.chooseData && _this.chooseData.length > 0) {
  232. const checkedList = []
  233. _this.chooseData.map(item => {
  234. checkedList.push(item.goodsSn)
  235. })
  236. res.data.map(item => {
  237. if (checkedList.includes(item.brandSn)) {
  238. item.checked = true
  239. } else {
  240. item.checked = false
  241. }
  242. })
  243. }
  244. if (_this.disabledList && _this.disabledList.length > 0) {
  245. res.data.map(item => {
  246. if (_this.disabledList.includes(item.brandSn)) {
  247. item.isDisabled = true
  248. } else {
  249. item.isDisabled = false
  250. }
  251. })
  252. }
  253. _this.brandList = res.data
  254. } else {
  255. this.brandList = []
  256. }
  257. })
  258. },
  259. // 禁用
  260. handleDisabled (list) {
  261. this.disabledList = list
  262. }
  263. },
  264. watch: {
  265. // 父页面传过来的弹框状态
  266. openModal (newValue, oldValue) {
  267. this.isShow = newValue
  268. },
  269. // 重定义的弹框状态
  270. isShow (newValue, oldValue) {
  271. if (!newValue) {
  272. this.$emit('close')
  273. this.checkAll = false
  274. this.checkOwn = false
  275. this.checkAgent = false
  276. this.brandList.map(item => {
  277. item.checked = false
  278. })
  279. } else {
  280. const _this = this
  281. _this.getBrandList()
  282. }
  283. }
  284. }
  285. }
  286. </script>
  287. <style lang="less" scoped>
  288. .chooseBrand-modal{
  289. .chooseBrand-con{
  290. .btn-con{
  291. text-align: center;
  292. margin: 30px 0 20px;
  293. .button-cancel{
  294. font-size: 12px;
  295. }
  296. }
  297. }
  298. }
  299. </style>