CommodityInfo.vue 21 KB

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