submit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. <template>
  2. <view class="content">
  3. <view class="box">
  4. <block v-if="JSON.stringify(address) == '{}'">
  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)?Number(options.buy_num):1
  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. that.address = res.data.data[0]
  208. that.address_id = that.address.id
  209. }
  210. }
  211. })
  212. },
  213. addAddr() {
  214. $api.jump('/page_shop/pages/address/list?select=true')
  215. },
  216. submit() {
  217. if(JSON.stringify(that.address) == '{}') {
  218. $api.info("请先选择地址")
  219. return
  220. }
  221. if(!that.address.name) {
  222. $api.info("请先选择地址")
  223. return
  224. }
  225. if(that.item_id) {
  226. $api.req({
  227. url: '/data/api.Order/order_create',
  228. method: 'POST',
  229. data: {
  230. admin_id: that.pageData.admin_id,
  231. item_id: that.pageData.items[that.item_id].id,
  232. num: that.buy_num,
  233. address_id: that.address_id,
  234. order_remark: that.remarks
  235. }
  236. }, function(res) {
  237. if(res.code == 1) {
  238. that.order_id = res.data.order_id
  239. that.pay_no = res.data.pay_no
  240. $api.req({
  241. url: '/data/api.auth.Center/channel',
  242. method: 'POST',
  243. data: {
  244. type: 2,
  245. from: 1
  246. }
  247. }, function(res) {
  248. if(res.code == 1) {
  249. var pay_code = res.data[0].code
  250. $api.req({
  251. url: '/data/api.Order/order_pay',
  252. method: 'POST',
  253. data: {
  254. pay_code: pay_code,
  255. pay_no: that.pay_no,
  256. type: 'wechat'
  257. }
  258. }, function(res) {
  259. if(res.code == 1) {
  260. wx.requestPayment({
  261. timeStamp: res.data.pay.timeStamp,
  262. nonceStr: res.data.pay.nonceStr,
  263. package: res.data.pay.package,
  264. signType: 'MD5',
  265. paySign: res.data.pay.paySign,
  266. success (res) {
  267. $api.jump('/page_shop/pages/order/paySuccess?id=' +that.order_id ,2)
  268. },
  269. fail (res) {
  270. console.log(res);
  271. }
  272. })
  273. }
  274. })
  275. }
  276. })
  277. }
  278. })
  279. } else {
  280. $api.req({
  281. url: '/data/api.Order/crat_create',
  282. method: 'POST',
  283. data: {
  284. cart_ids: that.cart_ids,
  285. address_id: that.address_id,
  286. order_remark: that.remarks
  287. }
  288. }, function(res) {
  289. if(res.code == 1) {
  290. that.pay_no = res.data
  291. $api.req({
  292. url: '/data/api.auth.Center/channel',
  293. method: 'POST',
  294. data: {
  295. type: 2,
  296. from: 1
  297. }
  298. }, function(res) {
  299. if(res.code == 1) {
  300. var pay_code = res.data[0].code
  301. $api.req({
  302. url: '/data/api.Order/order_pay',
  303. method: 'POST',
  304. data: {
  305. pay_code: pay_code,
  306. pay_no: that.pay_no,
  307. type: 'wechat'
  308. }
  309. }, function(res) {
  310. if(res.code == 1) {
  311. wx.requestPayment({
  312. timeStamp: res.data.pay.timeStamp,
  313. nonceStr: res.data.pay.nonceStr,
  314. package: res.data.pay.package,
  315. signType: 'MD5',
  316. paySign: res.data.pay.paySign,
  317. success (res) {
  318. $api.jump('/page_shop/pages/order/paySuccess?id=' +that.order_id ,2)
  319. },
  320. fail (res) { }
  321. })
  322. }
  323. })
  324. }
  325. })
  326. }
  327. })
  328. }
  329. }
  330. },
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .content::v-deep {
  335. background-color: #F4F4F4;
  336. .box {
  337. background: #FFFFFF;
  338. border-radius: 10px;
  339. margin: 20rpx auto 0;
  340. width: 690rpx;
  341. box-sizing: border-box;
  342. padding: 34rpx 20rpx;
  343. .title {
  344. font-size: 32rpx;
  345. font-weight: 500;
  346. color: #222222;
  347. line-height: 44rpx;
  348. }
  349. .text_style1 {
  350. font-size: 28rpx;
  351. font-weight: 500;
  352. color: #222222;
  353. line-height: 40rpx;
  354. }
  355. .text_style2 {
  356. font-size: 26rpx;
  357. font-weight: 400;
  358. color: #888888;
  359. line-height: 36rpx;
  360. }
  361. .cell {
  362. padding: 20rpx 0 32rpx;
  363. }
  364. .cell2 {
  365. padding: 32rpx 0 20rpx;
  366. }
  367. .img {
  368. width: 160rpx;
  369. height: 160rpx;
  370. border-radius: 24rpx;
  371. }
  372. .img_right {
  373. width:calc(100% - 160rpx);
  374. padding-left: 20rpx;
  375. .item_name {
  376. font-size: 30rpx;
  377. font-weight: 400;
  378. color: #222222;
  379. line-height: 42rpx;
  380. }
  381. .norm {
  382. max-width: 288rpx;
  383. width: max-content;
  384. // height: 42px;
  385. background: #F5F5F5;
  386. border-radius: 12rpx;
  387. box-sizing: border-box;
  388. padding: 12rpx 12rpx 5rpx;
  389. font-size: 20rpx;
  390. font-weight: 400;
  391. color: #888888;
  392. line-height: 28rpx;
  393. text-overflow: ellipsis;
  394. overflow: hidden;
  395. display: -webkit-box;
  396. -webkit-box-orient: vertical;
  397. box-orient: vertical;
  398. line-clamp: 2;
  399. -webkit-line-clamp: 2;
  400. }
  401. }
  402. .left_text {
  403. font-size: 24rpx;
  404. font-weight: 500;
  405. color: #888888;
  406. line-height: 28rpx;
  407. }
  408. .right_text {
  409. font-size: 24rpx;
  410. font-weight: bold;
  411. color: #222222;
  412. line-height: 28rpx;
  413. }
  414. .item_bottom {
  415. padding-top: 22rpx;
  416. border-top: 1rpx solid #F4F4F4;
  417. }
  418. .text_red {
  419. font-weight: bold;
  420. color: #EE5850;
  421. }
  422. .pay_icon {
  423. width: 48rpx;
  424. height: 48rpx;
  425. margin-right: 20rpx;
  426. }
  427. .check_icon {
  428. width: 32rpx;
  429. height: 32rpx;
  430. }
  431. }
  432. .u-radio-group {
  433. flex: 0 !important;
  434. }
  435. .bottom {
  436. width: 100%;
  437. height: 166rpx;
  438. background: #FFFFFF;
  439. z-index: 9;
  440. position: fixed;
  441. bottom: 0;
  442. box-sizing: border-box;
  443. padding: 8rpx 50rpx 74rpx;
  444. .title {
  445. font-size: 24rpx;
  446. font-weight: 400;
  447. color: #222222;
  448. line-height: 34rpx;
  449. }
  450. .text_blue {
  451. font-size: 44rpx;
  452. color: #5270FF;
  453. }
  454. .btn{
  455. margin-left: 16rpx;
  456. width: 260rpx;
  457. height: 84rpx;
  458. background: #506DFF;
  459. border-radius: 42rpx;
  460. text-align: center;
  461. font-size: 36rpx;
  462. font-weight: 500;
  463. color: #FFFFFF;
  464. line-height: 84rpx;
  465. }
  466. }
  467. }
  468. </style>