index.vue 6.5 KB

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