CommodityInfo.vue 16 KB

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