order.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <scroll-view scroll-y="true" class="scroll-view">
  6. <view class="list-scroll-view">
  7. <view class="one_1">
  8. <text class="localicon iconfont icon-dingweixiao"></text>
  9. <view class="other" v-if="address._id">
  10. <view class="name">
  11. <text>{{address.name}},</text>{{address.phone}}
  12. </view>
  13. <view class="other_1">
  14. <text>{{address.province}}</text><text>{{address.city}}</text>
  15. <text>{{address.area}}</text><text>{{address.address}}</text>
  16. </view>
  17. </view>
  18. <view class="address" v-else><text>请选择一个收货地址</text></view>
  19. <text @click="toChoose" class="iconfont icon-jiantouyou"></text>
  20. </view>
  21. <view class="one_2">
  22. <view class="list" v-for="(item,index) in orderList" :key="index">
  23. <view class="list_1">
  24. <view class="l">
  25. <text class="iconfont icon-shangdian"></text>
  26. <text>{{item.shop_name}}</text>
  27. </view>
  28. </view>
  29. <view class="list_2" v-for="(tag,index) in item.goods" :key="index">
  30. <view class="l">
  31. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''"
  32. mode=""></image>
  33. </view>
  34. <view class="c">
  35. <view class="name">
  36. {{tag.goods_name}}
  37. </view>
  38. <view class="Spec">
  39. 规格:{{tag.goodsSpec_name}}
  40. </view>
  41. </view>
  42. <view class="r">
  43. <view class="price">
  44. ¥{{tag.money}}
  45. </view>
  46. <view class="num">
  47. ×{{tag.num}}
  48. </view>
  49. </view>
  50. </view>
  51. <view class="list_3">
  52. <view class="other">
  53. <view class="other_1">配送方式</view>
  54. <view class="other_2"><text class="iconfont icon-duihao"></text>快递配送</view>
  55. </view>
  56. <view class="other">
  57. <view class="other_1">运费</view>
  58. <view class="other_2" v-if="!item.freight_total==0">¥{{item.freight_total}}
  59. </view>
  60. <view class="other_2" v-else>包邮</view>
  61. </view>
  62. <view class="other">
  63. <view class="other_1">订单备注</view>
  64. <view class="other_3">
  65. <input type="text" v-model="tag.remarks" placeholder="选填,可填写您与卖家达成一致的要求" />
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </scroll-view>
  73. </view>
  74. <view class="two">
  75. <view class="two_1">
  76. <view>实付金额:</view>
  77. <view>¥{{goods_total}}</view>
  78. </view>
  79. <view class="two_2">
  80. <text @click="toSubmit">提交订单</text>
  81. </view>
  82. </view>
  83. </view>
  84. <uni-popup ref="popup" background-color="#fff" type="right">
  85. <view class="content" v-for="(item,index) in addressList" :key="index">
  86. <view class="one">
  87. <view class="one_1">
  88. <view class="name">
  89. <text>{{item.name}},</text>{{item.phone}}
  90. </view>
  91. <view class="address">
  92. <text>{{item.province}}</text><text>{{item.city}}</text>
  93. <text>{{item.area}}</text><text>{{item.address}}</text>
  94. </view>
  95. </view>
  96. <text class="iconfont icon-jiantouyou"></text>
  97. </view>
  98. <view class="two">
  99. <view class="two_1">
  100. <checkbox-group @change="toCheckbox">
  101. <label>
  102. <checkbox :value="item._id" :checked="item.checked" style="transform:scale(0.7)" />选择地址
  103. </label>
  104. </checkbox-group>
  105. </view>
  106. <view class="two_2">
  107. <text class="text" v-if="item.is_default=='1'">默认</text>
  108. <text @click="toDel(item)" class="iconfont icon-del"></text>
  109. </view>
  110. </view>
  111. </view>
  112. </uni-popup>
  113. </mobile-frame>
  114. </template>
  115. <script>
  116. export default {
  117. data() {
  118. return {
  119. user: {},
  120. key: '',
  121. address: {},
  122. orderList: [],
  123. shop: [],
  124. goods_total: 0,
  125. // 收货地址
  126. addressList: [],
  127. };
  128. },
  129. onLoad: async function(e) {
  130. const that = this;
  131. that.$set(that, `key`, e.key || '');
  132. that.watchLogin()
  133. },
  134. methods: {
  135. // 选择收货地址
  136. toChoose() {
  137. const that = this;
  138. that.$refs.popup.open();
  139. },
  140. // 是否选中
  141. toCheckbox(e) {
  142. const that = this;
  143. var addressList = that.addressList;
  144. var values = e.detail.value;
  145. for (var i = 0, lenI = addressList.length; i < lenI; ++i) {
  146. const item = addressList[i]
  147. if (values.includes(item._id)) {
  148. that.$set(item, 'checked', true)
  149. that.$set(that, `address`, item);
  150. } else {
  151. that.$set(item, 'checked', false)
  152. }
  153. }
  154. that.$refs.popup.close();
  155. },
  156. // 删除收货地址
  157. toDel(e) {
  158. const that = this;
  159. uni.showModal({
  160. title: '提示',
  161. content: '确定删除该地址吗?',
  162. success: async function(res) {
  163. if (res.confirm) {
  164. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  165. if (arr.errcode == '0') {
  166. uni.showToast({
  167. title: '删除信息成功',
  168. icon: 'none'
  169. })
  170. that.search();
  171. } else {
  172. uni.showToast({
  173. title: arr.errmsg,
  174. icon: 'none'
  175. })
  176. }
  177. }
  178. }
  179. });
  180. },
  181. // 提交订单
  182. async toSubmit() {
  183. const that = this;
  184. let data = {
  185. address: that.address,
  186. goods: that.orderList,
  187. total_detail: that.goods_total
  188. }
  189. const arr = await that.$api(`/order`, 'POST', data)
  190. if (arr.errcode == '0') {
  191. uni.showToast({
  192. title: `提交订单成功`,
  193. icon: 'none'
  194. })
  195. } else {
  196. uni.showToast({
  197. title: arr.data.msg,
  198. icon: 'none'
  199. })
  200. }
  201. },
  202. // 监听用户是否登录
  203. watchLogin() {
  204. const that = this;
  205. uni.getStorage({
  206. key: 'token',
  207. success: function(res) {
  208. let user = that.$jwt(res.data);
  209. that.$set(that, `user`, user);
  210. that.search()
  211. },
  212. fail: function(err) {
  213. uni.reLaunch({
  214. url: `/pages/login/index`
  215. })
  216. }
  217. })
  218. },
  219. // 查询列表
  220. async search() {
  221. const that = this;
  222. let user = that.user;
  223. const res = await that.$api(`/address`, 'GET', {
  224. customer: user._id
  225. })
  226. if (res.errcode == '0') {
  227. that.$set(that, `addressList`, res.data);
  228. }
  229. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  230. key: that.key
  231. })
  232. if (arr.errcode == '0') {
  233. that.$set(that, `address`, arr.data.address);
  234. that.$set(that, `orderList`, arr.data.goodsData);
  235. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  236. that.$set(that, `goods_total`, total);
  237. }
  238. },
  239. }
  240. }
  241. </script>
  242. <style lang="scss">
  243. .main {
  244. display: flex;
  245. flex-direction: column;
  246. width: 100vw;
  247. height: 100vh;
  248. .one {
  249. position: relative;
  250. flex-grow: 1;
  251. background-color: var(--f1Color);
  252. .one_1 {
  253. display: flex;
  254. justify-content: space-between;
  255. align-items: center;
  256. width: 100vw;
  257. padding: 2vw;
  258. border-bottom: 1vw dashed var(--fcColor);
  259. .address {
  260. flex-grow: 1;
  261. margin: 0 0 0 2vw;
  262. font-size: var(--font14Size);
  263. color: var(--f85Color);
  264. }
  265. .iconfont {
  266. font-size: var(--font20Szie);
  267. }
  268. .other {
  269. width: 82vw;
  270. padding: 0 2vw;
  271. .name {
  272. font-size: var(--font16Size);
  273. }
  274. .other_1 {
  275. font-size: var(--font14Size);
  276. color: var(--f85Color);
  277. text {
  278. margin: 0 1vw 0 0;
  279. }
  280. }
  281. }
  282. }
  283. .one_2 {
  284. margin: 2vw 0 0 0;
  285. .list {
  286. width: 100vw;
  287. margin: 2vw 0;
  288. .list_1 {
  289. padding: 2vw;
  290. background-color: var(--mainColor);
  291. border-bottom: 0.1vw solid var(--fcColor);
  292. text {
  293. padding: 0 0 0 1vw;
  294. }
  295. }
  296. .list_2 {
  297. padding: 2vw;
  298. display: flex;
  299. background-color: var(--mainColor);
  300. .l {
  301. width: 20vw;
  302. .image {
  303. width: 100%;
  304. height: 20vw;
  305. border-radius: 5px;
  306. }
  307. }
  308. .c {
  309. width: 60vw;
  310. padding: 0 2vw;
  311. .Spec {
  312. font-size: var(--font12Size);
  313. color: var(--f85Color);
  314. }
  315. }
  316. .r {
  317. width: 15vw;
  318. text-align: right;
  319. }
  320. }
  321. .list_3 {
  322. width: 96vw;
  323. padding: 2vw;
  324. background-color: var(--mainColor);
  325. .other {
  326. display: flex;
  327. justify-content: space-between;
  328. border-bottom: 0.1vw solid var(--fcColor);
  329. margin: 0 0 2vw 0;
  330. padding: 2vw 0;
  331. .other_1 {
  332. font-size: var(--font16Size);
  333. color: var(--f85Color);
  334. }
  335. .other_3 {
  336. flex-grow: 1;
  337. margin: 0 0 0 2vw;
  338. font-size: var(--font12Size);
  339. }
  340. text {
  341. padding: 0 1vw 0 0;
  342. font-size: var(--font20Szie);
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. .two {
  350. display: flex;
  351. justify-content: space-between;
  352. border-top: 0.1vw solid var(--fcColor);
  353. .two_1 {
  354. display: flex;
  355. align-items: center;
  356. padding: 0 2vw;
  357. font-size: var(--font16Size);
  358. view:last-child {
  359. margin: 0 0 0 2vw;
  360. color: var(--ff0Color);
  361. font-weight: bold;
  362. }
  363. }
  364. .two_2 {
  365. padding: 3vw 4vw;
  366. color: var(--mainColor);
  367. font-size: var(--font16Size);
  368. background-color: var(--ff0Color);
  369. }
  370. }
  371. }
  372. .scroll-view {
  373. position: absolute;
  374. top: 0;
  375. left: 0;
  376. right: 0;
  377. bottom: 0;
  378. .list-scroll-view {
  379. display: flex;
  380. flex-direction: row;
  381. flex-wrap: wrap;
  382. }
  383. }
  384. .content {
  385. display: flex;
  386. flex-direction: column;
  387. background-color: var(--f1Color);
  388. .one {
  389. display: flex;
  390. justify-content: space-between;
  391. margin: 2vw 0 0 0;
  392. padding: 2vw;
  393. background-color: var(--mainColor);
  394. .name {
  395. font-size: var(--font16Size);
  396. }
  397. .address {
  398. font-size: var(--font14Size);
  399. }
  400. .iconfont {
  401. line-height: 15vw;
  402. font-size: var(--font20Szie);
  403. }
  404. }
  405. .two {
  406. display: flex;
  407. justify-content: space-between;
  408. border-top: 0.1vw solid var(--fcColor);
  409. padding: 2vw;
  410. background-color: var(--mainColor);
  411. font-size: var(--font14Size);
  412. .text {
  413. margin: 0 2vw 0 0;
  414. border: 0.1vw solid var(--fFB1Color);
  415. padding: 1vw;
  416. font-size: var(--font12Size);
  417. border-radius: 2vw;
  418. color: var(--fFB1Color);
  419. }
  420. }
  421. }
  422. </style>