CommodityInfo.vue 16 KB

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