index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }" :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  3. <tm-menubars title="消息列表" :shadow="0" :showback="true"></tm-menubars>
  4. <view class="zhuti shangpin">
  5. <tm-sheet :padding="[0, 0]" class="jiaoxi xiao">
  6. <view v-for="item in test">
  7. <tm-checkbox @change="choose" style="float: left;padding:2px !important;margin-top:9%;"
  8. v-model="item.checked" label=""></tm-checkbox>
  9. <tm-cartCellListFood @change="shuliangjia(item)" class="shuliang" :typeclick="typeclick"
  10. :mdata="item" :cart-num.sync="item.buy"></tm-cartCellListFood>
  11. </view>
  12. </tm-sheet>
  13. </view>
  14. <view class="dibu">
  15. <tm-listitem class="liebiao" value="免费" :round="24" :shadow="12" title="邮费" :show-right-icon="false">
  16. </tm-listitem>
  17. <tm-listitem class="liebiao jiageList" :value="'¥'+zongjia" :round="24" :shadow="12" title="价格"
  18. :show-right-icon="false"></tm-listitem>
  19. <view class="text-align-center">
  20. <tm-button theme="red" @click="shanchu" :round="24" class="mt-50 logincla">删除</tm-button>
  21. <tm-button theme="primary" :round="24" class="mt-50 logincla" @click="goPay">立即付款</tm-button>
  22. </view>
  23. </view>
  24. <!-- 弹出层消息 -->
  25. <tm-message ref="toast"></tm-message>
  26. </view>
  27. </template>
  28. <script>
  29. import {
  30. myRequest
  31. } from '@/api/request.js'
  32. export default {
  33. data() {
  34. return {
  35. zongjia: 0,
  36. test: [],
  37. typeclick: 2, //1加入购物车,2购物车
  38. };
  39. },
  40. onLoad() {
  41. },
  42. created() {
  43. this.sys = uni.getSystemInfoSync();
  44. this.getList()
  45. },
  46. methods: {
  47. goPay() {
  48. var that = this,
  49. data = this.test,
  50. goods = [];
  51. for (let i = 0; i < data.length; i++) {
  52. if (data[i].checked) {
  53. goods.push(data[i])
  54. console.log(data, goods, '数据');
  55. }
  56. }
  57. if (goods.length == 0) {
  58. that.$refs.toast.show({
  59. model: 'success',
  60. label: '请选择商品'
  61. })
  62. return
  63. } else if (goods.length == 1) {
  64. myRequest({
  65. url: "/api/Order/addOrder",
  66. method: 'post',
  67. data: {
  68. order_remark: '',
  69. order_money: that.zongjia,
  70. pay_money: that.zongjia,
  71. buy_num: goods[0].buy,
  72. goods_id: goods[0].goods_id
  73. }
  74. }).then(res => {
  75. if (res.data.code == 200) {
  76. that.$refs.toast.show({
  77. model: 'success',
  78. label: res.data.msg
  79. })
  80. } else {
  81. that.$refs.toast.show({
  82. model: 'error',
  83. label: res.data.msg
  84. })
  85. }
  86. })
  87. } else {
  88. console.log('不止一个');
  89. }
  90. },
  91. shanchu() {
  92. var that = this,
  93. data = this.test,
  94. ids = [];
  95. for (let i = 0; i < data.length; i++) {
  96. if (data[i].checked) {
  97. ids.push(data[i].id)
  98. console.log(ids);
  99. }
  100. }
  101. console.log(data, '数据');
  102. if (ids.length == 0) {
  103. that.$refs.toast.show({
  104. model: 'success',
  105. label: '请选择商品'
  106. })
  107. return
  108. }
  109. myRequest({
  110. url: "/api/ShopCart/deleteOneGoods",
  111. method: 'post',
  112. data: {
  113. id: ids
  114. }
  115. }).then(res => {
  116. if (res.data.code == 200) {
  117. this.getList()
  118. that.$refs.toast.show({
  119. model: 'success',
  120. label: res.data.msg
  121. })
  122. } else {
  123. that.$refs.toast.show({
  124. model: 'error',
  125. label: res.data.msg
  126. })
  127. }
  128. })
  129. },
  130. shuliangjia(num) {
  131. this.jiage();
  132. },
  133. choose() {
  134. this.jiage()
  135. },
  136. jiage() {
  137. var data = this.test,
  138. jiage = 0;
  139. for (let i = 0; i < data.length; i++) {
  140. if (data[i].checked) {
  141. var danjia = JSON.parse(data[i].price);
  142. var shuliang = data[i].buy;
  143. jiage = jiage + (danjia * shuliang);
  144. }
  145. }
  146. this.zongjia = jiage;
  147. },
  148. getList() {
  149. var that = this;
  150. myRequest({
  151. url: "/api/ShopCart/shopCartList",
  152. method: 'post',
  153. data: {}
  154. }).then(res => {
  155. if (res.data.code == 200) {
  156. if (res.data.data.length != 0) {
  157. that.test = [];
  158. for (let i = 0; i < res.data.data.length; i++) {
  159. var obj = {
  160. img: res.data.data[i].goods_image,
  161. title: res.data.data[i].goods_name,
  162. // label: '黑色 - 6518/320',
  163. // size:'S',
  164. price: res.data.data[i].goods_price,
  165. id: res.data.data[i].id,
  166. buy: res.data.data[i].goods_num,
  167. itemId: res.data.data[i].id,
  168. checked: false,
  169. goods_id:res.data.data[i].goods_id
  170. };
  171. that.test.push(obj)
  172. }
  173. that.jiage()
  174. }
  175. } else {
  176. that.test = [];
  177. }
  178. })
  179. },
  180. },
  181. }
  182. </script>
  183. <style lang="scss">
  184. /deep/ .tm-menubars .body {
  185. background-color: #1b1b1b !important;
  186. }
  187. /deep/ .jiaoxi {
  188. margin: 0 !important;
  189. padding: 8px !important;
  190. margin-bottom: 200px !important;
  191. }
  192. /deep/ .shangpin .white.bk {
  193. background-color: #1b1b1b !important;
  194. }
  195. /deep/ .shangpin .tm-cartCellListFood {
  196. padding: 0px 0px 15px 0px !important;
  197. margin-top: 5px !important;
  198. margin-bottom: 20px !important;
  199. border-bottom: 1px solid #303030;
  200. }
  201. /deep/ .shangpin .border-t-1.bk {
  202. border-top: 1px solid #1b1b1b !important;
  203. }
  204. /deep/ .shangpin .title {
  205. color: white !important;
  206. }
  207. /deep/ .shangpin .text-red {
  208. color: white !important;
  209. }
  210. /deep/ .shangpin .round-3 {
  211. width: 90px !important;
  212. height: 90px !important;
  213. }
  214. /deep/ .shangpin .tm-cartCellListFood-img {
  215. width: 90px !important;
  216. height: 90px !important;
  217. }
  218. /deep/ .shuliang .text-size-n {
  219. color: white !important;
  220. }
  221. .dibu {
  222. background: #0D0D0D;
  223. position: fixed;
  224. bottom: 0px;
  225. width: 100%;
  226. }
  227. /deep/ .liebiao .grey-darken-4.bk {
  228. background: #0D0D0D !important;
  229. padding: 0px;
  230. margin: 0px;
  231. width: 100%;
  232. border-radius: 0px !important;
  233. }
  234. .logincla {
  235. width: 40%;
  236. margin: 0 auto;
  237. margin-top: 20px;
  238. margin-bottom: 30px;
  239. }
  240. /deep/ .jiageList .d-inline-block {
  241. font-size: 18px !important;
  242. color: white !important;
  243. }
  244. </style>