list-button.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template name="button">
  2. <view class="button-template">
  3. <!-- 底部按钮 -->
  4. <view class="button-content">
  5. <view class="btn btn-confirm" v-if="btnState.isConfirm" @click.stop="btnConfirm">操作</view>
  6. </view>
  7. <tui-actionsheet
  8. :show="showActionSheet"
  9. :tips="tips"
  10. :item-list="itemList"
  11. :mask-closable="maskClosable"
  12. :color="color"
  13. :size="size"
  14. :is-cancel="isCancel"
  15. @click="handleClickItem"
  16. @cancel="closeActionSheet"
  17. ></tui-actionsheet>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'button',
  23. props: {
  24. status: {
  25. type: Number
  26. },
  27. dataInfo: {
  28. type: Object
  29. }
  30. },
  31. data() {
  32. return {
  33. payment:{},
  34. btnState: this.initStatus(),
  35. mapStateArr: [{ label: 'isConfirm', val: [0], status: true }],
  36. souStateArr:[
  37. {
  38. type:1,
  39. action:[
  40. { text: '作废',handleId:0},
  41. { text: '设为返佣款',handleId:2},
  42. { text: '设为供应商退款',handleId:3},
  43. ],
  44. },
  45. {
  46. type:2,
  47. action:[
  48. { text: '作废',handleId:0},
  49. { text: '设为普通款',handleId:1},
  50. { text: '设为返佣款',handleId:2},
  51. { text: '设为供应商退款',handleId:3}
  52. ],
  53. },
  54. {
  55. type:3,
  56. action:[
  57. { text: '作废',handleId:0},
  58. { text: '设为普通款',handleId:1},
  59. { text: '设为供应商退款',handleId:3}
  60. ],
  61. },
  62. {
  63. type:4,
  64. action:[
  65. { text: '作废',handleId:0},
  66. { text: '设为普通款',handleId:1},
  67. { text: '设为返佣款',handleId:2}
  68. ],
  69. },
  70. ],
  71. showActionSheet: false,
  72. maskClosable: true,
  73. tips: '',
  74. itemList: [],
  75. color: '#9a9a9a',
  76. size: 24,
  77. isCancel: true
  78. }
  79. },
  80. created() {
  81. this.initData(this.status,this.dataInfo)
  82. },
  83. computed: {},
  84. watch: {
  85. status: {
  86. handler: function(val) {
  87. this.initData(val)
  88. },
  89. deep: true //对象内部的属性监听,也叫深度监听
  90. }
  91. },
  92. methods: {
  93. initData(resVal,dataVal) {
  94. /**
  95. * @分享按钮统一显示
  96. * @按钮根据状态显示
  97. * @(4、5、7、12、22、23、32)显示[查看物流]按钮,其他隐藏
  98. * @(6)显示[删除订单],其他隐藏
  99. * @(0、111)显示[取消订单],其他隐藏
  100. * @(21,31)只显示分享
  101. * @(13,33)显示[确认收货]和[查看物流]
  102. */
  103. this.payment = dataVal
  104. this.btnState = this.initStatus()
  105. this.mapStateArr.forEach(el => {
  106. el.val.forEach(value => {
  107. if (resVal === value) {
  108. this.btnState[el.label] = el.status
  109. }
  110. })
  111. })
  112. this.initActionSheet(this.payment.sourceType)
  113. },
  114. initActionSheet(dataVal){
  115. this.souStateArr.forEach(el => {
  116. if (dataVal === el.type) {
  117. this.itemList = el.action
  118. }
  119. })
  120. },
  121. initStatus() {
  122. let btnState = {
  123. isConfirm: false
  124. }
  125. return btnState
  126. },
  127. handleClickItem(data){
  128. const handleAction = this.handleArrayReturn(data.index)
  129. const payment ={
  130. handleAction:handleAction,
  131. payment: this.payment
  132. }
  133. this.$emit('buttonConfirm',payment)
  134. this.showActionSheet = false
  135. },
  136. handleArrayReturn(data){// 处理操作后结果
  137. let handleValue = {}
  138. this.souStateArr.forEach(el => {
  139. if(this.payment.sourceType === el.type){
  140. el.action.forEach((value,index) => {
  141. if (data === index) {
  142. handleValue = value
  143. }
  144. })
  145. }
  146. })
  147. return handleValue
  148. },
  149. btnConfirm() {
  150. this.showActionSheet = true
  151. },
  152. closeActionSheet() {
  153. this.showActionSheet = false
  154. },
  155. // btnConfirm(){
  156. // this.$emit('buttonConfirm',data)
  157. // }
  158. }
  159. }
  160. </script>
  161. <style lang="scss">
  162. .button-template {
  163. width: 100%;
  164. height: auto;
  165. float: left;
  166. background: #ffffff;
  167. .button-content {
  168. width: 100%;
  169. height: auto;
  170. float: left;
  171. position: relative;
  172. .btn {
  173. width: 160rpx;
  174. height: 64rpx;
  175. margin: 10rpx 0 0 0;
  176. line-height: 64rpx;
  177. font-size: $font-size-26;
  178. text-align: center;
  179. border-radius: 6rpx;
  180. float: right;
  181. }
  182. .btn-cancel {
  183. background-color: #f6f6f6;
  184. color: #333333;
  185. }
  186. .btn-delete {
  187. background-color: #f6f6f6;
  188. color: #333333;
  189. }
  190. .btn-query {
  191. background-color: #ff5000;
  192. color: #ffffff;
  193. }
  194. .btn-confirm {
  195. background-color: #4688fa;
  196. color: #ffffff;
  197. }
  198. .btn-pay {
  199. background-color: #4688fa;
  200. color: #ffffff;
  201. margin-right: 0;
  202. }
  203. }
  204. }
  205. .tui-actionsheet-btn{
  206. box-sizing: content-box;
  207. }
  208. </style>