deposit.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <view class="good-list">
  3. <view class="flex nav-box">
  4. <view class="tab">
  5. 总计:<text class="font-color-red">{{total_count}}</text>(个)
  6. </view>
  7. <view class="line"></view>
  8. <view class="tab">
  9. 押金:<text class="font-color-red">{{total_pledge_money}}</text>(元)
  10. </view>
  11. </view>
  12. <view class="deposit-item">
  13. <view class="list flex" v-for="(item,index) in navList[tabCurrentIndex].orderList" @click="open(item)">
  14. <view class="content">
  15. <view class="title">
  16. 小金康泉矿泉水
  17. </view>
  18. <view class="flex type-list">
  19. <view class="ls">
  20. 余桶:<text class="font-color-red">{{item.remain_num}}</text>
  21. </view>
  22. <view class="ls">
  23. 押桶:<text class="font-color-red">{{item.pledge_num}}</text>
  24. </view>
  25. <view class="ls">
  26. 借桶:<text class="font-color-red">{{item.borrow_num}}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="iconfont iconenter">
  31. </view>
  32. </view>
  33. </view>
  34. <uni-load-more :status="navList[tabCurrentIndex].loadingType"></uni-load-more>
  35. <uni-popup ref="popup" type="bottom">
  36. <view class="buttomBox">
  37. <view class="item borde-b" @click="addBarrel">
  38. 押桶
  39. </view>
  40. <view class="item borde-b" @click="delBarrel">
  41. 退桶
  42. </view>
  43. </view>
  44. <view class="buttomBox" @click="$refs.popup.close()">
  45. <view class="item qx">
  46. 取消
  47. </view>
  48. </view>
  49. </uni-popup>
  50. </view>
  51. </template>
  52. <script>
  53. import {
  54. certificate,
  55. createPledge,
  56. delPledge
  57. } from '@/api/water.js';
  58. export default {
  59. data() {
  60. return {
  61. tabCurrentIndex: 0,
  62. navList: [{
  63. state: 0,
  64. text: '全部',
  65. loadingType: 'more',
  66. orderList: [],
  67. page: 1, //当前页数
  68. limit: 10 //每次信息条数
  69. }],
  70. // 保存当前选中的桶对象
  71. actionItem: {},
  72. total_pledge_money: 0, //押金
  73. total_count: 0, //总数
  74. };
  75. },
  76. onReachBottom() {
  77. this.getGoodList();
  78. },
  79. onLoad: function(option) {
  80. this.getGoodList();
  81. },
  82. methods: {
  83. // 押桶
  84. addBarrel() {
  85. const that = this;
  86. uni.showModal({
  87. title: '押桶',
  88. placeholderText: '请输入押桶数量',
  89. editable: true,
  90. cancelText: '关闭',
  91. confirmText: '押桶',
  92. success: res => {
  93. if (res.confirm) {
  94. if(res.content.search(/^\d*$/)<0){
  95. uni.showModal({
  96. title: '错误',
  97. content: '请输入数字',
  98. showCancel: false,
  99. });
  100. return
  101. }
  102. createPledge({
  103. id: that.actionItem.id,
  104. num: res.content,
  105. pay_type: 'yue'
  106. }).then(() => {
  107. that.$refs.popup.close();
  108. uni.showToast({
  109. title: '押桶成功'
  110. })
  111. that.reloadList();
  112. }).catch(e => {
  113. console.log(e);
  114. });
  115. }
  116. },
  117. });
  118. },
  119. // 退桶
  120. delBarrel() {
  121. const that = this;
  122. uni.showModal({
  123. title: '退桶',
  124. placeholderText: '请输入退桶数量',
  125. editable: true,
  126. cancelText: '关闭',
  127. confirmText: '退桶',
  128. success: res => {
  129. if (res.confirm) {
  130. if(res.content.search(/^\d*$/)<0){
  131. uni.showModal({
  132. title: '错误',
  133. content: '请输入数字',
  134. showCancel: false,
  135. });
  136. return
  137. }
  138. console.log(that.actionItem.pledge_num,res.content);
  139. if(that.actionItem.pledge_num<+res.content){
  140. uni.showModal({
  141. title: '错误',
  142. content: '退桶数不可大于押桶数',
  143. showCancel: false,
  144. });
  145. return
  146. }
  147. delPledge({
  148. id: that.actionItem.id,
  149. num: res.content,
  150. }).then(() => {
  151. that.$refs.popup.close();
  152. uni.showToast({
  153. title: '退桶成功'
  154. })
  155. that.reloadList();
  156. }).catch(e => {
  157. console.log(e);
  158. });
  159. }
  160. },
  161. });
  162. },
  163. // 重新加载数据
  164. reloadList() {
  165. this.navList = [{
  166. state: 0,
  167. text: '全部',
  168. loadingType: 'more',
  169. orderList: [],
  170. page: 1, //当前页数
  171. limit: 10 //每次信息条数
  172. }];
  173. this.getGoodList();
  174. },
  175. // 打开选择弹窗
  176. open(item) {
  177. this.actionItem = item;
  178. this.$refs.popup.open()
  179. },
  180. // 加载数据
  181. getGoodList(source) {
  182. //这里是将订单挂载到tab列表下
  183. let index = this.tabCurrentIndex;
  184. let navItem = this.navList[index];
  185. let state = navItem.state;
  186. console.log(navItem, '数据');
  187. if (source === 'tabChange' && navItem.loaded === true) {
  188. //tab切换只有第一次需要加载数据
  189. return;
  190. }
  191. if (navItem.loadingType === 'loading') {
  192. //防止重复加载
  193. return;
  194. }
  195. if (navItem.loadingType === 'noMore') {
  196. //防止重复加载
  197. return;
  198. }
  199. // 修改当前对象状态为加载中
  200. navItem.loadingType = 'loading';
  201. certificate({
  202. page: navItem.page,
  203. limit: navItem.limit
  204. })
  205. .then(({
  206. data
  207. }) => {
  208. this.total_pledge_money = data.total_pledge_money;
  209. this.total_count = data.total_count;
  210. let arr = data.data.map(e => {
  211. return e;
  212. });
  213. navItem.orderList = navItem.orderList.concat(arr);
  214. // console.log(navItem.orderList);
  215. navItem.page++;
  216. if (navItem.limit == arr.length) {
  217. //判断是否还有数据, 有改为 more, 没有改为noMore
  218. navItem.loadingType = 'more';
  219. return;
  220. } else {
  221. //判断是否还有数据, 有改为 more, 没有改为noMore
  222. navItem.loadingType = 'noMore';
  223. }
  224. uni.hideLoading();
  225. this.$set(navItem, 'loaded', true);
  226. })
  227. .catch(e => {
  228. console.log(e);
  229. });
  230. },
  231. }
  232. };
  233. </script>
  234. <style lang="scss">
  235. .good-list {
  236. padding: 30rpx 0;
  237. width: 750rpx;
  238. .nav-box {
  239. border-radius: 10rpx;
  240. background-color: #FFF;
  241. border-bottom: 2px solid $page-color-base;
  242. .tab {
  243. width: 50%;
  244. height: 95rpx;
  245. text-align: center;
  246. flex-shrink: 1;
  247. font-size: $font-lg;
  248. font-weight: bold;
  249. line-height: 95rpx;
  250. }
  251. .line {
  252. height: 55rpx;
  253. width: 3px;
  254. background-color: $page-color-base;
  255. }
  256. }
  257. }
  258. .deposit-item {
  259. padding: 0 30rpx;
  260. background-color: #FFF;
  261. line-height: 1;
  262. .list {
  263. border-bottom: 2px solid $page-color-base;
  264. padding: 30rpx 0;
  265. .content {
  266. width: 0;
  267. flex-grow: 1;
  268. .title {
  269. font-size: $font-lg;
  270. font-weight: bold;
  271. }
  272. .type-list {
  273. padding-top: 30rpx;
  274. font-size: $font-sm;
  275. color: $font-color-base;
  276. .ls {
  277. width: 33%;
  278. }
  279. }
  280. }
  281. }
  282. }
  283. .buttomBox {
  284. border-radius: 20rpx;
  285. margin: 0 $page-row-spacing;
  286. margin-bottom: 30rpx;
  287. color: $font-color-dark;
  288. background-color: #FFFFFF;
  289. overflow: hidden;
  290. .item {
  291. line-height: 100rpx;
  292. height: 100rpx;
  293. text-align: center;
  294. font-size: 32rpx;
  295. color: $base-color;
  296. &.qx {
  297. color: $color-red;
  298. }
  299. }
  300. .border_b {
  301. border-bottom: 1px solid $page-color-light;
  302. }
  303. }
  304. </style>