index.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. {include file="public/head"}
  5. <link href="/system/frame/css/style.min.css?v=3.0.0" rel="stylesheet">
  6. <title>{$title|default=''}</title>
  7. <style>
  8. .flex {
  9. display: flex;
  10. justify-content: flex-start;
  11. align-items: center;
  12. }
  13. .no-shink {
  14. flex-shrink: 0;
  15. }
  16. .mar-l-10 {
  17. margin-left: 10px;
  18. }
  19. .mar-b-10 {
  20. margin-bottom: 10px;
  21. }
  22. .padd-15 {
  23. padding: 0 15px !important;
  24. }
  25. .shopBOx {
  26. margin: 15px 10px !important;
  27. }
  28. .alertBottom {
  29. position: fixed !important;
  30. bottom: 0;
  31. left: 0;
  32. padding-left: 30px !important;
  33. width: 100%;
  34. background-color: #ffffff;
  35. }
  36. .shopImg {
  37. width: 100px;
  38. height: 100px;
  39. }
  40. .clamp2 {
  41. overflow: hidden;
  42. text-overflow: ellipsis;
  43. display: -webkit-box;
  44. -webkit-line-clamp: 2;
  45. -webkit-box-orient: vertical;
  46. }
  47. .itemStart {
  48. align-items: flex-start;
  49. }
  50. .flexcontent {
  51. justify-content: center;
  52. }
  53. .text-cente {
  54. text-align: center
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <div class="wrapper wrapper-content">
  60. <div class="row">
  61. <div class="col-sm-12">
  62. <div class="ibox float-e-margins ">
  63. <div class="ibox-title">
  64. <h5>在线下单</h5>
  65. </div>
  66. <div id="store-attr" class="mp-form" v-cloak="">
  67. <Row class="searchBox padd-15 mar-b-10 mar-l-10" v-if="UserCard">
  68. <i-Col span="6">
  69. <div class="flex">
  70. <span class="no-shink">当前会员卡号:{{UserCard}} &nbsp; 会员余额:{{userData.now_money}} &nbsp; 消费券:{{userData.integral}} &nbsp; 手机号:{{userData.phone}}</span>
  71. </div>
  72. </i-Col>
  73. </Row>
  74. <Row class="searchBox padd-15" v-if="UserCard">
  75. <i-Col span="6">
  76. <div class="flex">
  77. <span class="no-shink mar-l-10">是否消费券:</span>
  78. <radio-group v-model="is_consumer" type="button">
  79. <Radio :label="1">是</Radio>
  80. <Radio :label="0">否</Radio>
  81. </radio-group>
  82. </div>
  83. </i-Col>
  84. <i-Col span="12">
  85. <div class="flex">
  86. <span class="no-shink mar-l-10">条形码:</span>
  87. <i-Input ref="code" placeholder="请扫描或输入条形码" @on-enter="getShopNum" v-model="shopId"
  88. type="text"></i-Input>
  89. <i-Button class="mar-l-10" type="primary" @click="getShopNum">添加商品</i-Button>
  90. </div>
  91. </i-Col>
  92. </Row>
  93. <Row class="searchBox padd-15" v-else>
  94. <i-Col span="8">
  95. <div class="flex">
  96. <span class="no-shink">会员卡号:</span>
  97. <i-Input ref="usercard" placeholder="请输入会员卡号" v-model="userCardInput" type="text"
  98. @on-enter="checkedUserCard"></i-Input>
  99. <i-Button class="mar-l-10" type="primary" @click="checkedUserCard">开始下单</i-Button>
  100. </div>
  101. </i-Col>
  102. </Row>
  103. <Row class="searchBox padd-15 shopBOx" v-if="UserCard">
  104. <i-Col span="24">
  105. <div>
  106. <h4 class="mar-b-10">当前商品信息</h4>
  107. <Row class="searchBox padd-15 mar-b-10 ">
  108. <i-Col span="8">
  109. <h4>商品信息</h4>
  110. </i-Col>
  111. <i-Col span="4">
  112. <h4 class="text-cente"> 商品单价</h4>
  113. </i-Col>
  114. <i-Col span="4">
  115. <h4 class="text-cente"> 商品总价</h4>
  116. </i-Col>
  117. <i-Col span="4">
  118. <h4 class="text-cente"> 商品类型</h4>
  119. </i-Col>
  120. <i-Col span="4">
  121. <h4 class="text-cente">
  122. 操作 </h4>
  123. </i-Col>
  124. </Row>
  125. <Row type="flex" align="middle" class="searchBox padd-15 mar-b-10"
  126. v-for="(ls,ind) in shopList" :key="ls.id">
  127. <i-Col span="8">
  128. <div class="flex itemStart">
  129. <img :src="ls.image" class="shopImg">
  130. <div class="titleBox mar-l-10">
  131. <div class="clamp2" :title="ls.name">{{ls.name}}</div>
  132. <div>
  133. 规格:{{ls.typeName}}
  134. </div>
  135. <div>
  136. 数量:{{ls.num}}
  137. </div>
  138. </div>
  139. </div>
  140. </i-Col>
  141. <i-Col span="4" class="text-cente">
  142. {{ls.price}}
  143. </i-Col>
  144. <i-Col span="4" class="text-cente">
  145. {{ls.price*ls.num}}
  146. </i-Col>
  147. <i-Col span="4" class="text-cente">
  148. {{+ls.is_consumer==0?'普通商品':'消费券商品'}}
  149. </i-Col>
  150. <i-Col span="4">
  151. <div class="flex flexcontent">
  152. <i-Button type="error" size="small" @click="delShop(ls,ind)">删除</i-Button>
  153. <i-Button class="mar-l-10" type="success" size="small"
  154. @click="changeNumShop(ls,1)">增加
  155. </i-Button>
  156. <i-Button class="mar-l-10" type="warning" size="small"
  157. @click="changeNumShop(ls,-1)">减少
  158. </i-Button>
  159. </div>
  160. </i-Col>
  161. </Row>
  162. </div>
  163. </i-Col>
  164. </Row>
  165. <Row class="searchBox padd-15 mar-b-10 alertBottom" v-if="UserCard">
  166. {eq name="type" value="0"}
  167. <i-Col span="6">
  168. <div class="flex">
  169. <span class="no-shink">选择商家:</span>
  170. <i-Select name="store_id" v-model="form.store_id" style="width: 80%" filterable>
  171. {volist name="store" id="v" }
  172. <i-Option value="{$v.id}">{$v.name}(id:{$v.id})</i-Option>
  173. {/volist}
  174. </i-Select>
  175. </div>
  176. </i-Col>
  177. {/eq}
  178. <i-Col span="6">
  179. <div class="flex">
  180. <span class="no-shink mar-l-10">支付方式:</span>
  181. <i-Select name="store_id" v-model="form.pay_type" default-label="微信" style="width: 80%"
  182. filterable>
  183. <!-- <i-Option value="alipay">支付宝</i-Option>-->
  184. <!-- <i-Option value="weixin">微信</i-Option>-->
  185. <i-Option value="jialie">嘉联支付</i-Option>-->
  186. <i-Option value="yue">余额</i-Option>
  187. <i-Option value="integral">消费券</i-Option>
  188. <!-- <i-Option value="consumer">消费券</i-Option>-->
  189. <i-Option value="offline">线下支付</i-Option>
  190. </i-Select>
  191. </div>
  192. </i-Col>
  193. <i-Col span="6">
  194. <div class="flex">
  195. <span class="no-shink mar-l-10">当前金额:¥{{allPayMoney}}</span>
  196. <i-Button class="mar-l-10" type="success" @click="submit">确认下单</i-Button>
  197. </div>
  198. </i-Col>
  199. </Row>
  200. </div>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. <script>
  206. mpFrame.start(function (Vue) {
  207. new Vue({
  208. data: function () {
  209. return {
  210. form: {
  211. store_id: '{eq name="type" value="1"}{$store.0.id}{/eq}',//商家id
  212. pay_type: 'weixin'//支付类型
  213. },
  214. shopList: [],//当前选中的商品
  215. userCardInput: '',//用户输入内容
  216. UserCard: '',//当前选中的会员卡号
  217. userId: '',//当前选中的用户id
  218. userData: {},//保存用户信息
  219. shopId: '',//当前商品条形码
  220. is_consumer: 0,//当前是否消费券
  221. }
  222. },
  223. mounted() {
  224. const that = this;
  225. //获取会员卡号焦点
  226. that.$nextTick(function () {
  227. that.$refs.usercard.focus();
  228. })
  229. },
  230. computed: {
  231. allPayMoney() {
  232. let money = 0;
  233. for (let i = 0; i < this.shopList.length; i++) {
  234. const item = this.shopList[i]
  235. money += item.price * item.num
  236. }
  237. return money;
  238. }
  239. },
  240. methods: {
  241. //选中用户卡号
  242. checkedUserCard(e) {
  243. const that = this;
  244. if (that.userCardInput.length == 12 || that.userCardInput.length == 15 || that.userCardInput.length == 8 || that.userCardInput.length == 11 || that.userCardInput== '1' ) {
  245. //初始化用户数据
  246. that.userId = '';
  247. that.userData = {}
  248. //请求获取用户信息
  249. $eb.axios.post('{:Url("getCardNo")}' + '?card_no=' + that.userCardInput).then(function (res) {
  250. console.log(res)
  251. const data = res.data;
  252. if (data.status == 200) {
  253. that.UserCard = that.userCardInput;
  254. that.userId = data.data.uid;
  255. that.userData = data.data.user
  256. console.log('获取焦点')
  257. that.$nextTick(function () {
  258. that.$refs.code.focus();
  259. })
  260. } else {
  261. layer.msg(data.msg, {icon: 5});
  262. }
  263. }).catch(function (err) {
  264. console.log(err);
  265. })
  266. //设置获取焦点
  267. } else {
  268. layer.msg('请输入8位,12位,17位卡号会员卡号,或输入1', {icon: 5});
  269. }
  270. },
  271. //删除购物车商品
  272. delShop(ls, ind) {
  273. const that = this;
  274. //询问框
  275. layer.confirm('是否删除当前商品?', {
  276. btn: ['是', '否'] //按钮
  277. }, function (index) {
  278. layer.close(index);
  279. //删除数组数据
  280. that.shopList.splice(ind, 1);
  281. //重新获取焦点
  282. that.$refs.code.focus();
  283. //删除购物车数据
  284. that.delCartShop([ls.cartId])
  285. layer.msg('删除成功!', {icon: 1});
  286. }, function (index) {
  287. layer.close(index);
  288. });
  289. },
  290. //删除购物车数据
  291. delCartShop(ids) {
  292. const that = this;
  293. $eb.axios.post('{:Url("del")}', {
  294. ids: ids,
  295. uid: that.userId
  296. }).then(function (res) {
  297. console.log(res, '购物车删除成功')
  298. }).catch(function (err) {
  299. console.log(err);
  300. })
  301. },
  302. //增加减少数量
  303. changeNumShop(item, type) {
  304. const that = this;
  305. layer.prompt({
  306. title: '请输入需要' + (type > 0 ? '添加' : '减少') + '的数量',
  307. formType: 0
  308. }, function (pass, index) {
  309. layer.close(index);
  310. const nt = /^[0-9]*$/g;//匹配数字
  311. if (!nt.test(pass)) {
  312. console.log(nt.test(pass), '判断是否正确');
  313. layer.msg('请输入数字')
  314. return false
  315. }
  316. if (item.num + pass * type > 0) {
  317. item.num += pass * type;
  318. //修改商品数量
  319. that.changeCartShop(item.cartId, item.num)
  320. layer.msg('成功' + (type > 0 ? '添加' : '减少') + pass + '件商品')
  321. } else {
  322. layer.msg('商品数量不可小于0')
  323. }
  324. });
  325. },
  326. //查询商品是否有库存
  327. getShopNum() {
  328. const that = this;
  329. let num =0 ;
  330. let orderId=0;
  331. if( that.shopId.length==13&&that.shopId.substr(0,2)=='20'){
  332. orderId = that.shopId.substr(2,5);
  333. num = (Math.floor(that.shopId.substr(7,6)/10)/1000).toFixed(3);
  334. }else{
  335. orderId = that.shopId;
  336. num=1
  337. }
  338. that.shopId = '';
  339. $eb.axios.post('{:Url("getBarCode")}' + (orderId ? '?bar_code=' + orderId : '')).then(function (res) {
  340. console.log(res);
  341. const data = res.data.data;
  342. console.log(data,'返回数据')
  343. if (that.is_consumer != data.is_consumer) {
  344. if (that.is_consumer == 1) {
  345. layer.msg('请选择消费券商品', {icon: 5})
  346. }
  347. if (that.is_consumer == 0) {
  348. layer.msg('请选择普通商品', {icon: 5})
  349. }
  350. } else {
  351. console.log(res, '开始调用购物车');
  352. //添加到购物车
  353. that.addCart(data,num)
  354. }
  355. that.$nextTick(function () {
  356. that.$refs.code.focus();
  357. })
  358. }).catch(function (err) {
  359. console.log(err);
  360. })
  361. },
  362. //添加购物车
  363. addCart(product,num=1) {
  364. const that = this
  365. console.log('开始添加购物车');
  366. let pushData = {
  367. productId: product.product_id,//普通产品编号
  368. uid: this.userId,
  369. uniqueId: product.unique,//属性唯一值
  370. cartNum: num, //购物车数量
  371. new: 0,// 1 加入购物车直接购买 0 加入购物车
  372. }
  373. $eb.axios.post('{:Url("add_cart")}', pushData).then(function (res) {
  374. console.log(res)
  375. const data = res.data;
  376. if (data.status == 200) {
  377. //保存购物车id
  378. const cartId = data.data.cartId
  379. //判断是否有这个商品
  380. const ind = that.shopList.findIndex(function (a) {
  381. if (a.cartId == cartId) {
  382. return true
  383. } else {
  384. return false
  385. }
  386. })
  387. console.log(ind, '当前下标')
  388. //判断这个商品是否已经存在数组
  389. if (ind > -1) {
  390. that.shopList[ind].num++;
  391. console.log(that.shopList, '添加数据后对象')
  392. } else {
  393. //初始化商品
  394. that.initShopData(product, cartId,num)
  395. console.log(that.shopList, '初始化后数据对象')
  396. }
  397. } else {
  398. layer.msg(data.msg, {icon: 5});
  399. }
  400. }).catch(function (err) {
  401. console.log(err);
  402. })
  403. },
  404. //初始化购物车商品
  405. initShopData(product, cartId,num) {
  406. const that = this;
  407. that.shopList = that.shopList.concat([{
  408. name: product.store_name,//商品
  409. num: num,//购物车中的数量
  410. id: product.product_id,//当前商品id
  411. cartId: cartId,//保存购物车id
  412. typeName: product.suk,//商品规格名称
  413. unique: product.unique,//商品规格id
  414. image: product.image,//商品主图
  415. price: product.price,//商品价格
  416. is_consumer:product.is_consumer//商品类型
  417. }])
  418. console.log(this, '初始化后this对象')
  419. //初始化该商品为1
  420. that.changeCartShop(cartId, num)
  421. },
  422. //修改购物车物品数量
  423. changeCartShop(cartId, num) {
  424. const that = this;
  425. return new Promise(function (ok, erro) {
  426. $eb.axios.post('{:Url("num")}', {
  427. id: cartId, number: num, uid: that.userId
  428. }).then(function (res) {
  429. ok(res)
  430. }).catch(function (err) {
  431. erro(err)
  432. console.log(err);
  433. })
  434. })
  435. },
  436. submit: async function () {
  437. let that = this;
  438. console.log(that.form.store_id, '当前门店id')
  439. //当前门店
  440. if (!that.form.store_id) {
  441. return layer.msg('请选择门店', {icon: 5});
  442. }
  443. if (!that.shopList.length > 0) {
  444. return layer.msg('请选择商品', {icon: 5});
  445. }
  446. //用于保存当前选中的商品cardid
  447. let pusharr = []
  448. for (let i = 0; i < that.shopList.length; i++) {
  449. pusharr.push(that.shopList[i].cartId);
  450. }
  451. //提交订单
  452. try {
  453. //提交数据
  454. let pushData = {
  455. cartId: pusharr.join(','),
  456. uid: that.userId
  457. }
  458. let res = await $eb.axios.post('{:Url("confirm")}', pushData);
  459. const orderKey = res.data.data.orderKey;
  460. let money = await that.computedOrder(orderKey);
  461. layer.confirm('订单总金额:¥' + that.allPayMoney.toFixed(2) + '<br/> vip优惠:¥' + ((that.allPayMoney - money.data.data.result.pay_price)>0?(that.allPayMoney - money.data.data.result.pay_price).toFixed(2):0) + '<br/> 实际支付:¥' + money.data.data.result.pay_price.toFixed(2), {
  462. btn: ['立即支付', '取消'] //按钮
  463. }, async function (index) {
  464. layer.close(index);
  465. try{
  466. //微信
  467. // if (that.form.pay_type == 'weixin') {
  468. // let qr = await that.weixinPay();
  469. // that.create(orderKey, qr)
  470. // }
  471. // 余额
  472. if (that.form.pay_type == 'yue') {
  473. that.create(orderKey)
  474. }
  475. //现金
  476. if (that.form.pay_type == 'offline') {
  477. that.create(orderKey)
  478. }
  479. // 积分
  480. if (that.form.pay_type == 'integral') {
  481. that.create(orderKey)
  482. }
  483. //支付宝
  484. // if (that.form.pay_type == 'alipay') {
  485. // that.create(orderKey)
  486. // }
  487. if (that.form.pay_type == 'jialie') {
  488. let qr = await that.jialiePay();
  489. that.create(orderKey, qr)
  490. }
  491. }catch (e) {
  492. console.log(e);
  493. }
  494. }, function (index) {
  495. layer.close(index);
  496. });
  497. console.log(money, '金额计算');
  498. } catch (e) {
  499. console.log(e)
  500. }
  501. },
  502. weixinPay() {
  503. return new Promise(function (ok, err) {
  504. layer.prompt({title: '请输入微信付款码编号', formType: 0}, function (pass, index) {
  505. layer.close(index);
  506. ok(pass)
  507. });
  508. })
  509. },
  510. //嘉联支付验证
  511. jialiePay() {
  512. return new Promise(function (ok, err) {
  513. layer.prompt({title: '请输入付款码编号', formType: 0}, function (pass, index) {
  514. layer.close(index);
  515. ok(pass)
  516. });
  517. })
  518. },
  519. //计算订单价格
  520. computedOrder(key) {
  521. const that = this;
  522. return new Promise(function (ok, erro) {
  523. $eb.axios.post('{:Url("computedOrder")}', {
  524. key,
  525. uid: that.userId
  526. }).then(function (res) {
  527. //保存订单key
  528. ok(res)
  529. }).catch(function (err) {
  530. erro(err)
  531. })
  532. })
  533. },
  534. //创建订单
  535. create(key, qr) {
  536. let that = this;
  537. let data = {
  538. key: key,
  539. uid: that.userId,
  540. shipping_type: 2,
  541. store_id: that.form.store_id,
  542. real_name: that.userData.nickname,
  543. phone: that.userData.phone,
  544. payType: that.form.pay_type//支付方式
  545. };
  546. //判断是否需要传入code码
  547. if(qr){
  548. data.auth_code = qr;
  549. }
  550. //提交订单
  551. $eb.axios.post('{:Url("create")}', data).then(function (res) {
  552. layer.confirm(res.data.msg + '<br/>' + '是否刷新?', {
  553. btn: ['刷新', '取消'] //按钮
  554. }, function (index) {
  555. //清除用户卡号信息
  556. that.UserCard = '';
  557. window.location.reload();
  558. //parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  559. layer.close(index);
  560. }, function (index) {
  561. layer.close(index);
  562. });
  563. console.log(res)
  564. }).catch(function (err) {
  565. })
  566. }
  567. },
  568. }).$mount(document.getElementById('store-attr'))
  569. })
  570. </script>