order.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. total_detail:{},
  127. // 收货地址
  128. addressList: [],
  129. };
  130. },
  131. onLoad: async function(e) {
  132. const that = this;
  133. that.$set(that, `key`, e.key || '');
  134. that.watchLogin()
  135. },
  136. methods: {
  137. // 选择收货地址
  138. toChoose() {
  139. const that = this;
  140. that.$refs.popup.open();
  141. },
  142. // 是否选中
  143. toCheckbox(e) {
  144. const that = this;
  145. var addressList = that.addressList;
  146. var values = e.detail.value;
  147. for (var i = 0, lenI = addressList.length; i < lenI; ++i) {
  148. const item = addressList[i]
  149. if (values.includes(item._id)) {
  150. that.$set(item, 'checked', true)
  151. that.$set(that, `address`, item);
  152. } else {
  153. that.$set(item, 'checked', false)
  154. }
  155. }
  156. that.$refs.popup.close();
  157. },
  158. // 删除收货地址
  159. toDel(e) {
  160. const that = this;
  161. uni.showModal({
  162. title: '提示',
  163. content: '确定删除该地址吗?',
  164. success: async function(res) {
  165. if (res.confirm) {
  166. const arr = await that.$api(`/address/${e._id}`, 'DELETE');
  167. if (arr.errcode == '0') {
  168. uni.showToast({
  169. title: '删除信息成功',
  170. icon: 'none'
  171. })
  172. that.search();
  173. } else {
  174. uni.showToast({
  175. title: arr.errmsg,
  176. icon: 'none'
  177. })
  178. }
  179. }
  180. }
  181. });
  182. },
  183. // 提交订单
  184. async toSubmit() {
  185. const that = this;
  186. let data = {
  187. address: that.address,
  188. goods: that.orderList,
  189. total_detail: that.total_detail
  190. }
  191. const arr = await that.$api(`/order`, 'POST', data)
  192. if (arr.errcode == '0') {
  193. uni.showToast({
  194. title: `提交订单成功`,
  195. icon: 'none'
  196. })
  197. } else {
  198. uni.showToast({
  199. title: arr.data.msg,
  200. icon: 'none'
  201. })
  202. }
  203. },
  204. // 监听用户是否登录
  205. watchLogin() {
  206. const that = this;
  207. uni.getStorage({
  208. key: 'token',
  209. success: function(res) {
  210. let user = that.$jwt(res.data);
  211. that.$set(that, `user`, user);
  212. that.search()
  213. },
  214. fail: function(err) {
  215. uni.reLaunch({
  216. url: `/pages/login/index`
  217. })
  218. }
  219. })
  220. },
  221. // 查询列表
  222. async search() {
  223. const that = this;
  224. let user = that.user;
  225. const res = await that.$api(`/address`, 'GET', {
  226. customer: user._id
  227. })
  228. if (res.errcode == '0') {
  229. that.$set(that, `addressList`, res.data);
  230. }
  231. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  232. key: that.key
  233. })
  234. if (arr.errcode == '0') {
  235. that.$set(that, `address`, arr.data.address);
  236. that.$set(that, `orderList`, arr.data.goodsData);
  237. that.$set(that, `total_detail`, arr.data.orderTotal);
  238. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  239. that.$set(that, `goods_total`, total);
  240. }
  241. },
  242. }
  243. }
  244. </script>
  245. <style lang="scss">
  246. .main {
  247. display: flex;
  248. flex-direction: column;
  249. width: 100vw;
  250. height: 100vh;
  251. .one {
  252. position: relative;
  253. flex-grow: 1;
  254. background-color: var(--f1Color);
  255. .one_1 {
  256. display: flex;
  257. justify-content: space-between;
  258. align-items: center;
  259. width: 100vw;
  260. padding: 2vw;
  261. border-bottom: 1vw dashed var(--fcColor);
  262. .address {
  263. flex-grow: 1;
  264. margin: 0 0 0 2vw;
  265. font-size: var(--font14Size);
  266. color: var(--f85Color);
  267. }
  268. .iconfont {
  269. font-size: var(--font20Szie);
  270. }
  271. .other {
  272. width: 82vw;
  273. padding: 0 2vw;
  274. .name {
  275. font-size: var(--font16Size);
  276. }
  277. .other_1 {
  278. font-size: var(--font14Size);
  279. color: var(--f85Color);
  280. text {
  281. margin: 0 1vw 0 0;
  282. }
  283. }
  284. }
  285. }
  286. .one_2 {
  287. margin: 2vw 0 0 0;
  288. .list {
  289. width: 100vw;
  290. margin: 2vw 0;
  291. .list_1 {
  292. padding: 2vw;
  293. background-color: var(--mainColor);
  294. border-bottom: 0.1vw solid var(--fcColor);
  295. text {
  296. padding: 0 0 0 1vw;
  297. }
  298. }
  299. .list_2 {
  300. padding: 2vw;
  301. display: flex;
  302. background-color: var(--mainColor);
  303. .l {
  304. width: 20vw;
  305. .image {
  306. width: 100%;
  307. height: 20vw;
  308. border-radius: 5px;
  309. }
  310. }
  311. .c {
  312. width: 60vw;
  313. padding: 0 2vw;
  314. .Spec {
  315. font-size: var(--font12Size);
  316. color: var(--f85Color);
  317. }
  318. }
  319. .r {
  320. width: 15vw;
  321. text-align: right;
  322. }
  323. }
  324. .list_3 {
  325. width: 96vw;
  326. padding: 2vw;
  327. background-color: var(--mainColor);
  328. .other {
  329. display: flex;
  330. justify-content: space-between;
  331. border-bottom: 0.1vw solid var(--fcColor);
  332. margin: 0 0 2vw 0;
  333. padding: 2vw 0;
  334. .other_1 {
  335. font-size: var(--font16Size);
  336. color: var(--f85Color);
  337. }
  338. .other_3 {
  339. flex-grow: 1;
  340. margin: 0 0 0 2vw;
  341. font-size: var(--font12Size);
  342. }
  343. text {
  344. padding: 0 1vw 0 0;
  345. font-size: var(--font20Szie);
  346. }
  347. }
  348. }
  349. }
  350. }
  351. }
  352. .two {
  353. display: flex;
  354. justify-content: space-between;
  355. border-top: 0.1vw solid var(--fcColor);
  356. .two_1 {
  357. display: flex;
  358. align-items: center;
  359. padding: 0 2vw;
  360. font-size: var(--font16Size);
  361. view:last-child {
  362. margin: 0 0 0 2vw;
  363. color: var(--ff0Color);
  364. font-weight: bold;
  365. }
  366. }
  367. .two_2 {
  368. padding: 3vw 4vw;
  369. color: var(--mainColor);
  370. font-size: var(--font16Size);
  371. background-color: var(--ff0Color);
  372. }
  373. }
  374. }
  375. .scroll-view {
  376. position: absolute;
  377. top: 0;
  378. left: 0;
  379. right: 0;
  380. bottom: 0;
  381. .list-scroll-view {
  382. display: flex;
  383. flex-direction: row;
  384. flex-wrap: wrap;
  385. }
  386. }
  387. .content {
  388. display: flex;
  389. flex-direction: column;
  390. background-color: var(--f1Color);
  391. .one {
  392. display: flex;
  393. justify-content: space-between;
  394. margin: 2vw 0 0 0;
  395. padding: 2vw;
  396. background-color: var(--mainColor);
  397. .name {
  398. font-size: var(--font16Size);
  399. }
  400. .address {
  401. font-size: var(--font14Size);
  402. }
  403. .iconfont {
  404. line-height: 15vw;
  405. font-size: var(--font20Szie);
  406. }
  407. }
  408. .two {
  409. display: flex;
  410. justify-content: space-between;
  411. border-top: 0.1vw solid var(--fcColor);
  412. padding: 2vw;
  413. background-color: var(--mainColor);
  414. font-size: var(--font14Size);
  415. .text {
  416. margin: 0 2vw 0 0;
  417. border: 0.1vw solid var(--fFB1Color);
  418. padding: 1vw;
  419. font-size: var(--font12Size);
  420. border-radius: 2vw;
  421. color: var(--fFB1Color);
  422. }
  423. }
  424. }
  425. </style>