orderButton.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template name="button">
  2. <view class="button-template" :style="{ paddingBottom: isIphoneX ? '68rpx' : '0rpx' }">
  3. <!-- 底部按钮 -->
  4. <view class="button-content">
  5. <view class="btn btn-pay" v-if="btnState.isPay" @click.stop="btnConfirm('pay', order)">付款</view>
  6. <view class="btn btn-pay" v-if="btnState.isConfirm" @click.stop="btnConfirm('confirm', order)"
  7. >确认收货</view
  8. >
  9. <view class="btn btn-pay" v-if="btnState.isAgain" @click.stop="btnConfirm('again', order)">再次购买</view>
  10. <view class="btn btn-cancel" v-if="btnState.isCancel" @click.stop="btnConfirm('cancel', order)"
  11. >取消订单</view
  12. >
  13. <view class="btn btn-cancel" v-if="btnState.isDelete" @click.stop="btnConfirm('delete', order)"
  14. >删除订单</view
  15. >
  16. <view class="btn btn-cancel" v-if="btnState.isQuery" @click.stop="btnConfirm('query', order)"
  17. >查看物流</view
  18. >
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'button',
  25. props: {
  26. status: {
  27. type: Number
  28. },
  29. order: {
  30. type: Object
  31. },
  32. shareCode: {
  33. type: String
  34. }
  35. },
  36. watch: {
  37. status: {
  38. handler: function(val) {
  39. this.initData(val)
  40. },
  41. deep: true //对象内部的属性监听,也叫深度监听
  42. }
  43. },
  44. data() {
  45. return {
  46. btnState: this.initStatus(),
  47. isIphoneX: this.$store.getters.isIphoneX,
  48. mapStateArr: [
  49. { label: 'isQuery', val: [4, 5, 12, 13, 33, 22, 23, 32, 77], status: true },
  50. { label: 'isDelete', val: [6], status: true },
  51. { label: 'isCancel', val: [0, 111], status: true },
  52. { label: 'isConfirm', val: [33], status: true },
  53. { label: 'isAgain', val: [33], status: true },
  54. { label: 'isPay', val: [11, 12, 13, 21, 22, 23, 111], status: true }
  55. ]
  56. }
  57. },
  58. created() {
  59. this.initData(this.status)
  60. },
  61. computed: {},
  62. methods: {
  63. initData(resVal) {
  64. /**
  65. * @分享按钮统一显示
  66. * @按钮根据状态显示
  67. * @(4、5、7、12、22、23、32)显示[查看物流]按钮,其他隐藏
  68. * @(6)显示[删除订单],其他隐藏
  69. * @(0、111)显示[取消订单],其他隐藏
  70. * @(21,31)只显示分享
  71. * @(13,33)显示[确认收货]和[查看物流]
  72. */
  73. this.btnState = this.initStatus()
  74. this.mapStateArr.forEach(el => {
  75. el.val.forEach(value => {
  76. if (resVal === value) {
  77. this.btnState[el.label] = el.status
  78. }
  79. })
  80. })
  81. },
  82. initStatus() {
  83. let btnState = {
  84. isQuery: false,
  85. isDelete: false,
  86. isCancel: false,
  87. isConfirm: false,
  88. isAgain: false
  89. }
  90. return btnState
  91. },
  92. btnConfirm(type, order) {
  93. let data = {
  94. type: type,
  95. orderId: order.orderId,
  96. order: order
  97. }
  98. this.$emit('buttonConfirm', data)
  99. }
  100. }
  101. }
  102. </script>
  103. <style lang="scss">
  104. .button-template {
  105. width: 100%;
  106. height: auto;
  107. position: fixed;
  108. bottom: 0;
  109. left: 0;
  110. background: #ffffff;
  111. .button-content {
  112. padding: 0 24rpx;
  113. height: auto;
  114. float: right;
  115. position: relative;
  116. .share-code {
  117. width: 200rpx;
  118. height: 64rpx;
  119. line-height: 64rpx;
  120. color: #2a45ff;
  121. text-align: left;
  122. position: absolute;
  123. font-size: $font-size-28;
  124. font-weight: bold;
  125. left: 24rpx;
  126. top: 24rpx;
  127. }
  128. .btn {
  129. width: 160rpx;
  130. height: 64rpx;
  131. margin: 22rpx 22rpx 22rpx 0;
  132. line-height: 64rpx;
  133. font-size: $font-size-26;
  134. color: #333333;
  135. text-align: center;
  136. float: right;
  137. border: 2rpx solid #333333;
  138. border-radius: 34rpx;
  139. &.btn-pay {
  140. border-color: $color-system;
  141. color: $color-system;
  142. }
  143. &.btn-cancel {
  144. text-align: center;
  145. }
  146. }
  147. }
  148. }
  149. </style>