box.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view class="box">
  3. <view class="box_head flexs">
  4. <!-- 修改 in 2 改成 in 3 标题名调用titleName方法 -->
  5. <view class="box_head_li center" @click="changeIndex(index)" v-for="(item,index) in 3" :class="{active:index == i}" :key="index">{{ titleName(index) }}</view>
  6. </view>
  7. <!-- 修改 -->
  8. <view class="box_ul">
  9. <!-- 待提货 已回列表 -->
  10. <template v-if="i < 2">
  11. <view class="box_ul_li" v-for="(item,index) in boxList" :key="index" @click="item.flag = !item.flag">
  12. <image class="an" v-if="i == 0" :src="item.flag ? '/static/image/publice/xuanzhong1@2x.png' : '/static/image/me/weixuanzhong@2x.png'" mode=""></image>
  13. <view class="box_ul_li_img">
  14. <image :src="item.goods_image" mode="aspectFill"></image>
  15. </view>
  16. <view class="box_ul_li_main">
  17. <view class="box_ul_li_name">
  18. <!-- 修改 -->
  19. <text>{{ item.goods_name }}</text>
  20. </view>
  21. <view class="box_ul_li_price">
  22. <view class="khj">开盒价:<text>{{ item.box_coin_price }}金币</text></view>
  23. <view class="xsj">销售价:<text>{{ item.goods_coin_price }}金币</text></view>
  24. <view class="hsj">回收价:<text>{{ item.goods_hui_price }}金币</text></view>
  25. </view>
  26. </view>
  27. <view class="box_ul_li_time">
  28. <!-- 修改 -->
  29. <text>时间:{{ item.time }}</text>
  30. <!-- 新增 -->
  31. <view v-if="i == 0" class="item-btn center" @click.stop="donationOpen(item)"> 一键转赠 </view>
  32. </view>
  33. </view>
  34. </template>
  35. <!-- 新增 转赠列表 -->
  36. <template v-else>
  37. <view class="box_ul_li flexs" v-for="(item,index) in donationList" :key="'donation-' + index" @click="item.flag = !item.flag">
  38. <view class="box_ul_li_img">
  39. <image :src="item.zzimage" mode="aspectFill"></image>
  40. </view>
  41. <view class="box_ul_li_main">
  42. <view class="box_ul_li_name">
  43. <!-- 修改 -->
  44. <text>{{ item.boxgoods }}</text>
  45. </view>
  46. <view class="box_ul_li_price flex">
  47. <view class="box_ul_li_time">时间:{{ item.zhuanztime }}</view>
  48. <text style="text-align: right;">已转赠</text>
  49. </view>
  50. <view class="box_ul_li_time">受赠人:{{ item.szuser }}</view>
  51. </view>
  52. </view>
  53. </template>
  54. </view>
  55. <view class="box_footer flex" v-if="i == 0">
  56. <view class="box_footer_all flexs">
  57. <image @click="changeAll" :src="isAll ? '/static/image/publice/xuanzhong1@2x.png' : '/static/image/me/weixuanzhong@2x.png'" mode=""></image>
  58. <text>全选({{ totalNumber }})</text>
  59. </view>
  60. <view class="box_footer_ul flexs">
  61. <view class="box_footer_li center" v-for="(items,index) in 2" :key="index" @click="apply(index)"> {{ index == 0 ? '一键回收' : '申请发货' }} </view>
  62. </view>
  63. </view>
  64. <!-- 新增 转赠窗口 -->
  65. <uni-popup ref="donation">
  66. <view class="donation">
  67. <view class="title">请输入您转赠人的手机号</view>
  68. <view class="input-container">
  69. <input v-model="donationPhone" type="number" placeholder="请输入转赠人注册手机号"/>
  70. </view>
  71. <view class="tip">注:一旦转赠成功不可退货,请谨慎操作</view>
  72. <view class="donation-btns">
  73. <view class="box_footer_li center" @click="$refs.donation.close()"> 取消 </view>
  74. <view class="box_footer_li center" @click="donation()"> 确定 </view>
  75. </view>
  76. </view>
  77. </uni-popup>
  78. <recycle ref="recycle"></recycle>
  79. </view>
  80. </template>
  81. <script>
  82. import recycle from "@/components/recycle.vue"
  83. export default {
  84. components: {
  85. recycle
  86. },
  87. data() {
  88. return {
  89. i:0,//
  90. page:1,
  91. isAll:false,//
  92. pages:null,//
  93. totalNumber:0,//总数量
  94. boxList:[],//盒子列表
  95. donationList:[],//转赠列表
  96. recordId: null,//转赠商品id
  97. donationPhone: null//转赠人手机号
  98. };
  99. },
  100. watch:{
  101. boxList:{
  102. handler(val){
  103. let totalNumber = 0
  104. this.isAll = val.every(item=>item.flag)
  105. if (val.length == 0) this.isAll = false
  106. val.forEach(item=>{
  107. if (item.flag) {
  108. totalNumber++
  109. }
  110. })
  111. this.totalNumber = totalNumber
  112. },
  113. deep:true //true 深度监听
  114. }
  115. },
  116. methods:{
  117. // 新增 标题名称
  118. titleName(index){
  119. switch(index){
  120. case 0: return "待提货"
  121. case 1: return "已回收"
  122. case 2: return "已转赠"
  123. }
  124. },
  125. //申请发货
  126. apply (index) {
  127. if (!this.boxList.some(item=>item.flag)) return uni.showToast({title:'请勾选要' +( index == 0 ? '回收' : '发货') + '的商品',icon:'none'})
  128. let ids = []
  129. this.boxList.forEach(item=>{
  130. if (item.flag) {
  131. ids.push(item.record_id)
  132. }
  133. })
  134. if (index == 0) {
  135. uni.showModal({
  136. cancelText: "取消",
  137. confirmText: "确认",
  138. title: "一键回收",
  139. content: "是否确认一键回收?",
  140. success: res => {
  141. if(res.confirm){
  142. this.$api.exchange({record_ids:ids.join(',')}).then(res=>{
  143. if (res.code === 1) {
  144. uni.showToast({title:res.msg})
  145. this.page = 1
  146. this.getMyBox()
  147. this.$refs['recycle'].open(res.data)
  148. }
  149. })
  150. }
  151. }
  152. })
  153. } else {
  154. uni.navigateTo({url:'/pages/me/applyFaHuo?id=' + ids.join(',')})
  155. }
  156. },
  157. //全选
  158. changeAll () {
  159. this.isAll = !this.isAll
  160. this.boxList.forEach(item=>{
  161. item.flag = this.isAll
  162. })
  163. },
  164. changeIndex (index) {
  165. this.i = index
  166. this.page = 1
  167. this.boxList = []
  168. this.getMyBox()
  169. },
  170. //获取我的盒柜
  171. getMyBox () {
  172. // 新增 获取已转赠
  173. if(this.i == 2){
  174. this.$api.echargezs({msg:'数据加载中'}).then( res => {
  175. this.donationList = res.data
  176. })
  177. return
  178. }
  179. this.$api.myBox({status:this.i + 1,page:this.page,msg:'数据加载中'}).then(res=>{
  180. if (res.code === 1) {
  181. res.data.data.forEach(item=>{
  182. item.flag = false
  183. })
  184. this.pages = res.data.last_page
  185. this.boxList = this.page == 1 ? res.data.data : [...this.boxList,...res.data.data]
  186. }
  187. })
  188. },
  189. // 新增 打开转赠窗口
  190. donationOpen (item) {
  191. this.recordId = item.record_id
  192. this.$refs.donation.open()
  193. },
  194. // 新增 转赠提交
  195. donation () {
  196. if(!this.checkPhone()){
  197. return
  198. }
  199. this.$api.echargez({record_ids: this.recordId, mobile: this.donationPhone}).then( res => {
  200. if(res.code === 1){
  201. //转赠成功
  202. const index = this.boxList.findIndex(item => item.record_id == this.recordId)
  203. this.boxList.splice(index, 1)
  204. this.$refs.donation.close()
  205. uni.showToast({
  206. icon: "success",
  207. title: "转赠成功"
  208. })
  209. }
  210. })
  211. },
  212. /* 新增 检查手机号 */
  213. checkPhone(){
  214. if(!(/^1[345789]\d{9}$/.test(this.donationPhone))){
  215. uni.showToast({
  216. title: '请输入正确的手机号码',
  217. icon: 'none'
  218. })
  219. return false
  220. }
  221. return true
  222. }
  223. },
  224. onShow () {
  225. this.getMyBox()
  226. },
  227. onReachBottom() {
  228. if(this.i == 2){
  229. return
  230. }
  231. if (this.page < this.pages) {
  232. this.page++
  233. this.getMyBox()
  234. }
  235. }
  236. }
  237. </script>
  238. <style lang="scss">
  239. .an{
  240. height: 25px;
  241. width: 25px;
  242. float: left;
  243. position: relative;
  244. top: 42px;
  245. }
  246. .box_head {
  247. position: sticky;
  248. top: 88rpx;
  249. /* #ifdef MP-WEIXIN */
  250. top: 0;
  251. /* #endif */
  252. left: 0;
  253. background: #FAFAFA;
  254. z-index: 2021;
  255. width: 100%;
  256. .box_head_li {
  257. flex:1 ;
  258. font-size: 30rpx;
  259. height: 90rpx;
  260. font-weight: bold;
  261. }
  262. .active {
  263. border-radius: 100rpx;
  264. color: #69a8f8;
  265. }
  266. }
  267. .box_ul {
  268. padding: 0 30rpx 98rpx 30rpx;
  269. .box_ul_li {
  270. padding: 15rpx;
  271. margin-bottom: 20rpx;
  272. background: #FFFFFF;
  273. border-radius: 20rpx;
  274. .box_ul_li_img {
  275. width: 30%;
  276. float: left;
  277. image {
  278. width: 200rpx;
  279. height: 200rpx;
  280. border-radius: 10rpx;
  281. }
  282. margin-right: 20rpx;
  283. }
  284. .box_ul_li_main {
  285. flex: 1;
  286. }
  287. //修改
  288. .box_ul_li_name {
  289. font-size: 28rpx;
  290. display: flex;
  291. overflow: hidden;
  292. text{
  293. display: -webkit-box;
  294. -webkit-box-orient: vertical;
  295. -webkit-line-clamp: 2;
  296. flex: 1;
  297. font-weight: bold;
  298. }
  299. }
  300. .box_ul_li_price {
  301. text {
  302. color: #66a6ff;
  303. font-size: 28rpx;
  304. font-weight:600;
  305. }
  306. image {
  307. width: 44rpx;
  308. height: 44rpx;
  309. }
  310. margin: 15rpx 0;
  311. }
  312. .box_ul_li_price .hsj,.khj,.xsj{
  313. display: block;
  314. margin: 10rpx 0;
  315. uni-text{
  316. float: right
  317. }
  318. }
  319. .box_ul_li_price .hsj{
  320. uni-text{
  321. color: #000000;
  322. }
  323. }
  324. .box_ul_li_time {
  325. color: #999999;
  326. font-size: 22rpx;
  327. align-items: center;
  328. margin-top: 20rpx;
  329. uni-text{
  330. line-height: 70rpx;
  331. }
  332. uni-image{
  333. width: 48rpx;
  334. height: 48rpx;
  335. float: right;
  336. }
  337. .item-btn{
  338. background-image: -moz-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  339. background-image: -webkit-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  340. background-image: -ms-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  341. color: #FFFFFF;
  342. border-radius: 19px;
  343. font-size: 28rpx;
  344. margin-left: auto;
  345. width: 200rpx;
  346. height: 60rpx;
  347. float: right;
  348. }
  349. }
  350. }
  351. }
  352. .box_footer {
  353. height: 98rpx;
  354. z-index: 20;
  355. position: fixed;
  356. bottom: 92rpx;
  357. /* #ifdef MP-WEIXIN */
  358. bottom: 0;
  359. /* #endif */
  360. width: 100%;
  361. padding: 0 30rpx;
  362. background: #FFFFFF;
  363. .box_footer_all {
  364. image {
  365. width: 44rpx;
  366. height: 44rpx;
  367. margin-right: 10rpx;
  368. }
  369. text {
  370. color: #000000;
  371. font-size: 28rpx;
  372. }
  373. }
  374. .box_footer_li {
  375. color: #FFFFFF;
  376. width: 200rpx;
  377. height: 70rpx;
  378. border-radius: 39rpx;
  379. font-size: 30rpx;
  380. margin-left: 30rpx;
  381. &:first-child {
  382. // background-image: -moz-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  383. // background-image: -webkit-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  384. // background-image: -ms-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  385. background-color: rgb(255,103,164);
  386. }
  387. &:last-child {
  388. background-color: rgb(102,166,255);
  389. // background-image: -moz-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  390. // background-image: -webkit-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  391. // background-image: -ms-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  392. }
  393. }
  394. }
  395. // 新增 转赠窗口样式
  396. .donation{
  397. background-color: #fff;
  398. padding: 30rpx 40rpx;
  399. border-radius: 10px;
  400. .title{
  401. font-size: 16px;
  402. font-weight: bold;
  403. text-align: center;
  404. margin-bottom: 30rpx;
  405. }
  406. .input-container{
  407. background-color: #f3f3f3;
  408. padding: 16rpx 20rpx;
  409. border-radius: 6rpx;
  410. margin-bottom: 20rpx;
  411. input{
  412. font-size: 30rpx;
  413. }
  414. }
  415. .tip{
  416. font-size: 12px;
  417. color: red;
  418. text-align: center;
  419. margin-bottom: 30rpx;
  420. }
  421. .donation-btns{
  422. display: flex;
  423. gap: 30rpx;
  424. view {
  425. color: #FFFFFF;
  426. flex: 1;
  427. width: 100%;
  428. height: 70rpx;
  429. border-radius: 39rpx;
  430. font-size: 30rpx;
  431. &:first-child {
  432. background: -webkit-linear-gradient(60deg, #ffc8de 0%, #ff67a4 100%);
  433. }
  434. &:last-child {
  435. background: -webkit-linear-gradient(0deg, #89f7fe 0%, #66a6ff 100%);
  436. }
  437. }
  438. }
  439. }
  440. </style>