detail.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <view>
  3. <swiper
  4. class="swiper"
  5. v-if="slides.length"
  6. :indicator-dots="slides.length > 1"
  7. indicator-color="#DC808B"
  8. indicator-active-color="#C30D23"
  9. >
  10. <swiper-item class="swiper-item" v-for="item in slides" :key="item.url">
  11. <image
  12. class="image"
  13. :src="item.cover"
  14. mode="aspectFill"
  15. lazy-load="true"
  16. />
  17. <view class="qrcode" @click="saveQrcode">
  18. <text class="iconfont icon-xiazai" />
  19. 二维码
  20. </view>
  21. </swiper-item>
  22. </swiper>
  23. <view class="head">
  24. <view class="line1">
  25. <view class="left">
  26. <text class="iconfont icon-biaoqian" />
  27. {{ detail.mainclassnames }}
  28. </view>
  29. <view
  30. class="right"
  31. hover-class="navigator-hover"
  32. @click="collectLoading ? '' : handleCollect(detail.iscollect)"
  33. >
  34. <u-loading-icon v-if="collectLoading" size="20" />
  35. <block v-else>
  36. <text
  37. v-if="detail.iscollect == 0"
  38. class="iconfont icon-weishoucang"
  39. />
  40. <text
  41. v-else
  42. class="iconfont icon-yishoucang"
  43. style="color: #ffc300"
  44. />
  45. 收藏
  46. </block>
  47. </view>
  48. </view>
  49. <view class="title">{{ detail.name }}</view>
  50. <view class="subtitle">型号:{{ detail.model || "--" }}</view>
  51. <view class="subtitle">尺寸:{{ detail.spec || "--" }}</view>
  52. <view class="subtitle">价格:{{ CNY(detail.price) || "--" }}</view>
  53. </view>
  54. <view class="introduce">
  55. <block v-if="detail.content">
  56. <view class="introduce-title"> 产品介绍 </view>
  57. <view class="introduce-text">
  58. <u-parse :content="detail.content" />
  59. </view>
  60. </block>
  61. </view>
  62. <storeInfo />
  63. <view style="position: absolute; z-index: -999; top: 0">
  64. <l-painter
  65. ref="painter"
  66. hidden
  67. css="padding:10px;background:#fff;width: 148px;"
  68. >
  69. <l-painter-view>
  70. <l-painter-view css="margin: 0 auto;width: 128px;">
  71. <l-painter-qrcode
  72. :text="detail.appleturl"
  73. css="width: 128px; height: 128px;color:#000;"
  74. />
  75. </l-painter-view>
  76. <l-painter-view
  77. css="width: 108px;text-align: center;margin: 10px auto 0;"
  78. >
  79. <l-painter-text :text="detail.name" />
  80. </l-painter-view>
  81. </l-painter-view>
  82. </l-painter>
  83. </view>
  84. <bottomForm
  85. :shareuserid="shareUserid"
  86. type="产品"
  87. ownertable="sa_fad"
  88. :ownerid="sa_fadid"
  89. />
  90. </view>
  91. </template>
  92. <script>
  93. import { winTheCustomer } from "../../utils/share";
  94. import lPainter from "../../uni_modules/lime-painter/components/l-painter/l-painter.vue";
  95. import lPainterText from "../../uni_modules/lime-painter/components/l-painter-text/l-painter-text.vue";
  96. import lPainterView from "../../uni_modules/lime-painter/components/l-painter-view/l-painter-view.vue";
  97. import lPainterQrcode from "../../uni_modules/lime-painter/components/l-painter-qrcode/l-painter-qrcode.vue";
  98. export default {
  99. components: { lPainter, lPainterQrcode, lPainterText, lPainterView },
  100. data() {
  101. return {
  102. sa_fadid: null,
  103. detail: {},
  104. slides: [],
  105. collectLoading: false,
  106. shareUserid: 0,
  107. };
  108. },
  109. onLoad(options) {
  110. this.sa_fadid = options.id;
  111. this.isInitializeLogin(render.bind(this));
  112. function render() {
  113. this.getDetail(true);
  114. this.shareUserid = winTheCustomer(options.shareUserid || 0, "单品", {
  115. ownertable: "sa_fad",
  116. ownerid: this.sa_fadid,
  117. });
  118. }
  119. },
  120. methods: {
  121. getDetail(init = false) {
  122. if (!init) return;
  123. this.$Http
  124. .basic({
  125. id: 20240418141002,
  126. content: {
  127. sa_fadid: this.sa_fadid,
  128. },
  129. })
  130. .then((res) => {
  131. console.log("获取单品详情", res);
  132. if (this.cutoff(res.msg)) return;
  133. this.detail = res.data;
  134. this.slides = res.data.attinfos_pic.map((v) => {
  135. return {
  136. cover: this.getSpecifiedImage(v.attinfos[0], "compressed"),
  137. url: v.attinfos[0].url,
  138. };
  139. });
  140. uni.setNavigationBarTitle({
  141. title: res.data.name,
  142. });
  143. });
  144. },
  145. handleCollect(iscollect) {
  146. this.collectLoading = true;
  147. this.$Http
  148. .basic({
  149. id: 20240416133702,
  150. content: {
  151. ownertable: "sa_fad",
  152. ownerid: this.detail.sa_fadid,
  153. type: 1,
  154. },
  155. })
  156. .then((res) => {
  157. console.log("收藏", res);
  158. this.collectLoading = false;
  159. if (this.cutoff(res.msg)) return;
  160. this.detail.iscollect = iscollect ? 0 : 1;
  161. });
  162. },
  163. saveQrcode() {
  164. let that = this;
  165. that.$refs.painter.canvasToTempFilePathSync({
  166. fileType: "jpg",
  167. // 如果返回的是base64是无法使用 saveImageToPhotosAlbum,需要设置 pathType为url
  168. pathType: "url",
  169. quality: 1,
  170. success: (res) => {
  171. console.log(res.tempFilePath);
  172. // 非H5 保存到相册
  173. // H5 提示用户长按图另存
  174. uni.saveImageToPhotosAlbum({
  175. filePath: res.tempFilePath,
  176. success: function (e) {
  177. uni.showModal({
  178. title: "提示",
  179. content: "图片已保存到系统相册",
  180. showCancel: false,
  181. });
  182. that.loading = false;
  183. },
  184. fail: ({ errMsg }) => {
  185. if (errMsg == "saveImageToPhotosAlbum:fail auth deny") {
  186. uni.showModal({
  187. title: "提示",
  188. content: "请授权添加到相册权限后再试!",
  189. showCancel: false,
  190. complete: (complete) => {
  191. uni.openSetting({
  192. success: (res) => {
  193. that.loading = false;
  194. if (res.authSetting["scope.writePhotosAlbum"]) {
  195. this.saveTheImage();
  196. } else {
  197. uni.showModal({
  198. title: "提示",
  199. content: "未获取授权!已取消保存",
  200. showCancel: false,
  201. });
  202. }
  203. },
  204. });
  205. },
  206. });
  207. } else {
  208. that.loading = false;
  209. uni.showModal({
  210. title: "提示",
  211. content: "已取消保存",
  212. showCancel: false,
  213. });
  214. }
  215. },
  216. });
  217. },
  218. });
  219. },
  220. getSheraDate() {
  221. let detail = this.detail;
  222. return {
  223. title: detail.name, // 标题
  224. path:
  225. "/packageCase/product/detail?id=" +
  226. detail.sa_fadid +
  227. "&shareUserid=" +
  228. this.shareUserid, // 分享路径
  229. imageUrl:
  230. this.detail.attinfos.find((v) => v.usetype == "sa_fad").url || "", // 分享图
  231. };
  232. },
  233. },
  234. onShareAppMessage(res) {
  235. return this.getSheraDate();
  236. },
  237. onShareTimeline() {
  238. return this.getSheraDate();
  239. },
  240. };
  241. </script>
  242. <style lang="scss">
  243. .swiper {
  244. width: 375px;
  245. height: 231px;
  246. background: #f5f5f5;
  247. border-radius: 5px;
  248. box-sizing: border-box;
  249. .swiper-item {
  250. position: relative;
  251. width: 100%;
  252. height: 100%;
  253. .image {
  254. width: 100%;
  255. height: 100%;
  256. }
  257. .qrcode {
  258. position: absolute;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. top: 10px;
  263. right: 10px;
  264. width: 70px;
  265. height: 25px;
  266. background: rgba($color: #333333, $alpha: 0.5);
  267. font-size: 12px;
  268. color: #ffffff;
  269. .iconfont {
  270. margin-right: 4px;
  271. }
  272. }
  273. }
  274. }
  275. .head {
  276. background: #fff;
  277. padding: 8px 10px 15px;
  278. .line1 {
  279. display: flex;
  280. justify-content: space-between;
  281. align-items: flex-end;
  282. .left {
  283. .iconfont {
  284. margin-right: 4px;
  285. font-size: 12px;
  286. }
  287. line-height: 17px;
  288. font-size: 12px;
  289. color: #999999;
  290. }
  291. .right {
  292. display: flex;
  293. align-items: center;
  294. justify-content: center;
  295. width: 80px;
  296. height: 24px;
  297. border-radius: 12px;
  298. border: 1px solid #cccccc;
  299. font-family: PingFang SC, PingFang SC;
  300. font-size: 12px;
  301. color: #333333;
  302. .iconfont {
  303. margin-right: 5px;
  304. }
  305. }
  306. }
  307. .title {
  308. line-height: 20px;
  309. font-family: PingFang SC, PingFang SC;
  310. font-weight: bold;
  311. font-size: 14px;
  312. color: #333333;
  313. margin: 10px 0;
  314. }
  315. .subtitle {
  316. line-height: 17px;
  317. font-family: PingFang SC, PingFang SC;
  318. font-size: 12px;
  319. color: #666666;
  320. margin-top: 5px;
  321. }
  322. }
  323. .introduce {
  324. background: #fff;
  325. margin-top: 10px;
  326. padding: 0 10px;
  327. &-title {
  328. line-height: 45px;
  329. background: #ffffff;
  330. font-family: PingFang SC, PingFang SC;
  331. font-weight: bold;
  332. font-size: 16px;
  333. color: #333333;
  334. }
  335. &-text {
  336. line-height: 20px;
  337. font-family: PingFang SC, PingFang SC;
  338. font-size: 14px;
  339. color: #333333;
  340. padding-bottom: 10px;
  341. }
  342. }
  343. </style>