order.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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.getStorage({
  194. key: 'system',
  195. success: function(res) {
  196. // 微信小程序支付
  197. if (res.data.uniPlatform == "mp-weixin") {
  198. uni.requestPayment({
  199. "provider": "wxpay",
  200. "orderInfo": {
  201. "appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  202. "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
  203. "package": "Sign=WXPay", // 固定值
  204. "partnerid": "148*****52", // 微信支付商户号
  205. "prepayid": "wx202254********************fbe90000", // 统一下单订单号
  206. "timestamp": 1597935292, // 时间戳(单位:秒)
  207. "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5/RSA 签名
  208. },
  209. success(res) {},
  210. fail(e) {}
  211. })
  212. } else if (res.data.uniPlatform == "app") {
  213. // app支付
  214. uni.requestPayment({
  215. provider: 'alipay',
  216. orderInfo: 'orderInfo', //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
  217. success: function(res) {
  218. console.log('success:' + JSON.stringify(res));
  219. },
  220. fail: function(err) {
  221. console.log('fail:' + JSON.stringify(err));
  222. }
  223. });
  224. } else {
  225. uni.showToast({
  226. title: `平台不支持支付`,
  227. icon: 'none'
  228. })
  229. }
  230. },
  231. fail: function(err) {}
  232. })
  233. } else {
  234. uni.showToast({
  235. title: arr.data.msg,
  236. icon: 'none'
  237. })
  238. }
  239. },
  240. // 监听用户是否登录
  241. watchLogin() {
  242. const that = this;
  243. uni.getStorage({
  244. key: 'token',
  245. success: function(res) {
  246. let user = that.$jwt(res.data);
  247. that.$set(that, `user`, user);
  248. that.search()
  249. },
  250. fail: function(err) {
  251. uni.reLaunch({
  252. url: `/pages/login/index`
  253. })
  254. }
  255. })
  256. },
  257. // 查询列表
  258. async search() {
  259. const that = this;
  260. let user = that.user;
  261. const res = await that.$api(`/address`, 'GET', {
  262. customer: user._id
  263. })
  264. if (res.errcode == '0') {
  265. that.$set(that, `addressList`, res.data);
  266. }
  267. const arr = await that.$api(`/order/toMakeOrder`, 'POST', {
  268. key: that.key
  269. })
  270. if (arr.errcode == '0') {
  271. that.$set(that, `address`, arr.data.address);
  272. that.$set(that, `orderList`, arr.data.goodsData);
  273. that.$set(that, `total_detail`, arr.data.orderTotal);
  274. var total = arr.data.orderTotal.freight_total + arr.data.orderTotal.goods_total
  275. that.$set(that, `goods_total`, total);
  276. }
  277. },
  278. }
  279. }
  280. </script>
  281. <style lang="scss">
  282. .main {
  283. display: flex;
  284. flex-direction: column;
  285. width: 100vw;
  286. height: 100vh;
  287. .one {
  288. position: relative;
  289. flex-grow: 1;
  290. background-color: var(--f1Color);
  291. .one_1 {
  292. display: flex;
  293. justify-content: space-between;
  294. align-items: center;
  295. width: 100vw;
  296. padding: 2vw;
  297. border-bottom: 1vw dashed var(--fcColor);
  298. .address {
  299. flex-grow: 1;
  300. margin: 0 0 0 2vw;
  301. font-size: var(--font14Size);
  302. color: var(--f85Color);
  303. }
  304. .iconfont {
  305. font-size: var(--font20Szie);
  306. }
  307. .other {
  308. width: 82vw;
  309. padding: 0 2vw;
  310. .name {
  311. font-size: var(--font16Size);
  312. }
  313. .other_1 {
  314. font-size: var(--font14Size);
  315. color: var(--f85Color);
  316. text {
  317. margin: 0 1vw 0 0;
  318. }
  319. }
  320. }
  321. }
  322. .one_2 {
  323. margin: 2vw 0 0 0;
  324. .list {
  325. width: 100vw;
  326. margin: 2vw 0;
  327. .list_1 {
  328. padding: 2vw;
  329. background-color: var(--mainColor);
  330. border-bottom: 0.1vw solid var(--fcColor);
  331. text {
  332. padding: 0 0 0 1vw;
  333. }
  334. }
  335. .list_2 {
  336. padding: 2vw;
  337. display: flex;
  338. background-color: var(--mainColor);
  339. .l {
  340. width: 20vw;
  341. .image {
  342. width: 100%;
  343. height: 20vw;
  344. border-radius: 5px;
  345. }
  346. }
  347. .c {
  348. width: 60vw;
  349. padding: 0 2vw;
  350. .Spec {
  351. font-size: var(--font12Size);
  352. color: var(--f85Color);
  353. }
  354. }
  355. .r {
  356. width: 15vw;
  357. text-align: right;
  358. }
  359. }
  360. .list_3 {
  361. width: 96vw;
  362. padding: 2vw;
  363. background-color: var(--mainColor);
  364. .other {
  365. display: flex;
  366. justify-content: space-between;
  367. border-bottom: 0.1vw solid var(--fcColor);
  368. margin: 0 0 2vw 0;
  369. padding: 2vw 0;
  370. .other_1 {
  371. font-size: var(--font16Size);
  372. color: var(--f85Color);
  373. }
  374. .other_3 {
  375. flex-grow: 1;
  376. margin: 0 0 0 2vw;
  377. font-size: var(--font12Size);
  378. }
  379. text {
  380. padding: 0 1vw 0 0;
  381. font-size: var(--font20Szie);
  382. }
  383. }
  384. }
  385. }
  386. }
  387. }
  388. .two {
  389. display: flex;
  390. justify-content: space-between;
  391. border-top: 0.1vw solid var(--fcColor);
  392. .two_1 {
  393. display: flex;
  394. align-items: center;
  395. padding: 0 2vw;
  396. font-size: var(--font16Size);
  397. view:last-child {
  398. margin: 0 0 0 2vw;
  399. color: var(--ff0Color);
  400. font-weight: bold;
  401. }
  402. }
  403. .two_2 {
  404. padding: 3vw 4vw;
  405. color: var(--mainColor);
  406. font-size: var(--font16Size);
  407. background-color: var(--ff0Color);
  408. }
  409. }
  410. }
  411. .scroll-view {
  412. position: absolute;
  413. top: 0;
  414. left: 0;
  415. right: 0;
  416. bottom: 0;
  417. .list-scroll-view {
  418. display: flex;
  419. flex-direction: row;
  420. flex-wrap: wrap;
  421. }
  422. }
  423. .content {
  424. display: flex;
  425. flex-direction: column;
  426. background-color: var(--f1Color);
  427. .one {
  428. display: flex;
  429. justify-content: space-between;
  430. margin: 2vw 0 0 0;
  431. padding: 2vw;
  432. background-color: var(--mainColor);
  433. .name {
  434. font-size: var(--font16Size);
  435. }
  436. .address {
  437. font-size: var(--font14Size);
  438. }
  439. .iconfont {
  440. line-height: 15vw;
  441. font-size: var(--font20Szie);
  442. }
  443. }
  444. .two {
  445. display: flex;
  446. justify-content: space-between;
  447. border-top: 0.1vw solid var(--fcColor);
  448. padding: 2vw;
  449. background-color: var(--mainColor);
  450. font-size: var(--font14Size);
  451. .text {
  452. margin: 0 2vw 0 0;
  453. border: 0.1vw solid var(--fFB1Color);
  454. padding: 1vw;
  455. font-size: var(--font12Size);
  456. border-radius: 2vw;
  457. color: var(--fFB1Color);
  458. }
  459. }
  460. }
  461. </style>