CommodityInfo.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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) | currency('', 2)}}</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. },
  176. mounted () {
  177. this.$nextTick(() => {
  178. this.loadSaveHistory()
  179. })
  180. },
  181. methods: {
  182. loadSaveHistory () {
  183. this.$store.dispatch('shop/saveHistory', {id: this.commodity.batchCode})
  184. },
  185. changeCurrency () {
  186. if (this.fragment.currency === 'RMB') {
  187. this.fragment.price = this.fragment.prices.rMBPrice
  188. } else if (this.fragment.currency === 'USD') {
  189. this.fragment.price = this.fragment.prices.uSDPrice
  190. }
  191. },
  192. subNum () {
  193. let newNum = this.fragment.num - this.commodity.minPackQty
  194. if (newNum >= this.commodity.minBuyQty) {
  195. this.fragment.num = newNum
  196. } else {
  197. this.fragment.canSub = false
  198. }
  199. this.fragment.canAdd = true
  200. getFragment(this.commodity, this.fragment)
  201. },
  202. addNum () {
  203. let newNum = this.fragment.num + this.commodity.minPackQty
  204. if (newNum <= this.commodity.reserve) {
  205. this.fragment.num = newNum
  206. } else {
  207. this.fragment.canAdd = false
  208. }
  209. this.fragment.canSub = true
  210. getFragment(this.commodity, this.fragment)
  211. },
  212. inputNum () {
  213. if (this.fragment.num < this.commodity.minBuyQty) {
  214. this.fragment.num = this.commodity.minBuyQty
  215. } else if (this.fragment.num > this.commodity.reserve) {
  216. this.fragment.num = this.commodity.reserve
  217. }
  218. getFragment(this.commodity, this.fragment)
  219. },
  220. buyNow: function (isBuy, item) {
  221. if (item) {
  222. // this.$emit('buyAction', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  223. if (isBuy) {
  224. // this.$store.dispatch('user/getBuyInfo', [{uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty}])
  225. axios.post('trade/order/buyNow', [{uuid: item.uuid, batchCode: item.batchCode, number: this.fragment.num}])
  226. .then(response => {
  227. window.location.href = '/user#/order/pay/' + this.enidfilter(response.data.orderid)
  228. }, err => {
  229. console.log(err)
  230. this.$http.get('/login/page').then(response => {
  231. if (response.data) {
  232. this.$router.push('/auth/login')
  233. }
  234. })
  235. })
  236. } else {
  237. // this.$store.dispatch('user/addCar', {uuid: item.uuid, batchCode: item.batchCode, number: item.minBuyQty})
  238. axios.post('trade/cart/add', {uuid: item.uuid, batchCode: item.batchCode, number: this.fragment.num})
  239. .then(response => {
  240. console.log(response.data)
  241. if (response.data.success) {
  242. Message({
  243. message: '添加购物车成功',
  244. type: 'success'
  245. })
  246. } else {
  247. Message.error(response.data.message)
  248. // console.log(response.data.message)
  249. }
  250. })
  251. }
  252. }
  253. // window.location.href = 'user#/order/pay/' + this.enidfilter(this.buy_info.orderid)
  254. },
  255. enidfilter: function (str) {
  256. if (str) {
  257. let encryptStr = '' // 最终返回的加密后的字符串
  258. // 产生三位随机数
  259. let num = ''
  260. for (let i = 0; i < 3; i++) {
  261. num += Math.floor(Math.random() * 10)
  262. }
  263. encryptStr += num // 产生3位随机数
  264. // 16位加密
  265. let tempspit = ''
  266. let strspit = str.toString().toLowerCase()
  267. if (strspit.match(/^[-+]?\d*$/) === null) { // 非整数字符,对每一个字符都转换成16进制,然后拼接
  268. /**
  269. * Unicode汉字、英文字母、数字的unicode范围
  270. *汉字:[0x4e00,0x9fa5](或十进制[19968,40869])
  271. *数字:[0x30,0x39](或十进制[48, 57])
  272. *小写字母:[0x61,0x7a](或十进制[97, 122])
  273. *大写字母:[0x41,0x5a](或十进制[65, 90]
  274. * 'a'的Unicode编码:'&#97;',charCodeAt()的值是97
  275. * '码'的Unicode编码:'\u7801', new String('码').charCodeAt()的值是30721,30721的16进制表示是7801
  276. */
  277. let s = strspit.split('')
  278. for (let i = 0; i < s.length; i++) {
  279. s[i] = s[i].charCodeAt() // 先转换成Unicode编码
  280. s[i] = s[i].toString(16)
  281. // 因为在服务器是每两位当做一个字符进行解析的,所以这里每个字符的Unicode编码范围必须在0——255之间。数字和大小写满足该要求,特殊字符则不一定,如果后续有特殊字符的要求,需要重写编码器和解码器
  282. if (s[i].length === 1) {
  283. s[i] = '0' + s[i]
  284. }
  285. tempspit = tempspit + s[i]
  286. }
  287. tempspit = tempspit + '{' + 1 // 1代表字符
  288. } else { // 数字直接转换成16进制
  289. strspit = parseInt(strspit)
  290. .toString(16)
  291. tempspit = strspit + '{' + 0 // 0代表纯数字
  292. }
  293. let temp = tempspit.split('{') // 对要加密的字符转换成16进制
  294. let numLength = temp[0].length // 转换后的字符长度
  295. numLength = numLength.toString(16) // 字符长度换算成16进制
  296. if (numLength.length === 1) { // 如果是1,补一个0
  297. numLength = '0' + numLength
  298. } else if (numLength.length > 3) { // 转换后的16进制字符长度如果大于2位数,则返回,不支持
  299. return ''
  300. }
  301. encryptStr += numLength
  302. if (temp[1] === '0') {
  303. encryptStr += 0
  304. } else if (temp[1] === '1') {
  305. encryptStr += 1
  306. }
  307. encryptStr += temp[0]
  308. if (encryptStr.length < 20) { // 如果小于20位,补上随机数
  309. // 产生三位随机数
  310. let numtwo = ''
  311. for (let i = 0; i < 20 - encryptStr.length; i++) {
  312. numtwo += Math.floor(Math.random() * 10)
  313. }
  314. let ran = numtwo // 产生3位随机数
  315. encryptStr += ran
  316. }
  317. return encryptStr
  318. }
  319. }
  320. }
  321. }
  322. </script>
  323. <style scoped>
  324. .container.commodity {
  325. width: 1190px;
  326. padding-left: 0px;
  327. padding-right: 0px;
  328. font-family: "Microsoft Yahei", "微软雅黑";
  329. }
  330. .commodity .commodity-detail {
  331. width: 100%;
  332. display: inline-block;
  333. font-size: 0px;
  334. }
  335. .commodity-detail .img{
  336. float: left;
  337. width: 258px;
  338. height: 320px;
  339. }
  340. .commodity-detail .img img {
  341. border: 1px solid #D6D3CE;
  342. }
  343. .commodity-detail .img .box {
  344. height: 62px;
  345. }
  346. .commodity-detail .content {
  347. width: 932px;
  348. float: left;
  349. font-size: 14px;
  350. }
  351. .commodity-detail .content {
  352. padding-left: 20px;
  353. }
  354. .commodity-detail .content .code {
  355. font-size: 24px;
  356. color: rgb(50, 50, 50);
  357. font-weight: 600;
  358. border-bottom: 1px solid #D6D3CE;
  359. line-height: 40px;
  360. }
  361. .commodity-detail .content .com-info {
  362. font-size: 14px;
  363. font-family: "Microsoft Yahei", "微软雅黑";
  364. line-height: 26px;
  365. }
  366. .input-group .input-group-operate {
  367. padding: 6px 12px;
  368. font-size: 14px;
  369. font-weight: 400;
  370. line-height: 1;
  371. color: #555;
  372. text-align: center;
  373. background-color: #eee;
  374. border: 1px solid #ccc;
  375. border-radius: 4px;
  376. }
  377. .input-group .input-group-operate:last-child {
  378. border-bottom-left-radius: 0px;
  379. border-top-left-radius: 0px;
  380. }
  381. .input-group .input-group-operate:first-child {
  382. border-bottom-right-radius: 0px;
  383. border-top-right-radius: 0px;
  384. }
  385. .content .com-info .name {
  386. letter-spacing: 15px;
  387. }
  388. .commodity-info-detail {
  389. float: left;
  390. padding-top: 10px;
  391. width: 582px;
  392. }
  393. .price-block {
  394. float: right;
  395. width: 330px;
  396. margin-top: 10px;
  397. height: 220px;
  398. }
  399. .commodity-price {
  400. line-height: 30px;
  401. text-align: center;
  402. border: 1px solid #D6D3CE;
  403. }
  404. .commodity-price .title {
  405. background-color: #f7f7f7;
  406. border-bottom: 1px solid #D6D3CE;
  407. }
  408. .commodity-price .head {
  409. border-bottom: 1px solid #D6D3CE;
  410. }
  411. .commodity-price .fragment {
  412. display: inline-block;
  413. width: 70px;
  414. }
  415. .commodity-price .price {
  416. width: 123px;
  417. display: inline-block;
  418. }
  419. .com-info div.select {
  420. display: inline-block;
  421. }
  422. .com-info .operate {
  423. cursor: pointer;
  424. }
  425. .com-info .operate:hover, .com-info .operate:link {
  426. background-color: #00B83F;
  427. color: white;
  428. }
  429. .com-info .money {
  430. font-weight: 600;
  431. color: red;
  432. }
  433. .com-info select {
  434. border-radius: 4px;
  435. width: 120px!important;
  436. }
  437. ul.list-inline {
  438. margin: 0px;
  439. }
  440. .commodity-price ul.list-inline li {
  441. padding-left: 0px;
  442. padding-right: 0px;
  443. border-bottom: 1px dashed #D6D3CE;
  444. }
  445. .commodity-price .table {
  446. margin-bottom: 0px;
  447. }
  448. .commodity-price ul>li:last-child {
  449. border-bottom: none;
  450. }
  451. div.button {
  452. padding-top: 20px;
  453. float: left;
  454. }
  455. button.btn-now {
  456. border: 1px solid #3D76C6;
  457. color: #3D76C6;
  458. margin-left: 30px;
  459. }
  460. .com-info .delivery {
  461. display: inline;
  462. }
  463. #commodity-info-fragment{
  464. margin-bottom: 20px;
  465. }
  466. </style>