order.vue 9.8 KB

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