index.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. //修改商品数量
  320. that.changeCartShop(item.cartId, (item.num * 1) + pass * type).then(function (data) {
  321. console.log(data.data.status);
  322. if (data.data.status == 200) {
  323. item.num = ((item.num * 1) + pass * type).toFixed(3);
  324. layer.msg('成功' + (type > 0 ? '添加' : '减少') + pass + '件商品')
  325. } else {
  326. layer.msg(data.data.msg);
  327. }
  328. }).catch(function (data) {
  329. console.log(data.data.status);
  330. layer.msg(data.data.msg);
  331. })
  332. } else {
  333. layer.msg('商品数量不可小于0')
  334. }
  335. });
  336. },
  337. //查询商品是否有库存
  338. getShopNum() {
  339. const that = this;
  340. let num = 0;
  341. let orderId = 0;
  342. if (that.shopId.length == 13 && that.shopId.substr(0, 2) == '20') {
  343. orderId = that.shopId.substr(2, 5);
  344. num = (Math.floor(that.shopId.substr(7, 6) / 10) / 1000).toFixed(3);
  345. } else {
  346. orderId = that.shopId;
  347. num = 1
  348. }
  349. that.shopId = '';
  350. $eb.axios.post('{:Url("getBarCode")}' + (orderId ? '?bar_code=' + orderId : '')).then(function (res) {
  351. console.log(res);
  352. const data = res.data.data;
  353. console.log(data, '返回数据')
  354. if (that.is_consumer != data.is_consumer) {
  355. if (that.is_consumer == 1) {
  356. layer.msg('请选择消费券商品', {icon: 5})
  357. }
  358. if (that.is_consumer == 0) {
  359. layer.msg('请选择普通商品', {icon: 5})
  360. }
  361. } else {
  362. console.log(res, '开始调用购物车');
  363. //添加到购物车
  364. that.addCart(data, num)
  365. }
  366. that.$nextTick(function () {
  367. that.$refs.code.focus();
  368. })
  369. }).catch(function (err) {
  370. console.log(err);
  371. })
  372. },
  373. //添加购物车
  374. addCart(product, num = 1) {
  375. const that = this
  376. console.log('开始添加购物车');
  377. let pushData = {
  378. productId: product.product_id,//普通产品编号
  379. uid: this.userId,
  380. uniqueId: product.unique,//属性唯一值
  381. cartNum: num, //购物车数量
  382. new: 0,// 1 加入购物车直接购买 0 加入购物车
  383. }
  384. $eb.axios.post('{:Url("add_cart")}', pushData).then(function (res) {
  385. console.log(res)
  386. const data = res.data;
  387. if (data.status == 200) {
  388. //保存购物车id
  389. const cartId = data.data.cartId
  390. //判断是否有这个商品
  391. const ind = that.shopList.findIndex(function (a) {
  392. if (a.cartId == cartId) {
  393. return true
  394. } else {
  395. return false
  396. }
  397. })
  398. console.log(ind, '当前下标')
  399. //判断这个商品是否已经存在数组
  400. if (ind > -1) {
  401. that.shopList[ind].num = (+that.shopList[ind].num + (+num)).toFixed(3);
  402. console.log(that.shopList, '添加数据后对象')
  403. } else {
  404. //初始化商品
  405. that.initShopData(product, cartId, (+num).toFixed(3))
  406. console.log(that.shopList, '初始化后数据对象')
  407. }
  408. } else {
  409. layer.msg(data.msg, {icon: 5});
  410. }
  411. }).catch(function (err) {
  412. console.log(err);
  413. })
  414. },
  415. //初始化购物车商品
  416. initShopData(product, cartId, num) {
  417. const that = this;
  418. that.shopList = ([{
  419. name: product.store_name,//商品
  420. num: num,//购物车中的数量
  421. id: product.product_id,//当前商品id
  422. cartId: cartId,//保存购物车id
  423. typeName: product.suk,//商品规格名称
  424. unique: product.unique,//商品规格id
  425. image: product.image,//商品主图
  426. price: product.price,//商品价格
  427. is_consumer: product.is_consumer//商品类型
  428. }]).concat(that.shopList);
  429. console.log(this, '初始化后this对象')
  430. //初始化该商品为1
  431. that.changeCartShop(cartId, num)
  432. },
  433. //修改购物车物品数量
  434. changeCartShop(cartId, num) {
  435. const that = this;
  436. return new Promise(function (ok, erro) {
  437. $eb.axios.post('{:Url("num")}', {
  438. id: cartId, number: num, uid: that.userId
  439. }).then(function (res) {
  440. console.log(ok)
  441. ok(res)
  442. }).catch(function (err) {
  443. erro(err)
  444. console.log(err);
  445. })
  446. })
  447. },
  448. submit: async function () {
  449. let that = this;
  450. console.log(that.form.store_id, '当前门店id')
  451. //当前门店
  452. if (!that.form.store_id) {
  453. return layer.msg('请选择门店', {icon: 5});
  454. }
  455. if (!that.shopList.length > 0) {
  456. return layer.msg('请选择商品', {icon: 5});
  457. }
  458. //用于保存当前选中的商品cardid
  459. let pusharr = []
  460. for (let i = 0; i < that.shopList.length; i++) {
  461. pusharr.push(that.shopList[i].cartId);
  462. }
  463. //提交订单
  464. try {
  465. //提交数据
  466. let pushData = {
  467. cartId: pusharr.join(','),
  468. uid: that.userId
  469. }
  470. let res = await $eb.axios.post('{:Url("confirm")}', pushData);
  471. const orderKey = res.data.data.orderKey;
  472. let money = await that.computedOrder(orderKey);
  473. 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), {
  474. btn: ['立即支付', '取消'] //按钮
  475. }, async function (index) {
  476. layer.close(index);
  477. try {
  478. //微信
  479. // if (that.form.pay_type == 'weixin') {
  480. // let qr = await that.weixinPay();
  481. // that.create(orderKey, qr)
  482. // }
  483. // 余额
  484. if (that.form.pay_type == 'yue') {
  485. that.create(orderKey)
  486. }
  487. //现金
  488. if (that.form.pay_type == 'offline') {
  489. that.create(orderKey)
  490. }
  491. // 积分
  492. if (that.form.pay_type == 'integral') {
  493. that.create(orderKey)
  494. }
  495. //支付宝
  496. // if (that.form.pay_type == 'alipay') {
  497. // that.create(orderKey)
  498. // }
  499. if (that.form.pay_type == 'jialie') {
  500. let qr = await that.jialiePay();
  501. that.create(orderKey, qr)
  502. }
  503. } catch (e) {
  504. console.log(e);
  505. }
  506. }, function (index) {
  507. layer.close(index);
  508. });
  509. console.log(money, '金额计算');
  510. } catch (e) {
  511. console.log(e)
  512. }
  513. },
  514. weixinPay() {
  515. return new Promise(function (ok, err) {
  516. layer.prompt({title: '请输入微信付款码编号', formType: 0}, function (pass, index) {
  517. layer.close(index);
  518. ok(pass)
  519. });
  520. })
  521. },
  522. //嘉联支付验证
  523. jialiePay() {
  524. return new Promise(function (ok, err) {
  525. layer.prompt({title: '请输入付款码编号', formType: 0}, function (pass, index) {
  526. layer.close(index);
  527. ok(pass)
  528. });
  529. })
  530. },
  531. //计算订单价格
  532. computedOrder(key) {
  533. const that = this;
  534. return new Promise(function (ok, erro) {
  535. $eb.axios.post('{:Url("computedOrder")}', {
  536. key,
  537. uid: that.userId
  538. }).then(function (res) {
  539. //保存订单key
  540. ok(res)
  541. }).catch(function (err) {
  542. erro(err)
  543. })
  544. })
  545. },
  546. //创建订单
  547. create(key, qr) {
  548. let that = this;
  549. let data = {
  550. key: key,
  551. uid: that.userId,
  552. shipping_type: 2,
  553. store_id: that.form.store_id,
  554. real_name: that.userData.nickname,
  555. phone: that.userData.phone,
  556. payType: that.form.pay_type//支付方式
  557. };
  558. //判断是否需要传入code码
  559. if (qr) {
  560. data.auth_code = qr;
  561. }
  562. //提交订单
  563. $eb.axios.post('{:Url("create")}', data).then(function (res) {
  564. layer.confirm(res.data.msg + '<br/>' + '是否刷新?', {
  565. btn: ['刷新', '取消'] //按钮
  566. }, function (index) {
  567. //清除用户卡号信息
  568. that.UserCard = '';
  569. window.location.reload();
  570. //parent.$(".J_iframe:visible")[0].contentWindow.location.reload();
  571. layer.close(index);
  572. }, function (index) {
  573. layer.close(index);
  574. });
  575. console.log(res)
  576. }).catch(function (err) {
  577. })
  578. }
  579. },
  580. }).$mount(document.getElementById('store-attr'))
  581. })
  582. </script>