myBox.vue 11 KB

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