order.vue 9.8 KB

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