box.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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="change(item)">
  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 flex">
  35. <!-- 修改 -->
  36. <view>时间:{{ item.time }}</view>
  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="'donation-' + 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. // 选择和取消
  171. change(item) {
  172. item.flag = !item.flag;
  173. },
  174. changeIndex(index) {
  175. this.i = index;
  176. this.page = 1;
  177. this.boxList = [];
  178. this.getMyBox();
  179. },
  180. //获取我的盒柜
  181. getMyBox() {
  182. // 新增 获取已转赠
  183. if (this.i == 2) {
  184. this.$api.echargezs({ msg: '数据加载中' }).then(res => {
  185. this.donationList = res.data;
  186. });
  187. return;
  188. }
  189. this.$api.myBox({ status: this.i + 1, page: this.page, msg: '数据加载中' }).then(res => {
  190. if (res.code === 1) {
  191. res.data.data.forEach(item => {
  192. item.flag = false;
  193. });
  194. this.pages = res.data.last_page;
  195. this.boxList = this.page == 1 ? res.data.data : [...this.boxList, ...res.data.data];
  196. }
  197. });
  198. },
  199. // 新增 打开转赠窗口
  200. donationOpen(item) {
  201. this.recordId = item.record_id;
  202. this.$refs.donation.open();
  203. },
  204. // 新增 转赠提交
  205. donation() {
  206. if (!this.checkPhone()) {
  207. return;
  208. }
  209. this.$api.echargez({ record_ids: this.recordId, mobile: this.donationPhone }).then(res => {
  210. if (res.code === 1) {
  211. //转赠成功
  212. const index = this.boxList.findIndex(item => item.record_id == this.recordId);
  213. this.boxList.splice(index, 1);
  214. this.$refs.donation.close();
  215. uni.showToast({
  216. icon: 'success',
  217. title: '转赠成功'
  218. });
  219. }
  220. });
  221. },
  222. /* 新增 检查手机号 */
  223. checkPhone() {
  224. if (!/^1[345789]\d{9}$/.test(this.donationPhone)) {
  225. uni.showToast({
  226. title: '请输入正确的手机号码',
  227. icon: 'none'
  228. });
  229. return false;
  230. }
  231. return true;
  232. }
  233. },
  234. onShow() {
  235. this.getMyBox();
  236. },
  237. onReachBottom() {
  238. if (this.i == 2) {
  239. return;
  240. }
  241. if (this.page < this.pages) {
  242. this.page++;
  243. this.getMyBox();
  244. }
  245. }
  246. };
  247. </script>
  248. <style lang="scss">
  249. .an {
  250. height: 25px;
  251. width: 25px;
  252. float: left;
  253. position: relative;
  254. top: 42px;
  255. }
  256. .box_head {
  257. position: sticky;
  258. top: 88rpx;
  259. /* #ifndef H5 */
  260. top: 0;
  261. /* #endif */
  262. left: 0;
  263. background: #fafafa;
  264. z-index: 2021;
  265. width: 100%;
  266. .box_head_li {
  267. flex: 1;
  268. font-size: 30rpx;
  269. height: 90rpx;
  270. font-weight: bold;
  271. }
  272. .active {
  273. border-radius: 100rpx;
  274. color: #69a8f8;
  275. }
  276. }
  277. .box_ul {
  278. padding: 0 30rpx 98rpx 30rpx;
  279. .box_ul_li {
  280. padding: 15rpx;
  281. margin-bottom: 20rpx;
  282. background: #ffffff;
  283. border-radius: 20rpx;
  284. .box_ul_li_img {
  285. width: 30%;
  286. float: left;
  287. image {
  288. width: 200rpx;
  289. height: 200rpx;
  290. border-radius: 10rpx;
  291. }
  292. margin-right: 20rpx;
  293. }
  294. .box_ul_li_main {
  295. flex: 1;
  296. }
  297. //修改
  298. .box_ul_li_name {
  299. font-size: 28rpx;
  300. display: flex;
  301. overflow: hidden;
  302. text {
  303. display: -webkit-box;
  304. -webkit-box-orient: vertical;
  305. -webkit-line-clamp: 2;
  306. flex: 1;
  307. font-weight: bold;
  308. }
  309. }
  310. .box_ul_li_price {
  311. text {
  312. color: #66a6ff;
  313. font-size: 28rpx;
  314. font-weight: 600;
  315. }
  316. image {
  317. width: 44rpx;
  318. height: 44rpx;
  319. }
  320. margin: 15rpx 0;
  321. }
  322. .box_ul_li_price .hsj,
  323. .khj,
  324. .xsj {
  325. display: block;
  326. margin: 10rpx 0;
  327. uni-text {
  328. float: right;
  329. }
  330. }
  331. .box_ul_li_price .hsj {
  332. uni-text {
  333. color: #000000;
  334. }
  335. }
  336. .box_ul_li_time {
  337. color: #999999;
  338. font-size: 22rpx;
  339. align-items: center;
  340. margin-top: 20rpx;
  341. uni-text {
  342. line-height: 70rpx;
  343. }
  344. uni-image {
  345. width: 48rpx;
  346. height: 48rpx;
  347. float: right;
  348. }
  349. .item-btn {
  350. background-image: linear-gradient(0deg, rgb(137, 247, 254) 0%, rgb(102, 166, 255) 100%);
  351. color: #ffffff;
  352. border-radius: 19px;
  353. font-size: 28rpx;
  354. margin-left: auto;
  355. width: 200rpx;
  356. height: 60rpx;
  357. float: right;
  358. }
  359. }
  360. }
  361. }
  362. .box_footer {
  363. height: 98rpx;
  364. z-index: 20;
  365. position: fixed;
  366. bottom: 92rpx;
  367. /* #ifndef H5 */
  368. bottom: 0;
  369. /* #endif */
  370. width: 100%;
  371. padding: 0 30rpx;
  372. background: #ffffff;
  373. .box_footer_all {
  374. image {
  375. width: 44rpx;
  376. height: 44rpx;
  377. margin-right: 10rpx;
  378. }
  379. text {
  380. color: #000000;
  381. font-size: 28rpx;
  382. }
  383. }
  384. .box_footer_li {
  385. color: #ffffff;
  386. width: 200rpx;
  387. height: 70rpx;
  388. border-radius: 39rpx;
  389. font-size: 30rpx;
  390. margin-left: 30rpx;
  391. &:first-child {
  392. // background-image: -moz-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  393. // background-image: -webkit-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  394. // background-image: -ms-linear-gradient( 60deg, rgb(255,200,222) 0%, rgb(255,103,164) 100%);
  395. background-color: rgb(255, 103, 164);
  396. }
  397. &:last-child {
  398. background-color: rgb(102, 166, 255);
  399. // background-image: -moz-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  400. // background-image: -webkit-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  401. // background-image: -ms-linear-gradient( 0deg, rgb(137,247,254) 0%, rgb(102,166,255) 100%);
  402. }
  403. }
  404. }
  405. // 新增 转赠窗口样式
  406. .donation {
  407. background-color: #fff;
  408. padding: 30rpx 40rpx;
  409. border-radius: 10px;
  410. .title {
  411. font-size: 16px;
  412. font-weight: bold;
  413. text-align: center;
  414. margin-bottom: 30rpx;
  415. }
  416. .input-container {
  417. background-color: #f3f3f3;
  418. padding: 16rpx 20rpx;
  419. border-radius: 6rpx;
  420. margin-bottom: 20rpx;
  421. input {
  422. font-size: 30rpx;
  423. }
  424. }
  425. .tip {
  426. font-size: 12px;
  427. color: red;
  428. text-align: center;
  429. margin-bottom: 30rpx;
  430. }
  431. .donation-btns {
  432. display: flex;
  433. gap: 30rpx;
  434. view {
  435. color: #ffffff;
  436. flex: 1;
  437. width: 100%;
  438. height: 70rpx;
  439. border-radius: 39rpx;
  440. font-size: 30rpx;
  441. &:first-child {
  442. background: -webkit-linear-gradient(60deg, #ffc8de 0%, #ff67a4 100%);
  443. }
  444. &:last-child {
  445. background: -webkit-linear-gradient(0deg, #89f7fe 0%, #66a6ff 100%);
  446. }
  447. }
  448. }
  449. }
  450. </style>