index.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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" v-if="test.length>0">
  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. if (!uni.getStorageSync("token")) {
  44. uni.navigateTo({
  45. url: "/pages/login/index",
  46. })
  47. }
  48. this.sys = uni.getSystemInfoSync();
  49. this.getList()
  50. },
  51. methods: {
  52. goPay() {
  53. var that = this,
  54. data = this.test,
  55. goods = [];
  56. for (let i = 0; i < data.length; i++) {
  57. if (data[i].checked) {
  58. goods.push(data[i])
  59. console.log(data, goods, '数据');
  60. }
  61. }
  62. if (goods.length == 0) {
  63. that.$refs.toast.show({
  64. model: 'success',
  65. label: '请选择商品'
  66. })
  67. return
  68. } else if (goods.length == 1) {
  69. myRequest({
  70. url: "/api/Order/addOrder",
  71. method: 'post',
  72. data: {
  73. order_remark: '',
  74. order_money: that.zongjia,
  75. pay_money: that.zongjia,
  76. buy_num: goods[0].buy,
  77. goods_id: goods[0].goods_id
  78. }
  79. }).then(res => {
  80. if (res.data.code == 200) {
  81. that.$refs.toast.show({
  82. model: 'success',
  83. label: res.data.msg
  84. })
  85. this.shanchu()
  86. } else {
  87. that.$refs.toast.show({
  88. model: 'error',
  89. label: res.data.msg
  90. })
  91. }
  92. })
  93. } else {
  94. console.log('不止一个');
  95. }
  96. },
  97. shanchu() {
  98. var that = this,
  99. data = this.test,
  100. ids = [];
  101. for (let i = 0; i < data.length; i++) {
  102. if (data[i].checked) {
  103. ids.push(data[i].id)
  104. console.log(ids);
  105. }
  106. }
  107. console.log(data, '数据');
  108. if (ids.length == 0) {
  109. that.$refs.toast.show({
  110. model: 'success',
  111. label: '请选择商品'
  112. })
  113. return
  114. }
  115. myRequest({
  116. url: "/api/ShopCart/deleteOneGoods",
  117. method: 'post',
  118. data: {
  119. id: ids
  120. }
  121. }).then(res => {
  122. if (res.data.code == 200) {
  123. that.$refs.toast.show({
  124. model: 'success',
  125. label: res.data.msg
  126. })
  127. this.getList()
  128. } else {
  129. that.$refs.toast.show({
  130. model: 'error',
  131. label: res.data.msg
  132. })
  133. }
  134. })
  135. },
  136. shuliangjia(num) {
  137. this.jiage();
  138. },
  139. choose() {
  140. this.jiage()
  141. },
  142. jiage() {
  143. var data = this.test,
  144. jiage = 0;
  145. for (let i = 0; i < data.length; i++) {
  146. if (data[i].checked) {
  147. var danjia = JSON.parse(data[i].price);
  148. var shuliang = data[i].buy;
  149. jiage = jiage + (danjia * shuliang);
  150. }
  151. }
  152. this.zongjia = jiage;
  153. },
  154. getList() {
  155. var that = this;
  156. myRequest({
  157. url: "/api/ShopCart/shopCartList",
  158. method: 'post',
  159. data: {}
  160. }).then(res => {
  161. if (res.data.code == 200) {
  162. if (res.data.data.length > 0) {
  163. that.test = [];
  164. for (let i = 0; i < res.data.data.length; i++) {
  165. var obj = {
  166. img: res.data.data[i].goods_image,
  167. title: res.data.data[i].goods_name,
  168. // label: '黑色 - 6518/320',
  169. // size:'S',
  170. price: res.data.data[i].goods_price,
  171. id: res.data.data[i].id,
  172. buy: res.data.data[i].goods_num,
  173. itemId: res.data.data[i].id,
  174. checked: false,
  175. goods_id:res.data.data[i].goods_id
  176. };
  177. that.test.push(obj)
  178. }
  179. that.jiage()
  180. }
  181. } else {
  182. that.test = [];
  183. }
  184. })
  185. },
  186. },
  187. }
  188. </script>
  189. <style lang="scss">
  190. /deep/ .tm-menubars .body {
  191. background-color: #1b1b1b !important;
  192. }
  193. /deep/ .jiaoxi {
  194. margin: 0 !important;
  195. padding: 8px !important;
  196. margin-bottom: 200px !important;
  197. }
  198. /deep/ .shangpin .white.bk {
  199. background-color: #1b1b1b !important;
  200. }
  201. /deep/ .shangpin .tm-cartCellListFood {
  202. padding: 0px 0px 15px 0px !important;
  203. margin-top: 5px !important;
  204. margin-bottom: 20px !important;
  205. border-bottom: 1px solid #303030;
  206. }
  207. /deep/ .shangpin .border-t-1.bk {
  208. border-top: 1px solid #1b1b1b !important;
  209. }
  210. /deep/ .shangpin .title {
  211. color: white !important;
  212. }
  213. /deep/ .shangpin .text-red {
  214. color: white !important;
  215. }
  216. /deep/ .shangpin .round-3 {
  217. width: 90px !important;
  218. height: 90px !important;
  219. }
  220. /deep/ .shangpin .tm-cartCellListFood-img {
  221. width: 90px !important;
  222. height: 90px !important;
  223. }
  224. /deep/ .shuliang .text-size-n {
  225. color: white !important;
  226. }
  227. .dibu {
  228. background: #0D0D0D;
  229. position: fixed;
  230. bottom: 0px;
  231. width: 100%;
  232. }
  233. /deep/ .liebiao .grey-darken-4.bk {
  234. background: #0D0D0D !important;
  235. padding: 0px;
  236. margin: 0px;
  237. width: 100%;
  238. border-radius: 0px !important;
  239. }
  240. .logincla {
  241. width: 40%;
  242. margin: 0 auto;
  243. margin-top: 20px;
  244. margin-bottom: 30px;
  245. }
  246. /deep/ .jiageList .d-inline-block {
  247. font-size: 18px !important;
  248. color: white !important;
  249. }
  250. </style>