index.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  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. -->
  187. <i-Option value="yue">余额</i-Option>
  188. <i-Option value="integral">消费券</i-Option>
  189. <!-- <i-Option value="consumer">消费券</i-Option>-->
  190. <i-Option value="offline">线下支付</i-Option>
  191. </i-Select>
  192. </div>
  193. </i-Col>
  194. <i-Col span="6">
  195. <div class="flex">
  196. <span class="no-shink mar-l-10">当前金额:¥{{allPayMoney}}</span>
  197. <i-Button class="mar-l-10" type="success" @click="submit">确认下单</i-Button>
  198. </div>
  199. </i-Col>
  200. </Row>
  201. </div>
  202. </div>
  203. </div>
  204. </div>
  205. </div>
  206. <script>
  207. mpFrame.start(function (Vue) {
  208. new Vue({
  209. data: function () {
  210. return {
  211. form: {
  212. store_id: '{eq name="type" value="1"}{$store.0.id}{/eq}',//商家id
  213. pay_type: 'weixin'//支付类型
  214. },
  215. shopList: [],//当前选中的商品
  216. userCardInput: '',//用户输入内容
  217. UserCard: '',//当前选中的会员卡号
  218. userId: '',//当前选中的用户id
  219. userData: {},//保存用户信息
  220. shopId: '',//当前商品条形码
  221. is_consumer: 0,//当前是否消费券
  222. }
  223. },
  224. mounted() {
  225. const that = this;
  226. //获取会员卡号焦点
  227. that.$nextTick(function () {
  228. that.$refs.usercard.focus();
  229. })
  230. },
  231. computed: {
  232. allPayMoney() {
  233. let money = 0;
  234. for (let i = 0; i < this.shopList.length; i++) {
  235. const item = this.shopList[i]
  236. money += item.price * item.num
  237. }
  238. return money;
  239. }
  240. },
  241. methods: {
  242. //选中用户卡号
  243. checkedUserCard(e) {
  244. const that = this;
  245. if (that.userCardInput.length == 12 || that.userCardInput.length == 15 || that.userCardInput.length == 8 || that.userCardInput.length == 11 || that.userCardInput == '1') {
  246. //初始化用户数据
  247. that.userId = '';
  248. that.userData = {}
  249. //请求获取用户信息
  250. $eb.axios.post('{:Url("getCardNo")}' + '?card_no=' + that.userCardInput).then(function (res) {
  251. console.log(res)
  252. const data = res.data;
  253. if (data.status == 200) {
  254. that.UserCard = that.userCardInput;
  255. that.userId = data.data.uid;
  256. that.userData = data.data.user
  257. console.log('获取焦点')
  258. that.$nextTick(function () {
  259. that.$refs.code.focus();
  260. })
  261. } else {
  262. layer.msg(data.msg, {icon: 5});
  263. }
  264. }).catch(function (err) {
  265. console.log(err);
  266. })
  267. //设置获取焦点
  268. } else {
  269. layer.msg('请输入8位,12位,17位卡号会员卡号,或输入1', {icon: 5});
  270. }
  271. },
  272. //删除购物车商品
  273. delShop(ls, ind) {
  274. const that = this;
  275. //询问框
  276. layer.confirm('是否删除当前商品?', {
  277. btn: ['是', '否'] //按钮
  278. }, function (index) {
  279. layer.close(index);
  280. //删除数组数据
  281. that.shopList.splice(ind, 1);
  282. //重新获取焦点
  283. that.$refs.code.focus();
  284. //删除购物车数据
  285. that.delCartShop([ls.cartId])
  286. layer.msg('删除成功!', {icon: 1});
  287. }, function (index) {
  288. layer.close(index);
  289. });
  290. },
  291. //删除购物车数据
  292. delCartShop(ids) {
  293. const that = this;
  294. $eb.axios.post('{:Url("del")}', {
  295. ids: ids,
  296. uid: that.userId
  297. }).then(function (res) {
  298. console.log(res, '购物车删除成功')
  299. }).catch(function (err) {
  300. console.log(err);
  301. })
  302. },
  303. //增加减少数量
  304. changeNumShop(item, type) {
  305. const that = this;
  306. layer.prompt({
  307. title: '请输入需要' + (type > 0 ? '添加' : '减少') + '的数量',
  308. formType: 0
  309. }, function (pass, index) {
  310. layer.close(index);
  311. const nt = /^[0-9]*$/g;//匹配数字
  312. if (!nt.test(pass)) {
  313. console.log(nt.test(pass), '判断是否正确');
  314. layer.msg('请输入数字')
  315. return false
  316. }
  317. console.log(pass);
  318. if ((item.num * 1) + (pass * type) > 0) {
  319. console.log(typeof (item.num * 1))
  320. console.log(typeof (pass * type))
  321. //修改商品数量
  322. that.changeCartShop(item.cartId, (item.num * 1) + pass * type).then(function (data) {
  323. console.log(data.data.status);
  324. if (data.data.status == 200) {
  325. item.num += pass * type;
  326. layer.msg('成功' + (type > 0 ? '添加' : '减少') + pass + '件商品')
  327. } else {
  328. layer.msg(data.data.msg);
  329. }
  330. }).catch(function (data) {
  331. console.log(data.data.status);
  332. layer.msg(data.data.msg);
  333. })
  334. } else {
  335. layer.msg('商品数量不可小于0')
  336. }
  337. });
  338. },
  339. //查询商品是否有库存
  340. getShopNum() {
  341. const that = this;
  342. let num = 0;
  343. let orderId = 0;
  344. if (that.shopId.length == 13 && that.shopId.substr(0, 2) == '20') {
  345. orderId = that.shopId.substr(2, 5);
  346. num = (Math.floor(that.shopId.substr(7, 6) / 10) / 1000).toFixed(3);
  347. } else {
  348. orderId = that.shopId;
  349. num = 1
  350. }
  351. that.shopId = '';
  352. $eb.axios.post('{:Url("getBarCode")}' + (orderId ? '?bar_code=' + orderId : '')).then(function (res) {
  353. console.log(res);
  354. const data = res.data.data;
  355. console.log(data, '返回数据')
  356. if (that.is_consumer != data.is_consumer) {
  357. if (that.is_consumer == 1) {
  358. layer.msg('请选择消费券商品', {icon: 5})
  359. }
  360. if (that.is_consumer == 0) {
  361. layer.msg('请选择普通商品', {icon: 5})
  362. }
  363. } else {
  364. console.log(res, '开始调用购物车');
  365. //添加到购物车
  366. that.addCart(data, num)
  367. }
  368. that.$nextTick(function () {
  369. that.$refs.code.focus();
  370. })
  371. }).catch(function (err) {
  372. console.log(err);
  373. })
  374. },
  375. //添加购物车
  376. addCart(product, num = 1) {
  377. const that = this
  378. console.log('开始添加购物车');
  379. let pushData = {
  380. productId: product.product_id,//普通产品编号
  381. uid: this.userId,
  382. uniqueId: product.unique,//属性唯一值
  383. cartNum: num, //购物车数量
  384. new: 0,// 1 加入购物车直接购买 0 加入购物车
  385. }
  386. $eb.axios.post('{:Url("add_cart")}', pushData).then(function (res) {
  387. console.log(res)
  388. const data = res.data;
  389. if (data.status == 200) {
  390. //保存购物车id
  391. const cartId = data.data.cartId
  392. //判断是否有这个商品
  393. const ind = that.shopList.findIndex(function (a) {
  394. if (a.cartId == cartId) {
  395. return true
  396. } else {
  397. return false
  398. }
  399. })
  400. console.log(ind, '当前下标')
  401. //判断这个商品是否已经存在数组
  402. if (ind > -1) {
  403. that.shopList[ind].num = (+that.shopList[ind].num + (+num)).toFixed(3);
  404. console.log(that.shopList, '添加数据后对象')
  405. } else {
  406. //初始化商品
  407. that.initShopData(product, cartId, (+num).toFixed(3))
  408. console.log(that.shopList, '初始化后数据对象')
  409. }
  410. } else {
  411. layer.msg(data.msg, {icon: 5});
  412. }
  413. }).catch(function (err) {
  414. console.log(err);
  415. })
  416. },
  417. //初始化购物车商品
  418. initShopData(product, cartId, num) {
  419. const that = this;
  420. that.shopList = ([{
  421. name: product.store_name,//商品
  422. num: num,//购物车中的数量
  423. id: product.product_id,//当前商品id
  424. cartId: cartId,//保存购物车id
  425. typeName: product.suk,//商品规格名称
  426. unique: product.unique,//商品规格id
  427. image: product.image,//商品主图
  428. price: product.price,//商品价格
  429. is_consumer: product.is_consumer//商品类型
  430. }]).concat(that.shopList);
  431. console.log(this, '初始化后this对象')
  432. //初始化该商品为1
  433. that.changeCartShop(cartId, num)
  434. },
  435. //修改购物车物品数量
  436. changeCartShop(cartId, num) {
  437. const that = this;
  438. return new Promise(function (ok, erro) {
  439. $eb.axios.post('{:Url("num")}', {
  440. id: cartId, number: num, uid: that.userId
  441. }).then(function (res) {
  442. console.log(ok)
  443. ok(res)
  444. }).catch(function (err) {
  445. erro(err)
  446. console.log(err);
  447. })
  448. })
  449. },
  450. submit: async function () {
  451. let that = this;
  452. console.log(that.form.store_id, '当前门店id')
  453. //当前门店
  454. if (!that.form.store_id) {
  455. return layer.msg('请选择门店', {icon: 5});
  456. }
  457. if (!that.shopList.length > 0) {
  458. return layer.msg('请选择商品', {icon: 5});
  459. }
  460. //用于保存当前选中的商品cardid
  461. let pusharr = []
  462. for (let i = 0; i < that.shopList.length; i++) {
  463. pusharr.push(that.shopList[i].cartId);
  464. }
  465. //提交订单
  466. try {
  467. //提交数据
  468. let pushData = {
  469. cartId: pusharr.join(','),
  470. uid: that.userId
  471. }
  472. let res = await $eb.axios.post('{:Url("confirm")}', pushData);
  473. const orderKey = res.data.data.orderKey;
  474. let money = await that.computedOrder(orderKey);
  475. 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), {
  476. btn: ['立即支付', '取消'] //按钮
  477. }, async function (index) {
  478. layer.close(index);
  479. try {
  480. //微信
  481. // if (that.form.pay_type == 'weixin') {
  482. // let qr = await that.weixinPay();
  483. // that.create(orderKey, qr)
  484. // }
  485. // 余额
  486. if (that.form.pay_type == 'yue') {
  487. that.create(orderKey)
  488. }
  489. //现金
  490. if (that.form.pay_type == 'offline') {
  491. that.create(orderKey)
  492. }
  493. // 积分
  494. if (that.form.pay_type == 'integral') {
  495. that.create(orderKey)
  496. }
  497. //支付宝
  498. // if (that.form.pay_type == 'alipay') {
  499. // that.create(orderKey)
  500. // }
  501. if (that.form.pay_type == 'jialie') {
  502. let qr = await that.jialiePay();
  503. that.create(orderKey, qr)
  504. }
  505. } catch (e) {
  506. console.log(e);
  507. }
  508. }, function (index) {
  509. layer.close(index);
  510. });
  511. console.log(money, '金额计算');
  512. } catch (e) {
  513. console.log(e)
  514. }
  515. },
  516. weixinPay() {
  517. return new Promise(function (ok, err) {
  518. layer.prompt({title: '请输入微信付款码编号', formType: 0}, function (pass, index) {
  519. layer.close(index);
  520. ok(pass)
  521. });
  522. })
  523. },
  524. //嘉联支付验证
  525. jialiePay() {
  526. return new Promise(function (ok, err) {
  527. layer.prompt({title: '请输入付款码编号', formType: 0}, function (pass, index) {
  528. layer.close(index);
  529. ok(pass)
  530. });
  531. })
  532. },
  533. //计算订单价格
  534. computedOrder(key) {
  535. const that = this;
  536. return new Promise(function (ok, erro) {
  537. $eb.axios.post('{:Url("computedOrder")}', {
  538. key,
  539. uid: that.userId
  540. }).then(function (res) {
  541. //保存订单key
  542. ok(res)
  543. }).catch(function (err) {
  544. erro(err)
  545. })
  546. })
  547. },
  548. //创建订单
  549. create(key, qr) {
  550. let that = this;
  551. let data = {
  552. key: key,
  553. uid: that.userId,
  554. shipping_type: 2,
  555. store_id: that.form.store_id,
  556. real_name: that.userData.nickname,
  557. phone: that.userData.phone,
  558. payType: that.form.pay_type//支付方式
  559. };
  560. //判断是否需要传入code码
  561. if (qr) {
  562. data.auth_code = qr;
  563. }
  564. //提交订单
  565. $eb.axios.post('{:Url("create")}', data).then(function (res) {
  566. layer.confirm(res.data.msg + '<br/>' + '是否刷新?', {
  567. btn: ['刷新', '取消'] //按钮
  568. }, function (index) {
  569. //清除用户卡号信息
  570. that.UserCard = '';
  571. window.location.reload();
  572. //parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  573. layer.close(index);
  574. }, function (index) {
  575. layer.close(index);
  576. });
  577. console.log(res)
  578. }).catch(function (err) {
  579. })
  580. }
  581. },
  582. }).$mount(document.getElementById('store-attr'))
  583. })
  584. </script>