order_confirm.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <!-- +---------------------------------------------------------------------- -->
  2. <!-- | CRMEB [ CRMEB赋能开发者,助力企业发展 ] -->
  3. <!-- +---------------------------------------------------------------------- -->
  4. <!-- | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved. -->
  5. <!-- +---------------------------------------------------------------------- -->
  6. <!-- | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权 -->
  7. <!-- +---------------------------------------------------------------------- -->
  8. <!-- | Author: CRMEB Team <admin@crmeb.com> -->
  9. <!-- +---------------------------------------------------------------------- -->
  10. {extend name="public/container" /}
  11. {block name="title"}提交订单{/block}
  12. {block name="head"}
  13. <style>
  14. body {
  15. padding-bottom: 1.12rem;
  16. padding-bottom: calc(1.12rem + constant(safe-area-inset-bottom));
  17. padding-bottom: calc(1.12rem + env(safe-area-inset-bottom));
  18. background-color: #f5f5f5;
  19. }
  20. </style>
  21. {/block}
  22. {block name="content"}
  23. <div v-cloak id="app" class="order-confirm">
  24. <div class="contact" @click="addressCheck">
  25. <div>
  26. <template v-if="addressChecked">
  27. <template v-for="item in address">
  28. <template v-if="item.id === addressChecked">
  29. <div :key="item.id">
  30. <span>{{ item.real_name }}</span>
  31. <span>{{ item.phone }}</span>
  32. </div>
  33. <div class="address">
  34. <span>[默认]</span>
  35. <span>{{ item.province }}{{ item.city }}{{ item.district }}{{ item.detail }}</span>
  36. </div>
  37. </template>
  38. </template>
  39. </template>
  40. <template v-else>选择收货地址</template>
  41. </div>
  42. <div class="iconfont iconxiangyou"></div>
  43. </div>
  44. <div class="content">
  45. <div class="goods">
  46. <div v-for="item in cartInfo" :key="item.id" class="item">
  47. <div><img :src="item.productInfo.image"></div>
  48. <div class="item-bd">
  49. <div class="name">{{ item.productInfo.store_name }}</div>
  50. <div class="wrap">
  51. <div class="money">¥{{ level ? item.productInfo.vip_price : item.productInfo.price }}</div>
  52. <div class="count">
  53. <button type="button" :disabled="number === 1" @click="number--">-</button>
  54. <input v-model.number="number" type="number" readonly>
  55. <button type="button" :disabled="number === item.productInfo.stock" @click="number++">+</button>
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="postage">
  62. <div>邮费</div>
  63. <div>{{ postage }}</div>
  64. </div>
  65. <div class="deduct">
  66. <div>{$gold_name}抵扣</div>
  67. <div>当前{$gold_name} <span>{$gold_num}</span></div>
  68. <i v-if="goldNum" :class="[useGold ? 'iconxuanzhong1' : 'iconweixuanzhong', 'iconfont']" @click="useGold = !useGold"></i>
  69. </div>
  70. </div>
  71. <div class="remark">
  72. <div>备注信息</div>
  73. <textarea v-model="signs.mark" placeholder="选填备注信息" rows="3"></textarea>
  74. </div>
  75. <div class="footer">
  76. <div class="message">
  77. <div class="message-bd">共{{ number }}件,合计:<div class="money"><span>¥</span>{{ total }}</div>
  78. </div>
  79. <div v-if="useGold" class="message-ft">抵扣减:¥{{ diko }}</div>
  80. </div>
  81. <button type="button" @click="pay">立即结算</button>
  82. </div>
  83. <div :class="{ mask: popupShow }" @click="popupShow = false"></div>
  84. <!-- 地址弹窗 -->
  85. <div class="popup" :class="{ on: popupShow }">
  86. <button type="button" @click="popupShow = false"></button>
  87. <div class="head">选择地址</div>
  88. <div class="cont">
  89. <label v-for="item in address" :key="item.id">
  90. <input v-model="addressChecked" :value="item.id" type="radio" name="address" hidden>
  91. <div>
  92. <div>{{ item.real_name }} {{ item.phone }}</div>
  93. <div>{{ item.province }}{{ item.city }}{{ item.district }}{{ item.detail }}</div>
  94. </div>
  95. </label>
  96. </div>
  97. <div class="foot">
  98. <a @click="go_address">选择其他地址</a>
  99. </div>
  100. </div>
  101. <!-- 支付弹窗 -->
  102. <pay-dialog :open.sync="payDialogOpen" :signs="signs" :money="totals" :now_money="now_money" :special_id="addressChecked"
  103. :pay_type_num="pay_type_num" :is-wechat="isWechat" :is-alipay="is_alipay" :is-balance="isyue" :template-id="templateId"
  104. :wxpay-h5="wxpayH5" :use-gold="useGold" :is-member="level" :member-money="cartInfo[0].productInfo.vip_price" :member-link="memberLink"
  105. @change="changeVal"></pay-dialog>
  106. <base-login :login-show="loginShow" :site-name="site_name" @login-close="logComplete"></base-login>
  107. <quick-menu></quick-menu>
  108. </div>
  109. {/block}
  110. {block name="foot"}
  111. <script>
  112. require(['vue', 'store', 'helper', 'components/pay-dialog/index', 'components/base-login/index', 'quick'], function (Vue, api, $h, PayDialog, BaseLogin) {
  113. var cartInfo = {$cartInfo};
  114. var cartId = {$cartId};
  115. var priceGroup = {$priceGroup};
  116. var orderKey = '{$orderKey}';
  117. var ratio = {$ratio};
  118. var now_money = {$now_money};
  119. var is_yue = {$is_yue? 'true': 'false'};
  120. var site_name = '{$Auth_site_name}';
  121. var isWechat = {$isWechat? 'true': 'false'};
  122. var is_alipay = {$is_alipay? 'true': 'false'};
  123. var wxpayH5 = {$is_h5_wechat_payment_switch? 'true': 'false'};
  124. var callback_url = '{$callback_url}';
  125. var memberLink = "{:url('special/member_recharge')}";
  126. new Vue({
  127. el: '#app',
  128. components: {
  129. 'pay-dialog': PayDialog,
  130. 'base-login': BaseLogin
  131. },
  132. data: {
  133. isWechat: isWechat,
  134. loginShow: false,
  135. url: isWechat ? $h.U({c: 'index', a: 'login'}) : $h.U({c: 'login', a: 'phone_check'}),
  136. site_name: site_name,
  137. payDialogOpen: false, // 是否显示支付弹窗
  138. pay_type_num: 40,
  139. pinkId: '',
  140. link_pay_uid: '',
  141. isyue: is_yue, //余额是否开启
  142. is_alipay: is_alipay, //支付宝是否开启
  143. now_money: now_money, //余额
  144. cartId: cartId,
  145. cartInfo: cartInfo,
  146. priceGroup: priceGroup,
  147. popupShow: false,
  148. number: cartInfo ? cartInfo[0].cart_num : 1,
  149. totalPrice: 0,
  150. address: [],
  151. addressChecked: 0,
  152. totals: 0,
  153. postages: 0,
  154. signs: {
  155. key: orderKey,
  156. mark: ''
  157. },
  158. templateId: '',
  159. wxpayH5: wxpayH5,
  160. level: {$level},
  161. useGold: false,
  162. goldNum: {$gold_num},
  163. ratio: {$ratio},
  164. memberLink: memberLink
  165. },
  166. computed: {
  167. total: function () {
  168. if (!this.cartInfo) {
  169. return;
  170. }
  171. this.totals = $h.Mul(this.cartInfo[0].productInfo[this.level ? 'vip_price' : 'price'], this.number);
  172. this.totals = $h.Add(this.totals, this.postages);
  173. this.totals = $h.Sub(this.totals, this.useGold ? $h.Mul(this.goldNum, this.ratio) : 0);
  174. if (this.totals < 0) {
  175. this.totals = 0;
  176. }
  177. return this.totals;
  178. },
  179. postage: function () {
  180. if (!this.cartInfo) {
  181. return;
  182. }
  183. if (this.cartInfo[0].productInfo.is_postage || this.cartInfo[0].productInfo.free_shipping > 0 && this.cartInfo[0].productInfo.free_shipping <= this.number) {
  184. this.postages = 0;
  185. return '包邮';
  186. }
  187. this.postages = this.cartInfo[0].productInfo.postage;
  188. return '¥' + this.postages;
  189. },
  190. diko: function () {
  191. if (!this.cartInfo) {
  192. return;
  193. }
  194. var totals = $h.Mul(this.cartInfo[0].productInfo[this.level ? 'vip_price' : 'price'], this.number);
  195. totals = $h.Add(totals, this.postages);
  196. var goldTotals = $h.Mul(this.goldNum, this.ratio);
  197. if (totals >= goldTotals) {
  198. return goldTotals;
  199. } else {
  200. return totals;
  201. }
  202. }
  203. },
  204. watch: {
  205. addressChecked: function () {
  206. this.popupShow = false;
  207. this.subscribeTemplate();
  208. }
  209. },
  210. created: function () {
  211. this.getAddress();
  212. },
  213. methods: {
  214. subscribeTemplate: function () {
  215. api.baseGet($h.U({
  216. c: 'special',
  217. a: 'getTemplateIds',
  218. q: {
  219. pay_type_num: this.pay_type_num,
  220. special_id: this.addressChecked
  221. }
  222. }), function (res) {
  223. this.templateId = res.data.msg;
  224. }.bind(this));
  225. },
  226. getAddress: function () {
  227. $h.loadFFF();
  228. api.baseGet($h.U({c: 'auth_api', a: 'user_address_list'}), function (res) {
  229. $h.loadClear();
  230. var data = res.data.data;
  231. this.address = data;
  232. var result = data.find(function (value) {
  233. return value.is_default;
  234. }.bind(this));
  235. if (result) {
  236. this.addressChecked = result.id;
  237. }
  238. }.bind(this), function (err) {
  239. $h.loadClear();
  240. console.error(err.data.msg);
  241. }.bind(this));
  242. },
  243. addressCheck: function () {
  244. if (this.address.length) {
  245. this.popupShow = true;
  246. } else {
  247. this.go_address();
  248. }
  249. },
  250. go_address: function () {
  251. this.getOrderPrice(1);
  252. },
  253. getOrderPrice: function (n) {
  254. $h.loadFFF();
  255. api.baseGet($h.U({
  256. c: 'special',
  257. a: 'getOrderPrice',
  258. q: {
  259. cartId: this.cartId,
  260. cateNum: this.number
  261. }
  262. }), function (res) {
  263. $h.loadClear();
  264. if (n) {
  265. window.location = $h.U({c: 'my', a: 'edit_address', p: {cartId: this.cartId}});
  266. } else {
  267. var data = res.data.data;
  268. this.signs.key = data.orderKey;
  269. this.priceGroup = data.priceGroup;
  270. this.payDialogOpen = true;
  271. }
  272. }.bind(this), function (err) {
  273. $h.loadClear();
  274. }.bind(this));
  275. },
  276. pay: function () {
  277. if (!this.addressChecked) {
  278. return $h.pushMsg('请选择收货地址');
  279. }
  280. $h.loadFFF();
  281. api.baseGet($h.U({c: 'index', a: 'user_login'}), function (res) {
  282. $h.loadClear();
  283. this.getOrderPrice(0);
  284. }.bind(this), function (err) {
  285. $h.loadClear();
  286. this.loginShow = true;
  287. }.bind(this));
  288. },
  289. pay_order: function (data) {
  290. this.orderId = data.data.result.orderId || '';
  291. switch (data.data.status) {
  292. case "PAY_ERROR": case 'ORDER_EXIST': case 'ORDER_ERROR':
  293. this.extendOrder(data.msg);
  294. break;
  295. case 'WECHAT_PAY':
  296. this.wechatPay(data.data.result.jsConfig);
  297. break;
  298. case 'WECHAT_H5_PAY':
  299. this.payDialogOpen = false;
  300. var callbackUrl = callback_url + '?type=2&id=0';
  301. var mwebUrl = data.data.result.jsConfig.mweb_url + '&redirect_url=' + encodeURIComponent(callbackUrl);
  302. window.location.href = mwebUrl;
  303. break;
  304. case 'SUCCESS':
  305. this.successOrder(data.msg);
  306. break;
  307. case 'ZHIFUBAO_PAY':
  308. window.location = $h.U({m: 'wap', c: 'alipay', a: 'index', q: {info: data.data.result, params: 'goods'}});
  309. break;
  310. }
  311. },
  312. wechatPay: function (config) {
  313. var that = this;
  314. mapleWx($jssdk(), function () {
  315. this.chooseWXPay(config, function () {
  316. that.successOrder();
  317. }, {
  318. fail: that.extendOrder,
  319. cancel: that.extendOrder
  320. });
  321. });
  322. },
  323. successOrder: function (msg) {
  324. $h.showMsg({
  325. title: msg ? msg : '支付成功',
  326. icon: 'success',
  327. success: function () {
  328. window.location = "{:url('wap/special/order_store_list')}?type=1";
  329. }
  330. });
  331. },
  332. extendOrder: function (msg) {
  333. if (typeof msg === 'object') {
  334. if (msg.errMsg === 'chooseWXPay:cancel') {
  335. msg = '微信支付取消';
  336. } else {
  337. msg = '支付失败';
  338. }
  339. } else {
  340. msg = '支付失败';
  341. }
  342. $h.pushMsg(msg, function () {
  343. window.location = "{:url('wap/special/order_store_list')}?type=0";
  344. });
  345. },
  346. enter: function () {
  347. this.loginShow = true;
  348. },
  349. //关闭登录
  350. loginClose: function (value) {
  351. this.loginShow = false;
  352. value && this.logComplete();
  353. },
  354. //登录完成回调事件
  355. logComplete: function () {
  356. this.loginShow = false;
  357. },
  358. changeVal: function (opt) {
  359. if (typeof opt != 'object') opt = {};
  360. var action = opt.action || '';
  361. var value = opt.value || '';
  362. this[action] && this[action](value);
  363. }
  364. }
  365. });
  366. });
  367. </script>
  368. {/block}