myGift.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <view>
  3. <u-sticky h5-nav-height="0">
  4. <u-tabs :list="list" active-color="#5c40e8" :is-scroll="false" :current="current" @change="change"></u-tabs>
  5. </u-sticky>
  6. <view v-if="current == 0">
  7. <block v-if="!$u.test.isEmpty(giftList)">
  8. <block v-for="(item, index) in giftList" :key="index">
  9. <view class="card" @click="select(item)">
  10. <view class="flex">
  11. <view :class="item.selected==true ? 'theme-color cuIcon-roundcheckfill':'cuIcon-round'" class="padding-sm" style="font-size: 50upx;"></view>
  12. <view class="padding-tb-sm">
  13. <view class="flex margin-top-xs">
  14. <image :src="item.goods.goodsPic" style="width: 220upx;height: 220upx;border-radius: 10rpx;"></image>
  15. <view class="padding-left-sm">
  16. <view class="name text-cut" style="width: 350upx;">{{item.goods.goodsName}}</view>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="flex justify-end padding" style="margin-top: -110upx;">
  22. <view class="count" style="border: #d9d9d9 1upx solid;" v-if="!item.selected">x{{item.exCount}}</view>
  23. <view class="justify-center flex align-center" v-else>
  24. <view class="" @click.stop="minus(item)"> <u-icon name="minus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  25. <input type="number" class="text-center input" v-model="item.exCount" />
  26. <view class="" @click.stop="plus(item)"> <u-icon name="plus-circle-fill" color="#5a3ee8" size="36"></u-icon> </view>
  27. </view>
  28. </view>
  29. </view>
  30. </block>
  31. <view style="height: 120upx;"></view>
  32. <view style="z-index: 9;" class="footer-fixed flex align-center justify-between padding-sm bg-white">
  33. <view class="flex align-center" @click="selectAll">
  34. <view :class="selectAllShow ? 'theme-color cuIcon-roundcheckfill':'cuIcon-round'" class="padding-right-xs" style="font-size: 50upx;"></view>
  35. <view class="text-sm padding-right-xs">全选</view>
  36. </view>
  37. <view>
  38. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;margin-right: 30upx;" @click="donate">捐赠</button>
  39. <button class="cu-btn round text-white theme-bg-color" style="width: 180upx;height: 80upx;" @click="navTap">领取</button>
  40. </view>
  41. </view>
  42. </block>
  43. <u-empty v-else margin-top="300" text="暂无礼物" mode="list"></u-empty>
  44. </view>
  45. <view v-if="current == 1 || current==2">
  46. <block v-for="(item, index) in doneList" :key="index">
  47. <view class="card" >
  48. <view class="padding">
  49. <view class="flex margin-top-xs">
  50. <image :src="item.goodsPic" style="width: 220upx;height: 220upx"></image>
  51. <view class="padding-left-sm">
  52. <view class="name text-cut" style="width: 350upx;">{{item.goodsName}}</view>
  53. </view>
  54. </view>
  55. </view>
  56. <view class="flex justify-end padding" style="margin-top: -120upx;">
  57. <view class="count">x{{item.count}}</view>
  58. </view>
  59. <view v-if="current==1" class="flex justify-end" style="padding:0 20rpx 15rpx;">
  60. <view class="">
  61. <u-button size="mini" class="custom-style-sm" shape="circle" @click="gains(item)">确认收货</u-button>
  62. </view>
  63. </view>
  64. </view>
  65. </block>
  66. </view>
  67. <u-popup v-model="dialogShow" mode="center" width="500" height="480" border-radius="30">
  68. <view class="bg-img text-center" style="background-image: url('https://upload-file-data.obs.cn-south-1.myhuaweicloud.com/e914f556be414767aca011a30961560a-dialogBgImg.png');height: 600rpx;">
  69. <view style="height: 80upx;"></view>
  70. <view style="font-size: 50upx;font-family: PingFang SC;font-weight: 600;color: #ffffff;">感谢你</view>
  71. <view class="text-bold text-black" style="padding: 80upx 0;">广发基金会已收到您的捐赠!</view>
  72. <view class="padding">
  73. <u-button class="custom-style" shape="circle" @click="confirm">确定</u-button>
  74. </view>
  75. </view>
  76. </u-popup>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. userId: '',
  84. successList:[],
  85. list: [{
  86. name: '待领取'
  87. }, {
  88. name: '配送中'
  89. }, {
  90. name: '已完成'
  91. }],
  92. current: 0,
  93. selectAllShow: false,
  94. clickShow: false,
  95. giftList: [],
  96. doneList:[],
  97. dialogShow: false,
  98. }
  99. },
  100. onLoad() {
  101. this.userId = uni.getStorageSync("userId");
  102. this.init()
  103. },
  104. onShow() {
  105. this.init()
  106. },
  107. methods: {
  108. init(){
  109. if (!this.userId) {
  110. this.$u.toast('用户未登录')
  111. return
  112. }
  113. this.getMineGiftList()
  114. },
  115. getMineGiftList(){
  116. this.$u.api.goods.getMineGoods({userId:this.userId}).then(res=>{
  117. this.giftList=res.records
  118. this.giftList.forEach(item=>{
  119. item.selected=false
  120. item.exCount=item.count
  121. })
  122. })
  123. },
  124. getDoneGift(distributionStatus){
  125. this.$u.api.goods.doneList({userId:this.userId,distributionStatus}).then(res=>{
  126. this.doneList=res.records
  127. })
  128. },
  129. change(index) {
  130. this.current = index;
  131. if(index==1){
  132. this.getDoneGift(0)
  133. }
  134. if (index==2) {
  135. this.getDoneGift(1)
  136. }
  137. },
  138. select(item) {
  139. item.selected=!item.selected
  140. let flag = true;
  141. for (let item of this.giftList) {
  142. if (!item.selected) {
  143. flag = false;
  144. }
  145. }
  146. this.selectAllShow = flag;
  147. this.$forceUpdate()
  148. },
  149. selectAll() {
  150. this.selectAllShow = !this.selectAllShow;
  151. for (let item of this.giftList) {
  152. if (this.selectAllShow) {
  153. item.selected = true;
  154. } else {
  155. item.selected = false;
  156. }
  157. }
  158. },
  159. donate() {
  160. let flag=false
  161. this.giftList.forEach(item=>{
  162. if (item.selected) {
  163. flag=true
  164. }
  165. })
  166. if (!flag) {
  167. uni.showToast({
  168. title:"请至少选择一个礼物!",
  169. icon:"none"
  170. })
  171. return
  172. }
  173. let newList=this.getSelectGoods()
  174. this.$dialog.showModal("确认捐赠?").then(()=>{
  175. this.$u.api.goods.donate(newList).then(res=>{
  176. // this.successList=res.records
  177. this.dialogShow=true
  178. })
  179. })
  180. },
  181. getSelectGoods(){
  182. let newList=[]
  183. this.giftList.forEach(item=>{
  184. if (item.selected) {
  185. let obj={
  186. id:item.id,
  187. userId:item.userId,
  188. goodsId:item.goodsId,
  189. activityIds:item.activityIds,
  190. count:item.exCount
  191. }
  192. newList.push(obj)
  193. }
  194. })
  195. return newList
  196. },
  197. confirm(){
  198. this.dialogShow = false;
  199. this.getMineGiftList()
  200. },
  201. gains(item){
  202. this.$dialog.showModal("确认收货?").then(()=>{
  203. let data= this.$u.deepClone(item)
  204. data.distributionStatus=1
  205. this.$u.api.goods.done(data).then(res=>{
  206. this.getDoneGift(0)
  207. })
  208. })
  209. },
  210. navTap() {
  211. let newList=[]
  212. this.giftList.forEach(item=>{
  213. if (item.selected) {
  214. let obj={
  215. id:item.id,
  216. userId:item.userId,
  217. goodsId:item.goodsId,
  218. activityIds:item.activityIds,
  219. count:item.exCount,
  220. goodsPic:item.goods.goodsPic,
  221. goodsName:item.goods.goodsName,
  222. }
  223. newList.push(obj)
  224. }
  225. })
  226. if (this.$u.test.isEmpty(newList)) {
  227. this.$u.toast("请至少选择一个礼物")
  228. return
  229. }
  230. let params=JSON.stringify(newList)
  231. uni.navigateTo({
  232. url: '/pages/activityList/mine/order/orderConfirm?goods='+params
  233. })
  234. },
  235. //礼物+
  236. plus(item) {
  237. if (item.exCount<item.count) {
  238. item.exCount++
  239. }
  240. this.$forceUpdate()
  241. },
  242. //礼物 -
  243. minus(item) {
  244. if (item.exCount>1) {
  245. item.exCount--
  246. }
  247. this.$forceUpdate()
  248. },
  249. }
  250. }
  251. </script>
  252. <style lang="scss" scoped>
  253. .card {
  254. margin: 20upx;
  255. border-radius: 16upx;
  256. background-color: #FFFFFF;
  257. .title {
  258. font-size: 28upx;
  259. font-family: PingFang SC;
  260. font-weight: 800;
  261. color: #222222;
  262. }
  263. .name {
  264. font-size: 26upx;
  265. font-family: PingFang SC;
  266. font-weight: 800;
  267. color: #222222;
  268. }
  269. .specification {
  270. padding-top: 30upx;
  271. font-size: 24upx;
  272. font-family: PingFang SC;
  273. font-weight: bold;
  274. color: #959595;
  275. }
  276. .count {
  277. width: 60upx;
  278. height: 60upx;
  279. border-radius: 16upx;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. }
  284. }
  285. .input {
  286. width: 80upx;
  287. background-color: #ffffff;
  288. text-align: center;
  289. border: none;
  290. height: 60rpx;
  291. min-height: 1.8rem;
  292. }
  293. .custom-style {
  294. background-color: #5b3ee7;
  295. width: 250upx;
  296. color: #ffffff;
  297. }
  298. .custom-style-sm {
  299. background-color: #5b3ee7;
  300. color: #ffffff;
  301. }
  302. </style>