product.vue 12 KB

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