index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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. .demo-spin-icon-load {
  57. animation: ani-demo-spin 1s linear infinite;
  58. }
  59. @keyframes ani-demo-spin {
  60. from {
  61. transform: rotate(0deg);
  62. }
  63. 50% {
  64. transform: rotate(180deg);
  65. }
  66. to {
  67. transform: rotate(360deg);
  68. }
  69. }
  70. .demo-spin-col {
  71. height: 100px;
  72. position: relative;
  73. border: 1px solid #eee;
  74. }
  75. </style>
  76. </head>
  77. <body>
  78. <div class="wrapper wrapper-content">
  79. <div class="row">
  80. <div class="col-sm-12">
  81. <div class="ibox float-e-margins ">
  82. <div class="ibox-title">
  83. <h5>在线下单</h5>
  84. </div>
  85. <div id="store-attr" class="mp-form" v-cloak="">
  86. <Row class="searchBox padd-15 mar-b-10 mar-l-10" v-if="UserCard">
  87. <i-Col span="6">
  88. <div class="flex">
  89. <span class="no-shink">当前会员卡号:{{UserCard}} &nbsp; 会员余额:{{userData.now_money}}
  90. &nbsp; 消费券:{{userData.integral}} &nbsp; 手机号:{{userData.phone}}</span>
  91. </div>
  92. </i-Col>
  93. </Row>
  94. <Row class="searchBox padd-15" v-if="UserCard">
  95. <i-Col span="6">
  96. <div class="flex">
  97. <span class="no-shink mar-l-10">是否消费券:</span>
  98. <radio-group v-model="is_consumer" type="button">
  99. <Radio :label="1">是</Radio>
  100. <Radio :label="0">否</Radio>
  101. </radio-group>
  102. </div>
  103. </i-Col>
  104. <i-Col span="12">
  105. <div class="flex">
  106. <span class="no-shink mar-l-10">条形码:</span>
  107. <i-Input ref="code" placeholder="请扫描或输入条形码" @on-enter="getShopNum"
  108. v-model="shopId" type="text"></i-Input>
  109. <i-Button class="mar-l-10" type="primary" @click="getShopNum">添加商品</i-Button>
  110. </div>
  111. </i-Col>
  112. </Row>
  113. <Row class="searchBox padd-15" v-else>
  114. <i-Col span="8">
  115. <div class="flex">
  116. <span class="no-shink">会员卡号:</span>
  117. <i-Input ref="usercard" placeholder="请输入会员卡号" v-model="userCardInput"
  118. type="text" @on-enter="checkedUserCard"></i-Input>
  119. <i-Button class="mar-l-10" type="primary" @click="checkedUserCard">开始下单
  120. </i-Button>
  121. </div>
  122. </i-Col>
  123. </Row>
  124. <Row class="searchBox padd-15 shopBOx" v-if="UserCard">
  125. <i-Col span="24">
  126. <div>
  127. <h4 class="mar-b-10">当前商品信息</h4>
  128. <Row class="searchBox padd-15 mar-b-10 ">
  129. <i-Col span="8">
  130. <h4>商品信息</h4>
  131. </i-Col>
  132. <i-Col span="4">
  133. <h4 class="text-cente"> 商品单价</h4>
  134. </i-Col>
  135. <i-Col span="4">
  136. <h4 class="text-cente"> 商品总价</h4>
  137. </i-Col>
  138. <i-Col span="4">
  139. <h4 class="text-cente"> 商品类型</h4>
  140. </i-Col>
  141. <i-Col span="4">
  142. <h4 class="text-cente">
  143. 操作 </h4>
  144. </i-Col>
  145. </Row>
  146. <Row type="flex" align="middle" class="searchBox padd-15 mar-b-10"
  147. v-for="(ls,ind) in shopList" :key="ls.id">
  148. <i-Col span="8">
  149. <div class="flex itemStart">
  150. <img :src="ls.image" class="shopImg">
  151. <div class="titleBox mar-l-10">
  152. <div class="clamp2" :title="ls.name">{{ls.name}}</div>
  153. <div>
  154. 规格:{{ls.typeName}}
  155. </div>
  156. <div>
  157. 数量:{{+ls.num}}
  158. </div>
  159. </div>
  160. </div>
  161. </i-Col>
  162. <i-Col span="4" class="text-cente">
  163. {{ls.price}}
  164. </i-Col>
  165. <i-Col span="4" class="text-cente">
  166. {{(ls.price*ls.num).toFixed(2)}}
  167. </i-Col>
  168. <i-Col span="4" class="text-cente">
  169. {{+ls.is_consumer==0?'普通商品':'消费券商品'}}
  170. </i-Col>
  171. <i-Col span="4">
  172. <div class="flex flexcontent">
  173. <i-Button type="error" size="small" @click="delShop(ls,ind)">删除
  174. </i-Button>
  175. <i-Button class="mar-l-10" type="success" size="small"
  176. @click="changeNumShop(ls,1)">增加
  177. </i-Button>
  178. <i-Button class="mar-l-10" type="warning" size="small"
  179. @click="changeNumShop(ls,-1)">减少
  180. </i-Button>
  181. </div>
  182. </i-Col>
  183. </Row>
  184. </div>
  185. </i-Col>
  186. </Row>
  187. <Row class="searchBox padd-15 mar-b-10 alertBottom" v-if="UserCard">
  188. {eq name="type" value="0"}
  189. <i-Col span="6">
  190. <div class="flex">
  191. <span class="no-shink">选择商家:</span>
  192. <i-Select name="store_id" v-model="form.store_id" style="width: 80%" filterable>
  193. {volist name="store" id="v" }
  194. <i-Option value="{$v.id}">{$v.name}(id:{$v.id})</i-Option>
  195. {/volist}
  196. </i-Select>
  197. </div>
  198. </i-Col>
  199. {/eq}
  200. <i-Col span="6">
  201. <div class="flex">
  202. <span class="no-shink mar-l-10">支付方式:</span>
  203. <i-Select name="store_id" v-model="form.pay_type" default-label="微信"
  204. style="width: 80%" filterable>
  205. <!-- <i-Option value="alipay">支付宝</i-Option>-->
  206. <!-- <i-Option value="weixin">微信</i-Option>-->
  207. <i-Option value="jialie">嘉联支付</i-Option>
  208. -->
  209. <i-Option value="yue">余额</i-Option>
  210. <i-Option value="integral">消费券</i-Option>
  211. <!-- <i-Option value="consumer">消费券</i-Option>-->
  212. <i-Option value="offline">线下支付</i-Option>
  213. </i-Select>
  214. </div>
  215. </i-Col>
  216. <i-Col span="6">
  217. <div class="flex">
  218. <span class="no-shink mar-l-10">当前金额:¥{{allPayMoney}}</span>
  219. <i-Button class="mar-l-10" type="success" @click="submit">确认下单</i-Button>
  220. </div>
  221. </i-Col>
  222. </Row>
  223. </div>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. <script>
  229. mpFrame.start(function(Vue) {
  230. new Vue({
  231. data: function() {
  232. return {
  233. form: {
  234. store_id: '{eq name="type" value="1"}{$store.0.id}{/eq}', //商家id
  235. pay_type: 'weixin' //支付类型
  236. },
  237. shopList: [], //当前选中的商品
  238. userCardInput: '', //用户输入内容
  239. UserCard: '', //当前选中的会员卡号
  240. userId: '', //当前选中的用户id
  241. userData: {}, //保存用户信息
  242. shopId: '', //当前商品条形码
  243. is_consumer: 0, //当前是否消费券
  244. lodingAddCart: false, //判断是否正在加入购物车
  245. }
  246. },
  247. mounted() {
  248. const that = this;
  249. //获取会员卡号焦点
  250. that.$nextTick(function() {
  251. that.$refs.usercard.focus();
  252. })
  253. },
  254. computed: {
  255. allPayMoney() {
  256. let money = 0;
  257. for (let i = 0; i < this.shopList.length; i++) {
  258. const item = this.shopList[i]
  259. money += item.price * item.num
  260. }
  261. return +(money.toFixed(2));
  262. }
  263. },
  264. methods: {
  265. //选中用户卡号
  266. checkedUserCard(e) {
  267. const that = this;
  268. if (that.userCardInput.length == 12 || that.userCardInput.length == 15 || that
  269. .userCardInput.length == 8 || that.userCardInput.length == 11 || that
  270. .userCardInput == '1') {
  271. //初始化用户数据
  272. that.userId = '';
  273. that.userData = {}
  274. //请求获取用户信息
  275. $eb.axios.post('{:Url("getCardNo")}' + '?card_no=' + that.userCardInput).then(
  276. function(res) {
  277. console.log(res)
  278. const data = res.data;
  279. if (data.status == 200) {
  280. that.UserCard = that.userCardInput;
  281. that.userId = data.data.uid;
  282. that.userData = data.data.user
  283. console.log('获取焦点')
  284. that.$nextTick(function() {
  285. that.$refs.code.focus();
  286. // 清空购物车
  287. that.delCartAll()
  288. })
  289. } else {
  290. layer.msg(data.msg, {
  291. icon: 5
  292. });
  293. }
  294. }).catch(function(err) {
  295. console.log(err);
  296. })
  297. //设置获取焦点
  298. } else {
  299. layer.msg('请输入8位,12位,17位卡号会员卡号,或输入1', {
  300. icon: 5
  301. });
  302. }
  303. },
  304. //删除购物车商品
  305. delShop(ls, ind) {
  306. const that = this;
  307. //询问框
  308. layer.confirm('是否删除当前商品?', {
  309. btn: ['是', '否'] //按钮
  310. }, function(index) {
  311. layer.close(index);
  312. //删除数组数据
  313. that.shopList.splice(ind, 1);
  314. //重新获取焦点
  315. that.$refs.code.focus();
  316. //删除购物车数据
  317. that.delCartShop([ls.cartId])
  318. layer.msg('删除成功!', {
  319. icon: 1
  320. });
  321. }, function(index) {
  322. layer.close(index);
  323. });
  324. },
  325. // 清空购物车
  326. delCartAll() {
  327. const that = this;
  328. console.log('gouwuche ', that.userId);
  329. $eb.axios.post('{:Url("clear_cart")}', {
  330. uid: that.userId
  331. }).then(function(res) {
  332. console.log(res, '购物车删除成功')
  333. }).catch(function(err) {
  334. console.log(err);
  335. })
  336. },
  337. //删除购物车数据
  338. delCartShop(ids) {
  339. const that = this;
  340. $eb.axios.post('{:Url("del")}', {
  341. ids: ids,
  342. uid: that.userId
  343. }).then(function(res) {
  344. console.log(res, '购物车删除成功')
  345. }).catch(function(err) {
  346. console.log(err);
  347. })
  348. },
  349. //增加减少数量
  350. changeNumShop(item, type) {
  351. const that = this;
  352. layer.prompt({
  353. title: '请输入需要' + (type > 0 ? '添加' : '减少') + '的数量',
  354. formType: 0
  355. }, function(pass, index) {
  356. layer.close(index);
  357. const nt = /^[0-9]*$/g; //匹配数字
  358. if (!nt.test(pass)) {
  359. console.log(nt.test(pass), '判断是否正确');
  360. layer.msg('请输入数字')
  361. return false
  362. }
  363. console.log(pass);
  364. if ((item.num * 1) + (pass * type) > 0) {
  365. //修改商品数量
  366. that.changeCartShop(item.cartId, (item.num * 1) + pass * type).then(
  367. function(data) {
  368. console.log(data.data.status);
  369. if (data.data.status == 200) {
  370. item.num = ((item.num * 1) + pass * type).toFixed(3);
  371. layer.msg('成功' + (type > 0 ? '添加' : '减少') + pass +
  372. '件商品')
  373. } else {
  374. layer.msg(data.data.msg);
  375. }
  376. }).catch(function(data) {
  377. console.log(data.data.status);
  378. layer.msg(data.data.msg);
  379. })
  380. } else {
  381. layer.msg('商品数量不可小于0')
  382. }
  383. });
  384. },
  385. openLoding() {
  386. const loading = this.$loading({
  387. lock: true,
  388. text: 'Loading',
  389. spinner: 'el-icon-loading',
  390. background: 'rgba(0, 0, 0, 0.7)'
  391. });
  392. setTimeout(() => {
  393. loading.close();
  394. }, 2000);
  395. },
  396. //处理扫码加入商品时间
  397. async getShopNum() {
  398. const that = this;
  399. if (that.lodingAddCart) {
  400. iView.Message.warning('扫码速度过快,加入失败')
  401. return
  402. }
  403. that.lodingAddCart = true;
  404. await that.isShopNum().catch(()=>{
  405. that.lodingAddCart = false;
  406. })
  407. that.lodingAddCart = false;
  408. // 处理设置允许获得焦点
  409. that.$nextTick(function() {
  410. that.$refs.code.focus();
  411. })
  412. },
  413. //查询商品是否有库存
  414. isShopNum() {
  415. const that = this;
  416. let num = 0;
  417. let orderId = 0;
  418. if (that.shopId.length == 13 && that.shopId.substr(0, 2) == '20') {
  419. orderId = that.shopId.substr(2, 5);
  420. num = (Math.floor(that.shopId.substr(7, 6) / 10) / 1000).toFixed(3);
  421. } else {
  422. orderId = that.shopId;
  423. num = 1
  424. }
  425. that.shopId = '';
  426. return new Promise((resolve, reject) => {
  427. $eb.axios.post('{:Url("getBarCode")}' + (orderId ? '?bar_code=' +
  428. orderId : ''))
  429. .then(function(res) {
  430. console.log(res);
  431. const data = res.data.data;
  432. console.log(data, '返回数据')
  433. if (that.is_consumer != data.is_consumer) {
  434. if (that.is_consumer == 1) {
  435. layer.msg('请选择消费券商品', {
  436. icon: 5
  437. })
  438. }
  439. if (that.is_consumer == 0) {
  440. layer.msg('请选择普通商品', {
  441. icon: 5
  442. })
  443. }
  444. resolve()
  445. } else {
  446. //添加到购物车
  447. that.addCart(data, num).then(() => {
  448. console.log('购物车加入成功');
  449. resolve()
  450. }).catch((err) => {
  451. console.log('购物车加入失败');
  452. reject()
  453. })
  454. }
  455. }).catch(function(err) {
  456. reject(err)
  457. console.log(err);
  458. })
  459. })
  460. },
  461. //添加购物车
  462. addCart(product, num = 1) {
  463. const that = this
  464. console.log('开始添加购物车');
  465. let pushData = {
  466. productId: product.product_id, //普通产品编号
  467. uid: this.userId,
  468. uniqueId: product.unique, //属性唯一值
  469. cartNum: num, //购物车数量
  470. new: 0, // 1 加入购物车直接购买 0 加入购物车
  471. }
  472. return new Promise((resolve, reject) => {
  473. $eb.axios.post('{:Url("add_cart")}', pushData).then(function(res) {
  474. console.log(res)
  475. const data = res.data;
  476. if (data.status == 200) {
  477. //保存购物车id
  478. const cartId = data.data.cartId
  479. //判断是否有这个商品
  480. const ind = that.shopList.findIndex(function(a) {
  481. if (a.cartId == cartId) {
  482. return true
  483. } else {
  484. return false
  485. }
  486. })
  487. //判断这个商品是否已经存在数组
  488. if (ind > -1) {
  489. that.shopList[ind].num = (+that.shopList[ind].num + (
  490. +num)).toFixed(3);
  491. } else {
  492. //初始化商品
  493. that.initShopData(product, cartId, (+num).toFixed(3))
  494. }
  495. resolve(true)
  496. } else {
  497. layer.msg(data.msg, {
  498. icon: 5
  499. });
  500. reject(data)
  501. }
  502. }).catch(function(err) {
  503. reject(err)
  504. console.log(err);
  505. })
  506. })
  507. },
  508. //初始化购物车商品
  509. initShopData(product, cartId, num) {
  510. const that = this;
  511. that.shopList = ([{
  512. name: product.store_name, //商品
  513. num: num, //购物车中的数量
  514. id: product.product_id, //当前商品id
  515. cartId: cartId, //保存购物车id
  516. typeName: product.suk, //商品规格名称
  517. unique: product.unique, //商品规格id
  518. image: product.image, //商品主图
  519. price: product.price, //商品价格
  520. is_consumer: product.is_consumer //商品类型
  521. }]).concat(that.shopList);
  522. console.log(this, '初始化后this对象')
  523. //初始化该商品为1
  524. that.changeCartShop(cartId, num)
  525. },
  526. //修改购物车物品数量
  527. changeCartShop(cartId, num) {
  528. const that = this;
  529. return new Promise(function(ok, erro) {
  530. $eb.axios.post('{:Url("num")}', {
  531. id: cartId,
  532. number: num,
  533. uid: that.userId
  534. }).then(function(res) {
  535. console.log(ok)
  536. ok(res)
  537. }).catch(function(err) {
  538. erro(err)
  539. console.log(err);
  540. })
  541. })
  542. },
  543. submit: async function() {
  544. let that = this;
  545. console.log(that.form.store_id, '当前门店id')
  546. //当前门店
  547. if (!that.form.store_id) {
  548. return layer.msg('请选择门店', {
  549. icon: 5
  550. });
  551. }
  552. if (!that.shopList.length > 0) {
  553. return layer.msg('请选择商品', {
  554. icon: 5
  555. });
  556. }
  557. //用于保存当前选中的商品cardid
  558. let pusharr = []
  559. for (let i = 0; i < that.shopList.length; i++) {
  560. pusharr.push(that.shopList[i].cartId);
  561. }
  562. //提交订单
  563. try {
  564. //提交数据
  565. let pushData = {
  566. cartId: pusharr.join(','),
  567. uid: that.userId
  568. }
  569. let res = await $eb.axios.post('{:Url("confirm")}', pushData);
  570. const orderKey = res.data.data.orderKey;
  571. let money = await that.computedOrder(orderKey);
  572. layer.confirm('订单总金额:¥' + that.allPayMoney.toFixed(2) + '<br/> vip优惠:¥' + ((
  573. that.allPayMoney - money.data.data.result.pay_price) > 0 ? (
  574. that.allPayMoney - money.data.data.result.pay_price).toFixed(
  575. 2) : 0) + '<br/> 实际支付:¥' + money.data.data.result.pay_price
  576. .toFixed(2), {
  577. btn: ['立即支付', '取消'] //按钮
  578. }, async function(index) {
  579. layer.close(index);
  580. try {
  581. //微信
  582. // if (that.form.pay_type == 'weixin') {
  583. // let qr = await that.weixinPay();
  584. // that.create(orderKey, qr)
  585. // }
  586. // 余额
  587. if (that.form.pay_type == 'yue') {
  588. that.create(orderKey)
  589. }
  590. //现金
  591. if (that.form.pay_type == 'offline') {
  592. that.create(orderKey)
  593. }
  594. // 积分
  595. if (that.form.pay_type == 'integral') {
  596. that.create(orderKey)
  597. }
  598. //支付宝
  599. // if (that.form.pay_type == 'alipay') {
  600. // that.create(orderKey)
  601. // }
  602. if (that.form.pay_type == 'jialie') {
  603. let qr = await that.jialiePay();
  604. that.create(orderKey, qr)
  605. }
  606. } catch (e) {
  607. console.log(e);
  608. }
  609. },
  610. function(index) {
  611. layer.close(index);
  612. });
  613. console.log(money, '金额计算');
  614. } catch (e) {
  615. console.log(e)
  616. }
  617. },
  618. weixinPay() {
  619. return new Promise(function(ok, err) {
  620. layer.prompt({
  621. title: '请输入微信付款码编号',
  622. formType: 0
  623. }, function(pass, index) {
  624. layer.close(index);
  625. ok(pass)
  626. });
  627. })
  628. },
  629. //嘉联支付验证
  630. jialiePay() {
  631. return new Promise(function(ok, err) {
  632. layer.prompt({
  633. title: '请输入付款码编号',
  634. formType: 0
  635. }, function(pass, index) {
  636. layer.close(index);
  637. ok(pass)
  638. });
  639. })
  640. },
  641. //计算订单价格
  642. computedOrder(key) {
  643. const that = this;
  644. return new Promise(function(ok, erro) {
  645. $eb.axios.post('{:Url("computedOrder")}', {
  646. key,
  647. uid: that.userId
  648. }).then(function(res) {
  649. //保存订单key
  650. ok(res)
  651. }).catch(function(err) {
  652. erro(err)
  653. })
  654. })
  655. },
  656. //创建订单
  657. create(key, qr) {
  658. let that = this;
  659. let data = {
  660. key: key,
  661. uid: that.userId,
  662. shipping_type: 2,
  663. store_id: that.form.store_id,
  664. real_name: that.userData.nickname,
  665. phone: that.userData.phone,
  666. payType: that.form.pay_type //支付方式
  667. };
  668. //判断是否需要传入code码
  669. if (qr) {
  670. data.auth_code = qr;
  671. }
  672. //提交订单
  673. $eb.axios.post('{:Url("create")}', data).then(function(res) {
  674. layer.confirm(res.data.msg + '<br/>' + '是否刷新?', {
  675. btn: ['刷新', '取消'] //按钮
  676. }, function(index) {
  677. //清除用户卡号信息
  678. that.UserCard = '';
  679. window.location.reload();
  680. //parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  681. layer.close(index);
  682. }, function(index) {
  683. layer.close(index);
  684. });
  685. console.log(res)
  686. }).catch(function(err) {
  687. })
  688. }
  689. },
  690. }).$mount(document.getElementById('store-attr'))
  691. })
  692. </script>