submit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <block v-if="address_id == ''">
  5. <view class="hflex acenter jbetween" @click="addAddr">
  6. <view class="title">新增收货地址</view>
  7. <u-icon name="arrow-right" color="#ABABAB" size="11"></u-icon>
  8. </view>
  9. </block>
  10. <block v-else>
  11. <view class="hflex acenter jbetween" @click="addAddr">
  12. <view class="hflex acenter">
  13. <u-icon name="map-fill" color="#506DFF" size="22"></u-icon>
  14. <view class="vflex" style="padding-left: 16rpx;">
  15. <view class="hflex acenter">
  16. <view class="text_style1" style="padding-right: 20rpx;">{{address.name}}</view>
  17. <view class="text_style1">{{address.phone}}</view>
  18. </view>
  19. <view class="text_style2">{{address.address}}</view>
  20. </view>
  21. </view>
  22. <u-icon name="arrow-right" color="#ABABAB" size="11"></u-icon>
  23. </view>
  24. </block>
  25. </view>
  26. <block v-if="pageList.length == 0">
  27. <view class="box">
  28. <view class="title">{{pageData.admin_name}}</view>
  29. <view class="hflex acenter cell">
  30. <image :src="pageData.items[item_id].show_image" mode="aspectFill" class="img"></image>
  31. <view class="img_right">
  32. <view class="hflex acenter jbetween">
  33. <view class="item_name text_hide" style="width: 374rpx;">{{pageData.name}}</view>
  34. <view class="item_name">¥{{pageData.items[item_id].price_selling}}</view>
  35. </view>
  36. <view class="hflex jbetween" style="padding: 2rpx 0 0;">
  37. <view class="norm">{{pageData.items[item_id].goods_spec}}</view>
  38. <view class="left_text">X{{buy_num}}</view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="hflex acenter jbetween">
  43. <view class="title">订单备注</view>
  44. <u-input v-model="remarks" inputAlign="right" border="none" placeholder="建议留言前先与商家沟通确认"></u-input>
  45. </view>
  46. </view>
  47. </block>
  48. <block v-if="pageList.length > 0">
  49. <block v-for="(item,index) in pageList" :key="index">
  50. <view class="box">
  51. <view class="title">{{item.nickname}}</view>
  52. <block v-for="(item2,index2) in item.goods_item" :key="index">
  53. <view class="hflex acenter cell">
  54. <image :src="item2.show_image" mode="aspectFill" class="img"></image>
  55. <view class="img_right">
  56. <view class="hflex acenter jbetween">
  57. <view class="item_name text_hide" style="width: 374rpx;">{{item2.name}}</view>
  58. <view class="item_name">¥{{item2.price_selling}}</view>
  59. </view>
  60. <view class="hflex jbetween" style="padding: 2rpx 0 0;">
  61. <view class="norm">{{item2.goods_spec}}</view>
  62. <view class="left_text">X{{item2.num}}</view>
  63. </view>
  64. </view>
  65. </view>
  66. </block>
  67. <view class="hflex acenter jbetween">
  68. <view class="title">订单备注</view>
  69. <u-input v-model="remarks" inputAlign="right" border="none" placeholder="建议留言前先与商家沟通确认"></u-input>
  70. </view>
  71. </view>
  72. </block>
  73. </block>
  74. <view class="box" v-if="pageList.length == 0">
  75. <view class="hflex acenter jbetween">
  76. <view class="left_text">商品金额</view>
  77. <view class="right_text">¥{{total}}</view>
  78. </view>
  79. <!-- <view class="hflex acenter jbetween cell2">
  80. <view class="left_text">运费</view>
  81. <view class="right_text">¥0.00</view>
  82. </view> -->
  83. <view class="hflex acenter jend item_bottom">
  84. <view class="title" style="font-size: 22rpx;">合计:<span class="text_red">¥{{total}}</span></view>
  85. </view>
  86. </view>
  87. <view class="box" v-if="pageList.length > 0">
  88. <view class="hflex acenter jbetween">
  89. <view class="left_text">商品金额</view>
  90. <view class="right_text">¥{{total}}</view>
  91. </view>
  92. <!-- <view class="hflex acenter jbetween cell2">
  93. <view class="left_text">运费</view>
  94. <view class="right_text">¥{{freight}}</view>
  95. </view> -->
  96. <view class="hflex acenter jend item_bottom">
  97. <view class="title" style="font-size: 22rpx;">合计:<span class="text_red">¥{{total}}</span></view>
  98. </view>
  99. </view>
  100. <view class="box hflex acenter jbetween" style="margin-bottom: 186rpx;">
  101. <view class="hflex acenter">
  102. <image src="/static/images/shop/wx_pay.png" class="pay_icon"></image>
  103. <view class="text_style1">微信支付</view>
  104. </view>
  105. <u-radio-group>
  106. <u-radio activeColor="#506DFF"></u-radio>
  107. </u-radio-group>
  108. </view>
  109. <view class="bottom hflex acenter jend">
  110. <view class="title" style="font-size: 22rpx;" v-if="pageList.length == 0">合计:<span class="text_blue">¥{{total}}</span></view>
  111. <view class="title" style="font-size: 22rpx;" v-else>合计:<span class="text_blue">¥{{total}}</span></view>
  112. <view class="btn" @click="submit">提交订单</view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import $api from '@/static/js/api.js'
  118. var that = ''
  119. export default {
  120. data() {
  121. return {
  122. address: {
  123. },
  124. pageData: {},
  125. pageList: [],
  126. order_id: '',
  127. address_id: '',
  128. pay_no:'',
  129. total: 0,
  130. freight: '0.00',
  131. item_id: '',
  132. cart_ids: '',
  133. buy_num: 1,
  134. remarks: ''
  135. }
  136. },
  137. onLoad(options) {
  138. that = this
  139. console.log(options);
  140. // that.address_id = uni.getStorageSync('address_id')
  141. if(options.address_id) {
  142. that.address_id = options.address_id
  143. }
  144. if(options.pageData) {
  145. that.pageData = JSON.parse(options.pageData)
  146. console.log('that.pageData',that.pageData);
  147. that.item_id = options.item_id
  148. that.buy_num = Number(options.buy_num)
  149. // pageData.items[item_id].goods_spec = $api.resetspec(pageData.items[item_id].goods_spec)
  150. that.total = (Number(that.pageData.items[that.item_id].price_selling) * that.buy_num).toFixed(2)
  151. that.pageData.items[that.item_id].goods_spec = $api.resetspec(that.pageData.items[that.item_id].goods_spec)
  152. } else {
  153. if(options.data) {
  154. that.pageList = JSON.parse(options.data)
  155. that.cart_ids = options.cart_ids
  156. that.count()
  157. for(var i=0;i<that.pageList.length;i++) {
  158. for(var j=0;j<that.pageList[i].goods_item.length;j++) {
  159. that.pageList[i].goods_item[j].goods_spec = $api.resetspec(that.pageList[i].goods_item[j].goods_spec)
  160. }
  161. }
  162. }
  163. }
  164. },
  165. onShow() {
  166. that.getAddr()
  167. },
  168. methods: {
  169. getData() {
  170. $api.req({
  171. url: '/data/api.Order/order_info',
  172. method: 'POST',
  173. data: {
  174. order_id: that.order_id,
  175. }
  176. }, function(res) {
  177. if(res.code == 1) {
  178. $api.info(res.info)
  179. that.pageData = res.data
  180. }
  181. })
  182. },
  183. count() {
  184. console.log(that.pageList);
  185. for(var i=0;i<that.pageList.length;i++) {
  186. for(var j=0;j<that.pageList[i].goods_item.length;j++) {
  187. console.log(that.pageList[i].goods_item[j]);
  188. if(that.pageList[i].goods_item[j].num != 0) {
  189. that.total += Number(that.pageList[i].goods_item[j].price_selling) * Number(that.pageList[i].goods_item[j].num)
  190. } else {
  191. that.total += Number(that.pageList[i].goods_item[j].price_selling) * Number(that.pageList[i].goods_item[j].stock_sales)
  192. }
  193. }
  194. }
  195. that.total = that.total.toFixed(2)
  196. },
  197. getAddr() {
  198. that.address_id = uni.getStorageSync('address_id')
  199. if(that.address_id == '') {
  200. return
  201. }
  202. $api.req({
  203. url: '/data/api.User/address_list'
  204. }, function(res) {
  205. if(res.code == 1) {
  206. for(var i=0;i<res.data.data.length;i++) {
  207. if(res.data.data[i].id == that.address_id) {
  208. that.address = res.data.data[i]
  209. }
  210. }
  211. }
  212. })
  213. },
  214. addAddr() {
  215. $api.jump('/page_shop/pages/address/list?select=true')
  216. },
  217. submit() {
  218. if(!that.address_id) {
  219. $api.info("请先选择地址")
  220. return
  221. }
  222. if(!that.address.name) {
  223. $api.info("请先选择地址")
  224. return
  225. }
  226. var openid = uni.getStorageSync('openid1')
  227. if(!openid) {
  228. $api.info("登录验证有误,请重新登录")
  229. return
  230. }
  231. if(that.item_id) {
  232. $api.req({
  233. url: '/data/api.Order/order_create',
  234. method: 'POST',
  235. data: {
  236. admin_id: that.pageData.admin_id,
  237. item_id: that.pageData.items[that.item_id].id,
  238. num: that.buy_num,
  239. address_id: that.address_id,
  240. order_remark: that.remarks
  241. }
  242. }, function(res) {
  243. if(res.code == 1) {
  244. that.order_id = res.data.order_id
  245. that.pay_no = res.data.pay_no
  246. $api.req({
  247. url: '/data/api.auth.Center/channel',
  248. method: 'POST',
  249. data: {
  250. type: 2,
  251. from: 1
  252. }
  253. }, function(res) {
  254. if(res.code == 1) {
  255. var pay_code = res.data[0].code
  256. $api.req({
  257. url: '/data/api.Order/order_pay',
  258. method: 'POST',
  259. data: {
  260. pay_code: pay_code,
  261. pay_no: that.pay_no,
  262. type: 'wechat'
  263. }
  264. }, function(res) {
  265. if(res.code == 1) {
  266. wx.requestPayment({
  267. timeStamp: res.data.pay.timeStamp,
  268. nonceStr: res.data.pay.nonceStr,
  269. package: res.data.pay.package,
  270. signType: 'MD5',
  271. paySign: res.data.pay.paySign,
  272. success (res) {
  273. $api.jump('/page_shop/pages/order/paySuccess?id=' +that.order_id ,2)
  274. },
  275. fail (res) { }
  276. })
  277. }
  278. })
  279. }
  280. })
  281. }
  282. })
  283. } else {
  284. $api.req({
  285. url: '/data/api.Order/crat_create',
  286. method: 'POST',
  287. data: {
  288. cart_ids: that.cart_ids,
  289. address_id: that.address_id,
  290. order_remark: that.remarks
  291. }
  292. }, function(res) {
  293. if(res.code == 1) {
  294. that.pay_no = res.data
  295. $api.req({
  296. url: '/data/api.auth.Center/channel',
  297. method: 'POST',
  298. data: {
  299. type: 2,
  300. from: 1
  301. }
  302. }, function(res) {
  303. if(res.code == 1) {
  304. var pay_code = res.data[0].code
  305. $api.req({
  306. url: '/data/api.Order/order_pay',
  307. method: 'POST',
  308. data: {
  309. pay_code: pay_code,
  310. pay_no: that.pay_no,
  311. type: 'wechat'
  312. }
  313. }, function(res) {
  314. if(res.code == 1) {
  315. wx.requestPayment({
  316. timeStamp: res.data.pay.timeStamp,
  317. nonceStr: res.data.pay.nonceStr,
  318. package: res.data.pay.package,
  319. signType: 'MD5',
  320. paySign: res.data.pay.paySign,
  321. success (res) {
  322. $api.jump('/page_shop/pages/order/paySuccess?id=' +that.order_id ,2)
  323. },
  324. fail (res) { }
  325. })
  326. }
  327. })
  328. }
  329. })
  330. }
  331. })
  332. }
  333. }
  334. },
  335. }
  336. </script>
  337. <style lang="scss" scoped>
  338. .content::v-deep {
  339. background-color: #F4F4F4;
  340. .box {
  341. background: #FFFFFF;
  342. border-radius: 10px;
  343. margin: 20rpx auto 0;
  344. width: 690rpx;
  345. box-sizing: border-box;
  346. padding: 34rpx 20rpx;
  347. .title {
  348. font-size: 32rpx;
  349. font-weight: 500;
  350. color: #222222;
  351. line-height: 44rpx;
  352. }
  353. .text_style1 {
  354. font-size: 28rpx;
  355. font-weight: 500;
  356. color: #222222;
  357. line-height: 40rpx;
  358. }
  359. .text_style2 {
  360. font-size: 26rpx;
  361. font-weight: 400;
  362. color: #888888;
  363. line-height: 36rpx;
  364. }
  365. .cell {
  366. padding: 20rpx 0 32rpx;
  367. }
  368. .cell2 {
  369. padding: 32rpx 0 20rpx;
  370. }
  371. .img {
  372. width: 160rpx;
  373. height: 160rpx;
  374. border-radius: 24rpx;
  375. }
  376. .img_right {
  377. width:calc(100% - 160rpx);
  378. padding-left: 20rpx;
  379. .item_name {
  380. font-size: 30rpx;
  381. font-weight: 400;
  382. color: #222222;
  383. line-height: 42rpx;
  384. }
  385. .norm {
  386. max-width: 288rpx;
  387. width: max-content;
  388. // height: 42px;
  389. background: #F5F5F5;
  390. border-radius: 12rpx;
  391. box-sizing: border-box;
  392. padding: 12rpx 12rpx 5rpx;
  393. font-size: 20rpx;
  394. font-weight: 400;
  395. color: #888888;
  396. line-height: 28rpx;
  397. text-overflow: ellipsis;
  398. overflow: hidden;
  399. display: -webkit-box;
  400. -webkit-box-orient: vertical;
  401. box-orient: vertical;
  402. line-clamp: 2;
  403. -webkit-line-clamp: 2;
  404. }
  405. }
  406. .left_text {
  407. font-size: 24rpx;
  408. font-weight: 500;
  409. color: #888888;
  410. line-height: 28rpx;
  411. }
  412. .right_text {
  413. font-size: 24rpx;
  414. font-weight: bold;
  415. color: #222222;
  416. line-height: 28rpx;
  417. }
  418. .item_bottom {
  419. padding-top: 22rpx;
  420. border-top: 1rpx solid #F4F4F4;
  421. }
  422. .text_red {
  423. font-weight: bold;
  424. color: #EE5850;
  425. }
  426. .pay_icon {
  427. width: 48rpx;
  428. height: 48rpx;
  429. margin-right: 20rpx;
  430. }
  431. .check_icon {
  432. width: 32rpx;
  433. height: 32rpx;
  434. }
  435. }
  436. .u-radio-group {
  437. flex: 0 !important;
  438. }
  439. .bottom {
  440. width: 100%;
  441. height: 166rpx;
  442. background: #FFFFFF;
  443. z-index: 9;
  444. position: fixed;
  445. bottom: 0;
  446. box-sizing: border-box;
  447. padding: 8rpx 50rpx 74rpx;
  448. .title {
  449. font-size: 24rpx;
  450. font-weight: 400;
  451. color: #222222;
  452. line-height: 34rpx;
  453. }
  454. .text_blue {
  455. font-size: 44rpx;
  456. color: #5270FF;
  457. }
  458. .btn{
  459. margin-left: 16rpx;
  460. width: 260rpx;
  461. height: 84rpx;
  462. background: #506DFF;
  463. border-radius: 42rpx;
  464. text-align: center;
  465. font-size: 36rpx;
  466. font-weight: 500;
  467. color: #FFFFFF;
  468. line-height: 84rpx;
  469. }
  470. }
  471. }
  472. </style>