product.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="pages">
  3. <view class="appAdv">
  4. <swiper class="swiper" :indicator-dots="swiper.indicatorDots" :autoplay="swiper.autoplay" :interval="swiper.interval" :duration="swiper.duration">
  5. <swiper-item v-for="(item,index) in albumPics" :key="index">
  6. <view class="adv-item">
  7. <image :src="$getimg+item|miniImg(75)+'/thumbnail/600x300'" class="pic" mode="aspectFit"></image>
  8. </view>
  9. </swiper-item>
  10. <!-- <swiper-item>
  11. <view class="adv-item"><image :src="$getimg+product.pic|miniImg(50)+'/thumbnail/750x'" class="pic" mode="aspectFit"></image></view>
  12. </swiper-item> -->
  13. </swiper>
  14. </view>
  15. <!-- 轮播结束 -->
  16. <view class="product-info-wrap">
  17. <view class="product-info-til">{{product.name}}</view>
  18. <view class="product-info-brand">{{product.brandName}}<!-- <text class="postage">包邮</text> --></view>
  19. <view class="product-info-item">
  20. <text class="item">保质期:{{product.qualityGuaranteePeriod||"参考包装"}}</text>
  21. <!-- <text class="item">生产日期:{{createTime}}</text> -->
  22. <text class="item" v-if="product.unit">包装:{{product.unit}}</text>
  23. <text class="item" v-if="product.spec">规格:{{product.spec}}</text>
  24. </view>
  25. <view class="product-info-price">
  26. <text class="rmb" v-if="product.price">¥</text>
  27. <text class="price" :class="!product.price?'noprice':''">{{product.price||"暂无价格"}}</text>
  28. <text class="unit" v-if="product.price&&product.unit">/{{product.unit}}</text>
  29. </view>
  30. </view>
  31. <!-- 产品基本信息结束 -->
  32. <view class="write-radius supplier wrap">
  33. <view class="block-til">
  34. <view class="block-til-left">供应商</view>
  35. <view class="block-til-right" v-if="companyinfo.isCert==1">
  36. <view class="safe-icon">
  37. <image class="safe-icon-img" src="/static/img/icon-safe.png" mode=""></image>
  38. </view>
  39. 商家已缴纳诚信保证金
  40. </view>
  41. </view>
  42. <view class="placeoforigin-info" @click="gocompany(companyinfo.id)">
  43. <view class="placeoforigin-info-img-wrap" >
  44. <image class="placeoforigin-info-img" :src="firstimg||'/static/img/inbuild.png'|miniImg(50)+'/thumbnail/240x'" mode="aspectFit"></image>
  45. </view>
  46. <view class="placeoforigin-info-text">
  47. <view class="placeoforigin-info-text-til">{{companyinfo.compName}}</view>
  48. <view class="placeoforigin-info-text-con">
  49. <view class="placeoforigin-info-text-level">等级:{{companyinfo.compLevel}}级</view>
  50. <view class="placeoforigin-info-text-product">经营产品:{{companyinfo.compManageProduct}}</view>
  51. <view class="placeoforigin-info-text-addr">地址:{{ companyinfo.provinceId + companyinfo.cityId||''}}</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 供应商 end -->
  57. <view class="write-radius placeoforigin wrap">
  58. <view class="block-til">
  59. <view class="block-til-left">生产地</view>
  60. </view>
  61. <view class="placeoforigin-addr">{{product.placeOfProduction}}</view>
  62. </view>
  63. <!-- 生产地 end -->
  64. <view class="write-radius introduce wrap">
  65. <view class="block-til">
  66. <view class="block-til-left">产品介绍</view>
  67. </view>
  68. <!-- <view class="introduce-table">
  69. <view class="introduce-table-til">规格</view>
  70. <view class="introduce-table-con">
  71. <view class="introduce-table-row">
  72. <view class="introduce-table-col">5斤装</view>
  73. <view class="introduce-table-col">30.00元/件</view>
  74. </view>
  75. <view class="introduce-table-row">
  76. <view class="introduce-table-col">10斤装</view>
  77. <view class="introduce-table-col">50.00元/件</view>
  78. </view>
  79. </view>
  80. </view> -->
  81. <!-- introduce-table end -->
  82. <view class="page-article">
  83. <rich-text :nodes="product.description"></rich-text>
  84. <!-- <view class="page-article-text">
  85. {{product.description}}
  86. </view> -->
  87. <!-- <image v-for="(item,index) in albumPics" :key="index" :src="$getimg+item|miniImg(50)+'/thumbnail/750x'" class="full-img" mode="widthFix"></image> -->
  88. </view>
  89. </view>
  90. <!-- 产品介绍 end -->
  91. <!-- 推荐产品 end -->
  92. <view class="write-radius recommend wrap" v-if="recommendList.length>0">
  93. <view class="block-til">
  94. <view class="block-til-left">推荐产品</view>
  95. </view>
  96. <view class="recommend-list">
  97. <view class="recommend-item" v-for="(item,index) in recommendList" :key="item.id" @click="productdetails(item.id)">
  98. <image class="recommend-item-img" :src="item.pic" mode="aspectFit"></image>
  99. <view class="recommend-item-til">{{item.name}}</view>
  100. <view class="product-info-price">
  101. <text class="rmb" v-if="item.price">¥</text>
  102. <text class="price" :class="!item.price?'noprice':''">{{item.price||"暂无价格"}}</text>
  103. <text class="unit" v-if="item.price&&item.unit">/{{item.unit}}</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <view class="bottom-flex-btn-wrap">
  109. <view class="bottom-flex-btn-content">
  110. <button type="default" :disabled="isPred==0?false:true" class="bottom-flex-btn" @click="focuse(params.productid)">有意向</button>
  111. <button type="default" class="bottom-flex-btn" @click="buy(params.productid)">立即购买</button>
  112. <button type="default" class="bottom-flex-btn primary" @click="callnumber(phoneNumber)">打电话</button>
  113. </view>
  114. </view>
  115. <uni-popup ref="popup" type="dialog">
  116. <uni-popup-dialog type="info" content="还未绑定手机号码,是否去绑定?" :duration="2000" :before-close="true" @close="closepopup" @confirm="confirmpopup"></uni-popup-dialog>
  117. </uni-popup>
  118. <quick-buy class="quickbuy" :pData="this.productresult" ref="quickBuy" @closeModal="closeModal" v-if="modal.visibleModal"></quick-buy>
  119. </view>
  120. </template>
  121. <script>
  122. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  123. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  124. import quickBuy from './modal/quickBuy';
  125. export default {
  126. components: {
  127. uniPopup,
  128. uniPopupDialog,
  129. quickBuy,
  130. },
  131. data() {
  132. return {
  133. userInfo:null,
  134. params:{
  135. token:'',
  136. tokenhead:'',
  137. productid:'',
  138. },
  139. phoneNumber:'',
  140. swiper: {
  141. indicatorDots: true,
  142. autoplay: true,
  143. interval: 9000,
  144. duration: 500
  145. },
  146. productresult:[],
  147. brand:[],
  148. companyinfo:[],
  149. origin:[],
  150. product:[],
  151. createTime:'',
  152. isPred:0,
  153. albumPics:null,
  154. firstimg:'',
  155. files:[],
  156. thispage:'',
  157. modal: {
  158. visibleModal: false
  159. },
  160. addrsList:[],
  161. recommendList:[],
  162. }
  163. },
  164. onShow() {
  165. let serf = this;
  166. this.getAddrs();
  167. //检查登录,获取token
  168. // let loginRes = this.checkLogin('/pages/index/index', '2');
  169. // if(!loginRes){return false;}
  170. // serf.params.token=loginRes[0];
  171. },
  172. onLoad(option) {
  173. let self = this;
  174. uni.getStorage({
  175. key:'token',
  176. success: function (res) {
  177. self.params.token = res.data;
  178. // console.log(res.data);
  179. }
  180. });
  181. uni.getStorage({
  182. key:'tokenhead',
  183. success: function (res) {
  184. self.params.tokenhead = res.data;
  185. // console.log(res.data);
  186. }
  187. });
  188. uni.getStorage({
  189. key:'userInfo',
  190. success: function (res) {
  191. self.userInfo = res.data.user;
  192. // console.log('userInfo',self.userInfo);
  193. }
  194. });
  195. // console.log('option',option);
  196. this.params.productid = option.id;
  197. this.thispage = `/#/pages/product/product?id=${this.params.productid}`;
  198. //获取产品
  199. //,{params:this.params}
  200. this.$api.http.get(this.config.apiBaseurl+'/product/detail/'+this.params.productid).then(res => {
  201. console.log('res',JSON.parse(JSON.stringify(res)));
  202. this.isPred = res.data.data.isPred;
  203. // console.log('this.isPred',this.isPred)
  204. this.productresult = res.data.data || '';
  205. this.brand = res.data.data.brand || '';
  206. this.companyinfo = res.data.data.companyInfo || '';
  207. this.origin = res.data.data.origin || '';
  208. this.product = res.data.data.product || '';
  209. this.albumPics = this.product.albumPics||'';
  210. this.albumPics = this.albumPics.split(',');
  211. this.files = res.data.data.companyInfo.files||'';
  212. this.firstimg = this.files[0].fileUrl||'';
  213. // console.log('this.albumPics',this.albumPics,'type',typeof this.albumPics,'this.firstimg',this.firstimg);
  214. this.phoneNumber = this.companyinfo.compConNum;//动态电话
  215. // this.phoneNumber = '13885026400';
  216. // console.log('this.brand',JSON.parse(JSON.stringify(this.brand)));
  217. // console.log('this.companyinfo',JSON.parse(JSON.stringify(this.companyinfo)));
  218. // console.log('this.origin',JSON.parse(JSON.stringify(this.origin)));
  219. // console.log('this.product',JSON.parse(JSON.stringify(this.product)));
  220. this.createTime = this.product.createTime.substring(0, 10);
  221. }).catch(err => {
  222. console.log(err)
  223. });
  224. //获取推广商品
  225. this.getrecommend();
  226. },
  227. methods: {
  228. //有意向
  229. focuse(productid){
  230. console.log('this.thispage',this.thispage);
  231. //没有手机号,提醒去绑定
  232. // if(!this.userInfo.phone){
  233. // this.$refs.popup.open();
  234. // return false;
  235. // };
  236. let thetoken = this.params.tokenhead + this.params.token;
  237. this.$api.http.put(this.config.apiBaseurl+'/pre/add',{productId:productid},{header: {Authorization:thetoken}}).then(res => {
  238. if(res.data.code!=200){
  239. uni.showToast({
  240. icon:"none",
  241. title:res.data.message,
  242. duration: 2000
  243. });
  244. return false;
  245. };
  246. console.log(res);
  247. uni.showToast({
  248. icon:'success',
  249. mask:true,
  250. title:`已添加有意向`,
  251. duration: 2000
  252. });
  253. }).catch(err => {
  254. uni.showToast({
  255. icon:'none',
  256. mask:true,
  257. // title:err.data.message,
  258. title:err.data.message,
  259. duration: 2000
  260. });
  261. console.log(err.data.message);
  262. });
  263. },
  264. //打电话
  265. callnumber(number){
  266. if(!number){
  267. uni.showToast({
  268. icon:'none',
  269. mask:true,
  270. title:`手机号码为空`,
  271. duration: 2000
  272. });
  273. return;
  274. };
  275. uni.makePhoneCall({
  276. phoneNumber: number
  277. });
  278. },
  279. // 跳转到供应商
  280. gocompany(id){
  281. uni.navigateTo({
  282. url:`/pages/supplier/supplierdetail/supplierdetail?id=${id}`
  283. })
  284. },
  285. closeModal(){
  286. this.modal.visibleModal = false;
  287. },
  288. closepopup(done){
  289. done()
  290. },
  291. confirmpopup(done,value){
  292. uni.navigateTo({
  293. url:'/pages/usercenter/bindphone/bindphone'
  294. });
  295. done()
  296. },
  297. buy(item){
  298. // console.log('item',item);
  299. console.log('this.addrsList',this.addrsList);
  300. if(this.addrsList.length <=0){
  301. console.log('productid',this.params.productid);
  302. uni.setStorage({
  303. key: 'productID',
  304. data:this.params.productid
  305. });
  306. uni.showToast({
  307. title:"您还未设置收货地址,将跳到设置页!",
  308. icon:"none",
  309. duration:2000
  310. });
  311. setTimeout(i=>{
  312. uni.navigateTo({
  313. url: '/pages/usercenter/addrs/addrs',
  314. fail:function(err){
  315. console.log(err)
  316. }
  317. });
  318. },2000);
  319. return;
  320. }
  321. if(!this.product.price){
  322. uni.showToast({
  323. icon:'none',
  324. mask:true,
  325. title:`暂时无法购买`,
  326. duration: 2000
  327. });
  328. return false;
  329. };
  330. this.modal.visibleModal = true;
  331. this.$nextTick(res => {
  332. this.$refs.quickBuy.openPop();
  333. });
  334. },
  335. getAddrs(){
  336. // console.log('this.token',this.token);
  337. let thetoken = this.params.tokenhead + this.params.token;
  338. this.$api.http.get(this.config.apiBaseurl + '/member/address/list',{header: {Authorization:thetoken}}).then(res => {
  339. // console.log('getAddrList', res.data.data);
  340. this.addrsList = res.data.data;
  341. }).catch(err => {
  342. // console.log('err', err)
  343. })
  344. },
  345. //获取推广商品
  346. getrecommend(){
  347. this.$api.http.get(this.config.apiBaseurl+'/home/better-select', {header: {Authorization:this.params.tokenhead+this.params.token}}).then(res => {
  348. // console.log('getrecommend',res)
  349. this.recommendList = res.data.data.list;
  350. console.log('this.recommendList',JSON.parse(JSON.stringify(this.recommendList)));
  351. }).catch(err => {
  352. console.log(err)
  353. });
  354. },
  355. //跳转详情
  356. productdetails(id){
  357. uni.navigateTo({
  358. url:`/pages/product/product?id=${id}`
  359. })
  360. },
  361. }
  362. }
  363. </script>
  364. <style>
  365. @import url("./product.css");
  366. </style>