goods.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="app-layout">
  3. <app-layout>
  4. <view class="poster-goods dir-top-nowrap" v-if="loadShow">
  5. <view id="head" class="head box-grow-1 main-center">
  6. <template v-if="selectForm.style == styleList[0].value">
  7. <app-goods-poster-one :info="info" :form="selectForm"
  8. :multiple="multiple"></app-goods-poster-one>
  9. </template>
  10. <template v-if="selectForm.style == styleList[1].value">
  11. <app-goods-poster-two :info="info" :form="selectForm"
  12. :multiple="multiple"></app-goods-poster-two>
  13. </template>
  14. <template v-if="selectForm.style == styleList[2].value">
  15. <app-goods-poster-three :info="info" :form="selectForm"
  16. :multiple="multiple"></app-goods-poster-three>
  17. </template>
  18. <template v-if="selectForm.style == styleList[3].value">
  19. <app-goods-poster-four :info="info" :form="selectForm"
  20. :multiple="multiple"></app-goods-poster-four>
  21. </template>
  22. </view>
  23. <view class="setting box-grow-0">
  24. <view class="dir-left-nowrap line">
  25. <view class="box-grow-0 main-center cross-center label">
  26. <icon :style="{'background-color': getTheme.background}" type></icon>
  27. <text>样式</text>
  28. </view>
  29. <view class="dir-left-wrap box-grow-1">
  30. <block v-for="(item,key) in styleList" :key="key">
  31. <template v-if="config.poster_style.indexOf(item.value.toString()) !== -1">
  32. <view :key="key"
  33. @click="changeStyle(item.value)"
  34. :style="{'border-color': item.value == selectForm.style ? getTheme.border : ''}"
  35. :class="item.value == selectForm.style ? 'active' : ''"
  36. class="style-input main-center cross-center"
  37. >
  38. <text>{{item.label}}</text>
  39. <icon
  40. v-if="item.value == selectForm.style"
  41. :style="{'background-color': getTheme.background}"
  42. class="icon-active" type></icon>
  43. </view>
  44. </template>
  45. </block>
  46. </view>
  47. </view>
  48. <view class="dir-left-nowrap line">
  49. <view class="box-grow-0 main-center cross-center label">
  50. <icon :style="{'background-color': getTheme.background}" type></icon>
  51. <text>排版</text>
  52. </view>
  53. <view class="dir-left-wrap box-grow-1">
  54. <block v-for="(item,key) in typesettingList" :key="key">
  55. <template v-if="config.image_style.indexOf(item.value.toString()) !== -1">
  56. <view :key="key"
  57. @click="changeTypeSetting(item.value)"
  58. :style="{'border-color': item.value == selectForm.typesetting ? getTheme.border : ''}"
  59. :class="item.value == selectForm.typesetting ? 'active' : ''"
  60. class="line-input dir-left-nowrap main-center cross-center"
  61. >
  62. <img :src="item.pic_url" class="icon-square"
  63. :style="{'background-image': `url(${item.pic_url})`}"/>
  64. <text>{{item.label}}</text>
  65. <icon v-if="item.value == selectForm.typesetting"
  66. :style="{'background-color': getTheme.background}"
  67. class="icon-active" type></icon>
  68. </view>
  69. </template>
  70. </block>
  71. </view>
  72. </view>
  73. <view class="dir-left-nowrap line" style="margin-bottom:5rpx">
  74. <view class="box-grow-0 main-center cross-center label">
  75. <icon :style="{'background-color': getTheme.background}" type></icon>
  76. <text>类型</text>
  77. </view>
  78. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  79. <view v-for="(item,key) in typeList" :key="key"
  80. @click="changeType(item.value)"
  81. :style="{'border-color': item.value == selectForm.type ? getTheme.border : ''}"
  82. :class="item.value == selectForm.type ? 'active' : ''"
  83. class="style-input dir-left-nowrap main-center cross-center"
  84. >
  85. <view v-if="item.value === 1" class="type-pure"></view>
  86. <view v-if="item.value === 2" class="type-gradient"></view>
  87. <text>{{item.label}}</text>
  88. <icon v-if="item.value == selectForm.type"
  89. :style="{'background-color': getTheme.background}"
  90. class="icon-active" type></icon>
  91. </view>
  92. </view>
  93. </view>
  94. <view class="dir-left-nowrap line">
  95. <view class="box-grow-0 main-center cross-center label" style="margin-top: 19rpx">
  96. <icon :style="{'background-color': getTheme.background}" type></icon>
  97. <text>颜色</text>
  98. </view>
  99. <view class="dir-left-wrap box-grow-1">
  100. <scroll-view scroll-x class="app-scroll" enable-flex="true">
  101. <view v-for="(color,key) in config.color" :key="key"
  102. @click="changeColor(color)"
  103. class="color-bg"
  104. :style="{'background': `${color}`}">
  105. <icon v-if="color == selectForm.color"
  106. :style="{'background-color': getTheme.background}"
  107. class="icon-active" type></icon>
  108. </view>
  109. </scroll-view>
  110. </view>
  111. </view>
  112. <view @click="submitSave" :style="{'background-color': getTheme.background}" class="button main-center cross-center">保存图片
  113. </view>
  114. </view>
  115. </view>
  116. </app-layout>
  117. </view>
  118. </template>
  119. <script>
  120. import AppGoodsPosterOne from '../../components/page-component/app-goods-poster/app-goods-poster-one.vue';
  121. import AppGoodsPosterTwo from '../../components/page-component/app-goods-poster/app-goods-poster-two.vue';
  122. import AppGoodsPosterThree from '../../components/page-component/app-goods-poster/app-goods-poster-three.vue';
  123. import AppGoodsPosterFour from '../../components/page-component/app-goods-poster/app-goods-poster-four.vue';
  124. import {mapGetters} from "vuex";
  125. export default {
  126. name: "goods",
  127. components: {AppGoodsPosterOne, AppGoodsPosterTwo, AppGoodsPosterThree, AppGoodsPosterFour},
  128. data() {
  129. return {
  130. loadShow: false,
  131. styleList: [{
  132. label: '样式一',
  133. value: 1
  134. }, {
  135. label: '样式二',
  136. value: 2
  137. }, {
  138. label: '样式三',
  139. value: 3
  140. }, {
  141. label: '样式四',
  142. value: 4
  143. }],
  144. typesettingList: [{
  145. label: '1张图',
  146. value: 1,
  147. pic_url: '../../static/image/poster/pic-one.png'
  148. }, {
  149. label: '2张图',
  150. value: 2,
  151. pic_url: '../../static/image/poster/pic-two.png'
  152. }, {
  153. label: '3张图',
  154. value: 3,
  155. pic_url: '../../static/image/poster/pic-three.png'
  156. }, {
  157. label: '4张图',
  158. value: 4,
  159. pic_url: '../../static/image/poster/pic-four.png'
  160. }, {
  161. label: '5张图',
  162. value: 5,
  163. pic_url: '../../static/image/poster/pic-five.png'
  164. }],
  165. typeList: [],
  166. colorList: [],
  167. selectForm: null,
  168. config: {
  169. color: [],
  170. image_style: [],
  171. poster_style: []
  172. },
  173. multiple: 0,
  174. info: null,
  175. posterConfig: '',
  176. posterGenerate: ''
  177. }
  178. },
  179. onLoad(options) { this.$commonLoad.onload(options);
  180. let { poster_config, poster_generate } = options;
  181. if (poster_config && poster_generate) {
  182. // #ifdef MP
  183. this.posterConfig = unescape(poster_config);
  184. this.posterGenerate = unescape(poster_generate);
  185. // #endif
  186. // #ifdef H5
  187. this.posterConfig = atob(poster_config);
  188. this.posterGenerate = atob(poster_generate);
  189. // #endif
  190. } else {
  191. return;
  192. }
  193. this.$nextTick(function (){
  194. this.loadData();
  195. })
  196. },
  197. methods: {
  198. calcMultiple() {
  199. let query = null;
  200. // #ifndef MP-WEIXIN
  201. query = uni.createSelectorQuery();
  202. // #endif
  203. // #ifdef MP-WEIXIN
  204. query = uni.createSelectorQuery().in(this);
  205. // #endif
  206. query.select('#head').boundingClientRect(item => {
  207. // #ifndef MP-TOUTIAO
  208. this.multiple = (item.height * (750 / uni.getSystemInfoSync().screenWidth) - 24 - 24) / 1334;
  209. // #endif
  210. // #ifdef MP-TOUTIAO
  211. this.multiple = 0.455;
  212. // #endif
  213. }).exec();
  214. },
  215. loadData() {
  216. this.$request({
  217. url: this.posterConfig,
  218. }).then(info => {
  219. this.$hideLoading();
  220. this.loadShow = true;
  221. let { code, data, msg } = info;
  222. if (code === 0) {
  223. this.config = data.config;
  224. this.info = data.info;
  225. this.typeList = [{label: '纯色', value: 1}, {label: '渐变', value: 2}];
  226. this.selectForm = {
  227. color: this.config['color'][0],
  228. style: this.config['poster_style'][0],
  229. typesetting: this.config['image_style'][0],
  230. type: 1
  231. }
  232. setTimeout(() => {
  233. this.calcMultiple();
  234. });
  235. } else {
  236. uni.showToast({title: msg,icon: 'none'});
  237. }
  238. })
  239. },
  240. changeStyle(value) {
  241. this.selectForm.style = value;
  242. },
  243. changeTypeSetting(value) {
  244. this.selectForm.typesetting = value;
  245. },
  246. changeType(value) {
  247. this.selectForm.type = value;
  248. },
  249. changeColor(value) {
  250. this.selectForm.color = value;
  251. },
  252. submitSave() {
  253. this.$showLoading({text: '生成中'});
  254. this.$request({
  255. url: this.posterGenerate,
  256. data: this.selectForm
  257. }).then(info => {
  258. this.$hideLoading();
  259. let { code, data, msg } = info;
  260. if (code === 0) {
  261. const pic_url = data.pic_url;
  262. // #ifndef H5
  263. if(false){
  264. let reg = /(api\/qrcode\/goods-new)+/;
  265. if(reg.test(this.posterGenerate)){
  266. let url = this.$api.index.test + '&url=' + btoa(pic_url);
  267. this.$utils.batchSave(url);
  268. return;
  269. }
  270. }
  271. // #endif
  272. this.$utils.batchSave(pic_url, 'image').then(() => {
  273. uni.showToast({title: '保存成功'});
  274. });
  275. } else {
  276. uni.showToast({title: msg, icon: 'none'});
  277. }
  278. }).catch(() => {
  279. this.$hideLoading();
  280. })
  281. }
  282. },
  283. computed: {
  284. ...mapGetters('mallConfig', {
  285. getTheme: 'getTheme'
  286. })
  287. },
  288. }
  289. </script>
  290. <style scoped lang="scss">
  291. $box: #f7f7f7;
  292. .app-layout /deep/ .app-layout {
  293. overflow-y: auto;
  294. }
  295. ::-webkit-scrollbar {
  296. width: 0;
  297. height: 0;
  298. color: transparent;
  299. }
  300. .app-scroll {
  301. width: 100%;
  302. white-space: nowrap;
  303. padding: 0 #{14rpx};
  304. }
  305. .poster-goods {
  306. height: 100vh;
  307. .head {
  308. height: #{655rpx};
  309. width: 100%;
  310. }
  311. .setting {
  312. padding-top: #{20rpx};
  313. font-size: #{24rpx};
  314. color: #353535;
  315. background: #FFFFFF;
  316. padding-bottom: #{48rpx};
  317. .line {
  318. margin-bottom: #{24rpx};
  319. .label {
  320. height: #{56rpx};
  321. icon {
  322. background-image: url("../../static/image/poster/mark.png");
  323. background-size: 100% 100%;
  324. height: #{21rpx};
  325. width: #{21rpx};
  326. background-repeat: no-repeat;
  327. margin-left: #{24rpx};
  328. border-radius: 50%;
  329. }
  330. text {
  331. line-height: 1;
  332. padding-left: #{12rpx};
  333. padding-right: #{26rpx - 14rpx};
  334. }
  335. }
  336. .style-input {
  337. position: relative;
  338. height: #{56rpx};
  339. width: #{120rpx};
  340. background: $box;
  341. border-radius: #{5rpx};
  342. margin: 0 #{14rpx};
  343. .type-pure {
  344. height: #{32rpx};
  345. width: #{32rpx};
  346. margin-right: #{10rpx};
  347. background: #d8d8d8;
  348. }
  349. .type-gradient {
  350. height: #{32rpx};
  351. width: #{32rpx};
  352. margin-right: #{10rpx};
  353. background: linear-gradient(#d8d8d8, #FFFFFF);
  354. }
  355. }
  356. }
  357. .active {
  358. border-width: #{3rpx};
  359. border-style: solid;
  360. background: #FFFFFF !important;
  361. }
  362. .icon-active {
  363. background-image: url("../../static/image/poster/input-active.png");
  364. height: #{38rpx};
  365. width: #{38rpx};
  366. background-repeat: no-repeat;
  367. background-size: 100% 100%;
  368. position: absolute;
  369. top: #{-19rpx};
  370. right: #{-19rpx};
  371. z-index: 10;
  372. border-radius: 50%;
  373. }
  374. .line-input {
  375. position: relative;
  376. border-radius: #{5rpx};
  377. margin: 0 #{14rpx} #{14rpx};
  378. background: $box;
  379. width: #{140rpx};
  380. height: #{56rpx};
  381. .icon-square {
  382. background-size: 100% 100%;
  383. height: #{32rpx};
  384. width: #{32rpx};
  385. background-repeat: no-repeat;
  386. }
  387. text {
  388. margin-left: #{10rpx};
  389. }
  390. }
  391. .color-bg {
  392. position: relative;
  393. display: inline-block;
  394. height: #{60rpx};
  395. width: #{60rpx};
  396. border-radius: #{5rpx};
  397. border: 1px solid #e5e5e5;
  398. margin-right: #{26rpx};
  399. margin-top: #{19rpx};
  400. }
  401. }
  402. .button {
  403. font-size: #{32rpx};
  404. border-radius: #{40rpx};
  405. height: #{68rpx};
  406. margin: #{34rpx} auto 0;
  407. color: #ffffff;
  408. width: #{500rpx};
  409. }
  410. }
  411. </style>