CommodityInfo.vue 18 KB

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