myGift.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. if (!this.userId) {
  103. this.$u.toast('用户未登录')
  104. return
  105. }
  106. this.init()
  107. },
  108. onShow() {
  109. this.init()
  110. },
  111. methods: {
  112. init(){
  113. if (!this.userId) {
  114. this.$u.toast('用户未登录')
  115. return
  116. }
  117. this.getMineGiftList()
  118. },
  119. getMineGiftList(){
  120. this.$u.api.goods.getMineGoods({userId:this.userId}).then(res=>{
  121. this.giftList=res.records
  122. this.giftList.forEach(item=>{
  123. item.selected=false
  124. item.exCount=item.count
  125. })
  126. })
  127. },
  128. getDoneGift(distributionStatus){
  129. this.$u.api.goods.doneList({userId:this.userId,distributionStatus}).then(res=>{
  130. this.doneList=res.records
  131. })
  132. },
  133. change(index) {
  134. this.current = index;
  135. if(index==1){
  136. this.getDoneGift(0)
  137. }
  138. if (index==2) {
  139. this.getDoneGift(1)
  140. }
  141. },
  142. select(item) {
  143. item.selected=!item.selected
  144. let flag = true;
  145. for (let item of this.giftList) {
  146. if (!item.selected) {
  147. flag = false;
  148. }
  149. }
  150. this.selectAllShow = flag;
  151. this.$forceUpdate()
  152. },
  153. selectAll() {
  154. this.selectAllShow = !this.selectAllShow;
  155. for (let item of this.giftList) {
  156. if (this.selectAllShow) {
  157. item.selected = true;
  158. } else {
  159. item.selected = false;
  160. }
  161. }
  162. },
  163. donate() {
  164. let flag=false
  165. this.giftList.forEach(item=>{
  166. if (item.selected) {
  167. flag=true
  168. }
  169. })
  170. if (!flag) {
  171. uni.showToast({
  172. title:"请至少选择一个礼物!",
  173. icon:"none"
  174. })
  175. return
  176. }
  177. let newList=this.getSelectGoods()
  178. this.$dialog.showModal("确认捐赠?").then(()=>{
  179. this.$u.api.goods.donate(newList).then(res=>{
  180. // this.successList=res.records
  181. this.dialogShow=true
  182. })
  183. })
  184. },
  185. getSelectGoods(){
  186. let newList=[]
  187. this.giftList.forEach(item=>{
  188. if (item.selected) {
  189. let obj={
  190. id:item.id,
  191. userId:item.userId,
  192. goodsId:item.goodsId,
  193. activityIds:item.activityIds,
  194. count:item.exCount
  195. }
  196. newList.push(obj)
  197. }
  198. })
  199. return newList
  200. },
  201. confirm(){
  202. this.dialogShow = false;
  203. this.getMineGiftList()
  204. },
  205. gains(item){
  206. this.$dialog.showModal("确认收货?").then(()=>{
  207. let data= this.$u.deepClone(item)
  208. data.distributionStatus=1
  209. this.$u.api.goods.done(data).then(res=>{
  210. this.getDoneGift(0)
  211. })
  212. })
  213. },
  214. navTap() {
  215. let newList=[]
  216. this.giftList.forEach(item=>{
  217. if (item.selected) {
  218. let obj={
  219. id:item.id,
  220. userId:item.userId,
  221. goodsId:item.goodsId,
  222. activityIds:item.activityIds,
  223. count:item.exCount,
  224. goodsPic:item.goods.goodsPic,
  225. goodsName:item.goods.goodsName,
  226. }
  227. newList.push(obj)
  228. }
  229. })
  230. if (this.$u.test.isEmpty(newList)) {
  231. this.$u.toast("请至少选择一个礼物")
  232. return
  233. }
  234. let params=JSON.stringify(newList)
  235. uni.navigateTo({
  236. url: '/pages/activityList/mine/order/orderConfirm?goods='+params
  237. })
  238. },
  239. //礼物+
  240. plus(item) {
  241. if (item.exCount<item.count) {
  242. item.exCount++
  243. }
  244. this.$forceUpdate()
  245. },
  246. //礼物 -
  247. minus(item) {
  248. if (item.exCount>1) {
  249. item.exCount--
  250. }
  251. this.$forceUpdate()
  252. },
  253. }
  254. }
  255. </script>
  256. <style lang="scss" scoped>
  257. .card {
  258. margin: 20upx;
  259. border-radius: 16upx;
  260. background-color: #FFFFFF;
  261. .title {
  262. font-size: 28upx;
  263. font-family: PingFang SC;
  264. font-weight: 800;
  265. color: #222222;
  266. }
  267. .name {
  268. font-size: 26upx;
  269. font-family: PingFang SC;
  270. font-weight: 800;
  271. color: #222222;
  272. }
  273. .specification {
  274. padding-top: 30upx;
  275. font-size: 24upx;
  276. font-family: PingFang SC;
  277. font-weight: bold;
  278. color: #959595;
  279. }
  280. .count {
  281. width: 60upx;
  282. height: 60upx;
  283. border-radius: 16upx;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. }
  288. }
  289. .input {
  290. width: 80upx;
  291. background-color: #ffffff;
  292. text-align: center;
  293. border: none;
  294. height: 60rpx;
  295. min-height: 1.8rem;
  296. }
  297. .custom-style {
  298. background-color: #5b3ee7;
  299. width: 250upx;
  300. color: #ffffff;
  301. }
  302. .custom-style-sm {
  303. background-color: #5b3ee7;
  304. color: #ffffff;
  305. }
  306. </style>