多租户商城-商户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.4 KiB

2 years ago
1 year ago
2 years ago
1 year ago
2 years ago
  1. import { directive, Swiper, SwiperSlide } from 'vue-awesome-swiper'
  2. import {funMixin} from '../../config/mixin'
  3. import 'swiper/css/swiper.css'
  4. import api from '../../config/api'
  5. import { mapGetters } from 'vuex'
  6. export const commonMixin = {
  7. name: 'productList',
  8. mixins: [funMixin],
  9. props: {
  10. terminal: {
  11. type: Number,
  12. default: 4
  13. },
  14. typeId: {
  15. type: Number,
  16. default: 1
  17. },
  18. shopId: {
  19. type: Number,
  20. default: 0
  21. },
  22. componentContent: {
  23. type: Object
  24. }
  25. },
  26. components: {
  27. Swiper,
  28. SwiperSlide
  29. },
  30. directives: {
  31. swiper: directive
  32. },
  33. data () {
  34. return {
  35. productData: []
  36. }
  37. },
  38. watch: {
  39. 'productNum': {
  40. handler(newVal, oldVal) {
  41. this.getData()
  42. },
  43. deep: true
  44. }
  45. },
  46. mounted() {
  47. this.getData(true)
  48. },
  49. computed: {
  50. ...mapGetters([
  51. 'productNum'
  52. ]),
  53. swiper() {
  54. if(this.$refs.mySwiper){
  55. return this.$refs.mySwiper.$swiper
  56. }
  57. }
  58. },
  59. methods: {
  60. getData(isFirst) {
  61. const _ = this
  62. if (_.componentContent.productData.sourceType === '1') {
  63. if(_.componentContent.productData.productIdList && _.componentContent.productData.productIdList.length>0){
  64. this.beforeGetData()
  65. _.sendReq({
  66. url: `${api.getProducts}?page=1&pageSize=99&ids=${_.componentContent.productData.productIdList}`,
  67. method: 'GET'
  68. }, (proRes) => {
  69. _.afterGetData()
  70. _.productData = proRes.data.list
  71. if(isFirst){
  72. _.componentContent.productData.imgTextData = _.productData
  73. }
  74. },(err)=>{
  75. _.afterGetData()
  76. })
  77. } else {
  78. _.productData = []
  79. }
  80. } else if(_.componentContent.productData.sourceType === '2'){
  81. if(_.componentContent.productData.categoryId) {
  82. this.beforeGetData()
  83. _.sendReq({
  84. url: `${api.getProducts}?page=1&pageSize=20&classifyId=${_.componentContent.productData.categoryId}`,
  85. method: 'GET'
  86. }, (proRes) => {
  87. _.afterGetData()
  88. _.productData = proRes.data.list
  89. if(isFirst){
  90. _.componentContent.productData.imgTextData = _.productData
  91. }
  92. // _.swiper.update()
  93. },(err)=>{
  94. _.afterGetData()
  95. })
  96. } else {
  97. _.productData = {
  98. products:[]
  99. }
  100. }
  101. }else if(_.componentContent.productData.sourceType === '3'){
  102. this.beforeGetData()
  103. _.sendReq({
  104. url: `${api.getProducts}?page=1&pageSize=20&type=4`,
  105. method: 'GET'
  106. }, (proRes) => {
  107. _.afterGetData()
  108. _.productData = proRes.data.list
  109. if(isFirst){
  110. _.componentContent.productData.imgTextData = _.productData
  111. }
  112. // _.swiper.update()
  113. },(err)=>{
  114. _.afterGetData()
  115. })
  116. }else if(_.componentContent.productData.sourceType === '4'){
  117. this.beforeGetData()
  118. _.sendReq({
  119. url: `${api.getProducts}?page=1&pageSize=20&type=5`,
  120. method: 'GET'
  121. }, (proRes) => {
  122. _.afterGetData()
  123. _.productData = proRes.data.list
  124. if(isFirst){
  125. _.componentContent.productData.imgTextData = _.productData
  126. }
  127. // _.swiper.update()
  128. },(err)=>{
  129. _.afterGetData()
  130. })
  131. }else if(_.componentContent.productData.sourceType === '5'){
  132. this.beforeGetData()
  133. _.sendReq({
  134. url: `${api.getProducts}?page=1&pageSize=20&type=6`,
  135. method: 'GET'
  136. }, (proRes) => {
  137. _.afterGetData()
  138. _.productData = proRes.data.list
  139. if(isFirst){
  140. _.componentContent.productData.imgTextData = _.productData
  141. }
  142. // _.swiper.update()
  143. },(err)=>{
  144. _.afterGetData()
  145. })
  146. }else if(_.componentContent.productData.sourceType === '6'){
  147. this.beforeGetData()
  148. _.sendReq({
  149. url: `${api.getProducts}?page=1&pageSize=6&type=7`,
  150. method: 'GET'
  151. }, (proRes) => {
  152. _.afterGetData()
  153. _.productData = proRes.data.list
  154. if(isFirst){
  155. _.componentContent.productData.imgTextData = _.productData
  156. }
  157. // _.swiper.update()
  158. },(err)=>{
  159. _.afterGetData()
  160. })
  161. }
  162. },
  163. }
  164. }