CommodityInfo.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <div>
  3. <div class="menu-com row">
  4. <div class="menu-title col-md-12">
  5. <a href=".">商城首页</a> >
  6. <a href="provider/home" v-if="storeInfo.type == 'AGENCY' || storeInfo.type == 'DISTRIBUTION'" title="代理经销">代理经销</a>
  7. <a href="provider/factories" v-if="storeInfo.type == 'ORIGINAL_FACTORY'" title="原厂专区">原厂专区</a>
  8. <a :href="'/store/' + storeInfo.uuid" v-if="storeInfo.type == 'CONSIGNMENT'" title="库存寄售">库存寄售</a>
  9. >
  10. <span v-if="storeInfo.type != 'CONSIGNMENT'"><a :href="'/store/' + storeInfo.uuid" :title="storeInfo.storeName" v-text="storeInfo.storeName">storeInfo.storeName</a>> </span>
  11. <span>产品详情</span>
  12. </div>
  13. </div>
  14. <div id="commodity-info-fragment">
  15. <div class="commodity-detail">
  16. <div class="img">
  17. <img :src="commodity.img || '/images/store/common/default.png'" style="width: 256px;height: 256px;"/>
  18. <div class="box"></div>
  19. </div>
  20. <div class="content">
  21. <div class="code">
  22. <span v-text="commodity.code"></span>
  23. </div>
  24. <div class="commodity-info-detail">
  25. <div class="com-info">
  26. <span class="name">价&nbsp;格</span>:
  27. <span class="money">
  28. <span v-if="fragment.currency == 'RMB'">¥</span>
  29. <span v-if="fragment.currency == 'USD'">$</span>
  30. <span v-text="fragment.price"></span>
  31. </span>
  32. </div>
  33. <div class="com-info">
  34. <span class="name">品&nbsp;牌</span>:<span v-text="commodity.brandNameEn"></span>
  35. </div>
  36. <div class="com-info">
  37. <span class="name">类&nbsp;目</span>:<span v-text="commodity.kindNameCn"></span>
  38. </div>
  39. <div class="com-info">
  40. <span class="name">下&nbsp;载</span>:<a target="_blank" :href="component.attach">{{component.attach ? '规格书' : '暂无信息'}}</a>
  41. </div>
  42. <div class="com-info">
  43. <span class="name">包&nbsp;装</span>:<span v-text="commodity.packaging || '无包装信息'"></span>
  44. </div>
  45. <div class="com-info">
  46. <span class="name">封&nbsp;装</span>:<span v-text="commodity.encapsulation || '无封装信息'"></span>
  47. </div>
  48. <div class="com-info">
  49. <span class="name">库&nbsp;存</span>:<span v-text="commodity.reserve || 0"></span>
  50. (<span v-text="commodity.minBuyQty || 1"></span>个起订)
  51. </div>
  52. <div class="com-info">
  53. <span class="name">货&nbsp;期</span>:
  54. <div class="delivery">
  55. <span v-text="commodity.b2cMinDelivery || 0"></span>
  56. <span v-if="commodity.b2cMaxDelivery && commodity.b2cMaxDelivery !== commodity.b2cMinDelivery">-</span>
  57. <span v-if="commodity.b2cMaxDelivery && commodity.b2cMaxDelivery !== commodity.b2cMinDelivery" v-text="commodity.b2cMaxDelivery || 0"></span>
  58. <span>(天)</span>
  59. </div>
  60. </div>
  61. <div class="com-info form-inline">
  62. <span class="name">数&nbsp;量</span>:
  63. <div class="input-group" style="width: 120px">
  64. <div :class="fragment.canSub ? ' input-group-addon operate':'input-group-addon'" @click="fragment.canSub ?subNum():''" :style="!fragment.canSub ?'cursor: not-allowed;':''">-</div>
  65. <input type="text" class="form-control" placeholder="数量" v-model="fragment.num" @change="inputNum()"style="padding: 0;min-width: 100px;text-align: center;"/>
  66. <div :class="fragment.canAdd ?'input-group-addon operate':'input-group-addon'" @click="fragment.canAdd ?addNum():''" :style="!fragment.canAdd ?'cursor: not-allowed;':''">+</div>
  67. <!-- <div class="input-group-addon operate" @click="subNum()">-</div>
  68. <input type="text" class="form-control" placeholder="数量" v-model="fragment.num" @change="inputNum()"style="padding: 0;min-width: 100px;text-align: center;"/>
  69. <div class="input-group-addon operate" @click="addNum()">+</div>-->
  70. </div>
  71. ×
  72. <!--<div class="select">
  73. <select class="form-control" :disabled="commodity.currencyName != 'RMB-USD'" v-model="fragment.currency" @change="changeCurrency()">
  74. <option value="RMB">RMB</option>
  75. <option value="USD">USD</option>
  76. </select>
  77. </div>-->
  78. <div class="select">
  79. <span v-if="fragment.currency == 'RMB'">¥</span>
  80. <span v-if="fragment.currency == 'USD'">$</span>
  81. <span>{{(fragment.price || 0)}}</span>
  82. <span v-if="fragment.currency == 'RMB'" class="tax"> ( 含税 ) </span>
  83. </div>
  84. <span class="money">
  85. <span v-if="fragment.currency == 'RMB'">¥</span>
  86. <span v-if="fragment.currency == 'USD'">$</span>
  87. <span>{{(calculate || 0)}}</span>
  88. </span>
  89. </div>
  90. <div class="button" ng-controller="GoodsPickUpCtrl">
  91. <button class="btn btn-default btn-primary" @click="buyNow(false, commodity)">加入购物车</button>
  92. <button class="btn btn-default btn-now" @click="buyNow(true, commodity)">立即购买</button>
  93. </div>
  94. </div>
  95. <div class="price-block">
  96. <div class="commodity-price">
  97. <div class="title">价格梯度</div>
  98. <div class="table">
  99. <div class="head">
  100. <div class="fragment">数量</div>
  101. <div class="price">单价¥(含税)</div>
  102. <div class="price">单价$</div>
  103. </div>
  104. <ul class="list-unstyled list-inline">
  105. <li v-for="price in commodity.prices">
  106. <div class="fragment">
  107. <span v-text="price.start"></span>+
  108. </div>
  109. <div class="price">
  110. <span v-if="price.rMBPrice" v-text="price.rMBPrice || 0"></span>
  111. </div>
  112. <div class="price">
  113. <span v-if="price.uSDPrice" v-text="price.uSDPrice || 0"></span>
  114. </div>
  115. </li>
  116. </ul>
  117. </div>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. </template>
  125. <script>
  126. function initFragment (commodity) {
  127. if (!commodity) {
  128. return {}
  129. }
  130. let fragment = {}
  131. let prices = commodity.prices[0]
  132. fragment.num = commodity.minBuyQty
  133. fragment.prices = prices
  134. if (commodity.currencyName !== 'USD') {
  135. fragment.currency = 'RMB'
  136. } else {
  137. fragment.currency = 'USD'
  138. }
  139. if (fragment.currency !== 'USD') {
  140. fragment.price = prices.rMBPrice
  141. } else {
  142. fragment.price = prices.uSDPrice
  143. }
  144. fragment.canAdd = true
  145. fragment.canSub = false
  146. return fragment
  147. }
  148. function getFragment (commodity, fragment) {
  149. // 判断是否小于第一分段的起订量
  150. if (commodity.prices[0].start > fragment.num) {
  151. fragment.num = commodity.prices[0].start
  152. }
  153. // 获取分段的信息
  154. let prices = commodity.prices
  155. for (let i = 0; i < prices.length; i++) {
  156. if (fragment.num <= prices[i].end) {
  157. fragment.prices = prices[i]
  158. break
  159. }
  160. }
  161. }
  162. export default {
  163. name: 'commodity-info',
  164. data () {
  165. return {
  166. fragment: {
  167. currency: 'RMB',
  168. num: 0,
  169. price: 0,
  170. canAdd: true,
  171. canSub: true}
  172. }
  173. },
  174. computed: {
  175. storeInfo () {
  176. return this.$store.state.shop.storeInfo.store.data
  177. },
  178. commodity () {
  179. let commodity = this.$store.state.shop.storeInfo.commodity.data
  180. this.fragment = initFragment(commodity)
  181. return commodity
  182. },
  183. component () {
  184. return this.$store.state.shop.storeInfo.component.data
  185. },
  186. calculate () {
  187. this.fragment.total = this.fragment.price * this.fragment.num
  188. return Math.ceil(this.fragment.total * Math.pow(10, 2)) / Math.pow(10, 2)
  189. },
  190. user () {
  191. return this.$store.state.option.user
  192. }
  193. },
  194. mounted () {
  195. this.$nextTick(() => {
  196. this.loadSaveHistory()
  197. })
  198. },
  199. methods: {
  200. loadSaveHistory () {
  201. if (this.user.logged) {
  202. this.$store.dispatch('shop/saveHistory', {id: this.commodity.batchCode})
  203. }
  204. },
  205. changeCurrency () {
  206. if (this.fragment.currency === 'RMB') {
  207. this.fragment.price = this.fragment.prices.rMBPrice
  208. } else if (this.fragment.currency === 'USD') {
  209. this.fragment.price = this.fragment.prices.uSDPrice
  210. }
  211. },
  212. changeNum: function (newNum) {
  213. let pack = this.commodity.minPackQty
  214. let buy = this.commodity.minBuyQty
  215. let reserve = this.commodity.reserve
  216. let breakUp = this.commodity.breakUp
  217. if (newNum < buy) {
  218. if (breakUp) {
  219. this.$message.error('最小起订量为' + buy)
  220. this.fragment.num = buy
  221. this.fragment.canSub = false
  222. } else {
  223. this.$message.error('最小起订量为' + buy)
  224. this.fragment.num = buy
  225. // this.fragment.num = (Math.floor(buy / pack) + 1) * pack
  226. console.log(this.fragment.num)
  227. this.fragment.canSub = false
  228. }
  229. if (newNum > reserve) {
  230. this.$message.error('库存不足')
  231. this.fragment.num = reserve - (reserve % pack)
  232. this.fragment.canAdd = false
  233. } else {
  234. if (reserve - this.fragment.num - pack < 0) {
  235. this.fragment.canAdd = false
  236. } else {
  237. this.fragment.canAdd = true
  238. }
  239. }
  240. } else {
  241. if (newNum - buy - pack < 0) {
  242. this.fragment.canSub = false
  243. } else {
  244. this.fragment.canSub = true
  245. }
  246. console.log(newNum)
  247. if (this.fragment.num % pack === 0) {
  248. this.fragment.num = newNum
  249. } else {
  250. this.fragment.num = (Math.floor(newNum / pack) + 1) * pack
  251. }
  252. if (this.fragment.num > reserve) {
  253. if (breakUp) {
  254. this.$message.error('库存不足')
  255. this.fragment.num = reserve
  256. this.fragment.canAdd = false
  257. } else {
  258. this.$message.error('库存不足')
  259. this.fragment.num = reserve - (reserve % pack)
  260. this.fragment.canAdd = false
  261. }
  262. } else {
  263. if (!breakUp) {
  264. let remainder = newNum % pack
  265. if (remainder !== 0) {
  266. this.fragment.num = (Math.floor(newNum / pack) + 1) * pack
  267. this.$message.error('不支持拆包且最小包装量为' + pack)
  268. }
  269. if (reserve - this.fragment.num - pack < 0) {
  270. this.fragment.canAdd = false
  271. } else {
  272. this.fragment.canAdd = true
  273. }
  274. }
  275. }
  276. }
  277. },
  278. subNum () {
  279. let newNum = this.fragment.num - this.commodity.minPackQty
  280. this.changeNum(newNum)
  281. getFragment(this.commodity, this.fragment)
  282. },
  283. addNum () {
  284. let newNum = this.fragment.num + this.commodity.minPackQty
  285. this.changeNum(newNum)
  286. getFragment(this.commodity, this.fragment)
  287. },
  288. inputNum () {
  289. if ((/^[\d]*$/).test(this.fragment.num)) {
  290. let num = Math.floor(this.fragment.num)
  291. this.changeNum(num)
  292. getFragment(this.commodity, this.fragment)
  293. } else {
  294. this.$message.error('请输入数字')
  295. this.fragment.num = this.commodity.minBuyQty
  296. }
  297. },
  298. buyNow: function (isBuy, item) {
  299. if (!this.$store.state.option.user.logged) {
  300. this.$http.get('/login/page').then(response => {
  301. if (response.data) {
  302. this.$router.push('/auth/login')
  303. }
  304. })
  305. } else {
  306. if (item) {
  307. if (isBuy) {
  308. this.$http.post('trade/order/buyNow', [{
  309. uuid: item.uuid,
  310. batchCode: item.batchCode,
  311. number: this.fragment.num,
  312. storeid: item.storeid,
  313. storeUuid: item.storeid,
  314. currencyName: item.currencyName,
  315. minPackQty: item.minPackQty
  316. }])
  317. .then(response => {
  318. // window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
  319. if (response.data.success) {
  320. if (response.data.message) {
  321. this.$message({
  322. message: response.data.message,
  323. type: 'success'
  324. })
  325. let _self = this
  326. window.setTimeout(function () {
  327. window.location.href = '/user#/order/pay/' + _self.enidfilter(response.data.data.orderid)
  328. }, 1000)
  329. } else {
  330. window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.data.orderid)
  331. }
  332. } else {
  333. if (response.data.data && response.data.data.unvailable === 1) {
  334. this.$message.error('产品信息已失效,请刷新界面')
  335. } else {
  336. this.$message.error(response.data.message)
  337. }
  338. }
  339. }, err => {
  340. console.log(err)
  341. })
  342. } else {
  343. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  344. this.$http.post('trade/cart/add', {
  345. uuid: item.uuid,
  346. batchCode: item.batchCode,
  347. number: this.fragment.num,
  348. storeid: item.storeid,
  349. storeUuid: item.storeid,
  350. currencyName: item.currencyName,
  351. minPackQty: item.minPackQty
  352. })
  353. .then(response => {
  354. if (response.data.success) {
  355. if (response.data.message) {
  356. this.$message({
  357. message: '添加购物车成功,但商品信息有更新',
  358. type: 'success'
  359. })
  360. } else {
  361. this.$message({
  362. message: '添加购物车成功',
  363. type: 'success'
  364. })
  365. }
  366. } else {
  367. this.$message.error(response.data.message)
  368. }
  369. })
  370. }
  371. }
  372. }
  373. // window.location.href = 'user#/order/pay/' + this.enidfilter(this.buy_info.orderid)
  374. },
  375. enidfilter: function (str) {
  376. if (str) {
  377. let encryptStr = '' // 最终返回的加密后的字符串
  378. // 产生三位随机数
  379. let num = ''
  380. for (let i = 0; i < 3; i++) {
  381. num += Math.floor(Math.random() * 10)
  382. }
  383. encryptStr += num // 产生3位随机数
  384. // 16位加密
  385. let tempspit = ''
  386. let strspit = str.toString().toLowerCase()
  387. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  388. /**
  389. * Unicode汉字、英文字母、数字的unicode范围
  390. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  391. *数字:[0x30,0x39](或十进制[48, 57])
  392. *小写字母:[0x61,0x7a](或十进制[97, 122])
  393. *大写字母:[0x41,0x5a](或十进制[65, 90]
  394. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  395. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  396. */
  397. let s = strspit.split('')
  398. for (let i = 0; i < s.length; i++) {
  399. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  400. s[i] = s[i].toString(16)
  401. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  402. if (s[i].length === 1) {
  403. s[i] = '0' + s[i]
  404. }
  405. tempspit = tempspit + s[i]
  406. }
  407. tempspit = tempspit + '{' + 1 // 1代表字符
  408. } else { // 数字直接转换成16进制
  409. strspit = parseInt(strspit)
  410. .toString(16)
  411. tempspit = strspit + '{' + 0 // 0代表纯数字
  412. }
  413. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  414. let numLength = temp[0].length // 转换后的字符长度
  415. numLength = numLength.toString(16) // 字符长度换算成16进制
  416. if (numLength.length === 1) { // 如果是1,补一个0
  417. numLength = '0' + numLength
  418. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  419. return ''
  420. }
  421. encryptStr += numLength
  422. if (temp[1] === '0') {
  423. encryptStr += 0
  424. } else if (temp[1] === '1') {
  425. encryptStr += 1
  426. }
  427. encryptStr += temp[0]
  428. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  429. // 产生三位随机数
  430. let numtwo = ''
  431. for (let i = 0; i < 20 - encryptStr.length; i++) {
  432. numtwo += Math.floor(Math.random() * 10)
  433. }
  434. let ran = numtwo // 产生3位随机数
  435. encryptStr += ran
  436. }
  437. return encryptStr
  438. }
  439. }
  440. }
  441. }
  442. </script>
  443. <style scoped>
  444. .container.commodity {
  445. width: 1190px;
  446. padding-left: 0;
  447. padding-right: 0;
  448. }
  449. .commodity .commodity-detail {
  450. width: 100%;
  451. display: inline-block;
  452. font-size: 0;
  453. }
  454. .commodity-detail .img{
  455. float: left;
  456. width: 258px;
  457. height: 320px;
  458. }
  459. .commodity-detail .img img {
  460. border: 1px solid #D6D3CE;
  461. }
  462. .commodity-detail .img .box {
  463. height: 62px;
  464. }
  465. .commodity-detail .content {
  466. width: 932px;
  467. float: left;
  468. font-size: 14px;
  469. }
  470. .commodity-detail .content {
  471. padding-left: 20px;
  472. }
  473. .commodity-detail .content .code {
  474. font-size: 24px;
  475. color: rgb(50, 50, 50);
  476. font-weight: 600;
  477. border-bottom: 1px solid #D6D3CE;
  478. line-height: 40px;
  479. }
  480. .commodity-detail .content .com-info {
  481. font-size: 14px;
  482. line-height: 26px;
  483. }
  484. .input-group .input-group-operate {
  485. padding: 6px 12px;
  486. font-size: 14px;
  487. font-weight: 400;
  488. line-height: 1;
  489. color: #555;
  490. text-align: center;
  491. background-color: #eee;
  492. border: 1px solid #ccc;
  493. border-radius: 4px;
  494. }
  495. .input-group .input-group-operate:last-child {
  496. border-bottom-left-radius: 0;
  497. border-top-left-radius: 0;
  498. }
  499. .input-group .input-group-operate:first-child {
  500. border-bottom-right-radius: 0;
  501. border-top-right-radius: 0;
  502. }
  503. .content .com-info .name {
  504. letter-spacing: 15px;
  505. }
  506. .content .com-info a{
  507. color: #1162a4;
  508. }
  509. .content .com-info:hover a{
  510. color: #23527c;
  511. }
  512. .commodity-info-detail {
  513. float: left;
  514. padding-top: 10px;
  515. width: 582px;
  516. }
  517. .price-block {
  518. float: right;
  519. width: 330px;
  520. margin-top: 10px;
  521. height: 220px;
  522. }
  523. .commodity-price {
  524. line-height: 30px;
  525. text-align: center;
  526. border: 1px solid #D6D3CE;
  527. }
  528. .commodity-price .title {
  529. background-color: #f7f7f7;
  530. border-bottom: 1px solid #D6D3CE;
  531. }
  532. .commodity-price .head {
  533. border-bottom: 1px solid #D6D3CE;
  534. }
  535. .commodity-price .fragment {
  536. display: inline-block;
  537. width: 70px;
  538. }
  539. .commodity-price .price {
  540. width: 123px;
  541. display: inline-block;
  542. }
  543. .com-info div.select {
  544. display: inline-block;
  545. font-weight: 600;
  546. color: red;
  547. font-size: 14px;
  548. }
  549. .com-info div.select .tax {
  550. font-weight: normal;
  551. color: black;
  552. font-size: 12px;
  553. }
  554. .com-info .operate {
  555. cursor: pointer;
  556. }
  557. .com-info .operate:hover, .com-info .operate:link {
  558. background-color: #00B83F;
  559. color: white;
  560. }
  561. .com-info .money {
  562. font-weight: 600;
  563. color: red;
  564. font-size: 14px;
  565. }
  566. .com-info select {
  567. border-radius: 4px;
  568. width: 120px!important;
  569. }
  570. ul.list-inline {
  571. margin: 0px;
  572. }
  573. .commodity-price ul.list-inline li {
  574. padding-left: 0px;
  575. padding-right: 0px;
  576. border-bottom: 1px dashed #D6D3CE;
  577. }
  578. .commodity-price .table {
  579. margin-bottom: 0px;
  580. }
  581. .commodity-price ul>li:last-child {
  582. border-bottom: none;
  583. }
  584. div.button {
  585. padding-top: 20px;
  586. float: left;
  587. }
  588. button.btn-now {
  589. border: 1px solid #3D76C6;
  590. color: #3D76C6;
  591. margin-left: 30px;
  592. }
  593. .com-info .delivery {
  594. display: inline;
  595. }
  596. #commodity-info-fragment{
  597. margin-bottom: 20px;
  598. }
  599. </style>