mixin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { directive, Swiper, SwiperSlide } from 'vue-awesome-swiper'
  2. import 'swiper/css/swiper.css'
  3. import api from '../../config/api'
  4. import {funMixin} from '../../config/mixin'
  5. import { mapGetters } from 'vuex'
  6. export const commonMixin = {
  7. name: 'price',
  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. composeProducts:[],
  37. rules: [{
  38. price: null,
  39. number: null
  40. }]
  41. }
  42. }
  43. },
  44. computed: {
  45. ...mapGetters([
  46. 'priceNum'
  47. ]),
  48. },
  49. watch: {
  50. 'priceNum': {
  51. handler(newVal, oldVal) {
  52. this.getData()
  53. },
  54. deep: true
  55. }
  56. },
  57. created() {
  58. this.getData()
  59. },
  60. methods: {
  61. getData() {
  62. const _ = this
  63. if(_.componentContent.priceId){
  64. this.beforeGetData()
  65. const params = {
  66. method: 'GET',
  67. url: `${api.getPrices}?shopId=${_.shopId}&ids=${_.componentContent.priceId}`,
  68. }
  69. this.sendReq(params, (res) => {
  70. _.afterGetData()
  71. if( res.data.length > 0){
  72. _.productData = res.data[0]
  73. }
  74. },(err)=>{
  75. _.afterGetData()
  76. })
  77. } else {
  78. _.productData = {
  79. products:[]
  80. }
  81. }
  82. },
  83. }
  84. }