goods.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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. <block v-if="selectForm.style == styleList[0].value">
  7. <app-goods-poster-one :info="info" :form="selectForm"
  8. :multiple="multiple"></app-goods-poster-one>
  9. </block>
  10. <block v-if="selectForm.style == styleList[1].value">
  11. <app-goods-poster-two :info="info" :form="selectForm"
  12. :multiple="multiple"></app-goods-poster-two>
  13. </block>
  14. <block v-if="selectForm.style == styleList[2].value">
  15. <app-goods-poster-three :info="info" :form="selectForm"
  16. :multiple="multiple"></app-goods-poster-three>
  17. </block>
  18. <block v-if="selectForm.style == styleList[3].value">
  19. <app-goods-poster-four :info="info" :form="selectForm"
  20. :multiple="multiple"></app-goods-poster-four>
  21. </block>
  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 :class="getTheme + '-m-back ' + getTheme"></icon>
  27. <text>样式</text>
  28. </view>
  29. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  30. <view v-for="(item,key) in styleList" :key="key"
  31. @click="changeStyle(item.value)"
  32. v-if="config.poster_style.indexOf(item.value.toString()) !== -1"
  33. :class="item.value == selectForm.style ? 'active ' + getTheme + '-m-border ' + getTheme : ''"
  34. class="style-input main-center cross-center"
  35. >
  36. <text>{{item.label}}</text>
  37. <icon
  38. v-if="item.value == selectForm.style"
  39. :class="getTheme + '-m-back icon-active ' + getTheme"></icon>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="dir-left-nowrap line choose-images" v-if="isChooseImages">
  44. <view class="box-grow-0 main-center cross-center label">
  45. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  46. <text>选择图片(最多{{chooseImagesLen}}张)</text>
  47. </view>
  48. <view class="dir-left-wrap box-grow-1 images-group">
  49. <image v-for="(item,key) in info.multi_map" :key="key"
  50. mode="aspectFill"
  51. :src="item" @click="selectImages(key)"
  52. :class="chooseImages.indexOf(key)!=-1?'active '+ getTheme + '-m-border':''">
  53. </image>
  54. </view>
  55. </view>
  56. <view class="dir-left-nowrap line" v-else>
  57. <view class="box-grow-0 main-center cross-center label">
  58. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  59. <text>排版</text>
  60. </view>
  61. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  62. <view v-for="(item,key) in typesettingList" :key="key"
  63. @click="changeTypeSetting(item.value)"
  64. v-if="config.image_style.indexOf(item.value.toString()) !== -1"
  65. :class="item.value == selectForm.typesetting ? 'active ' + getTheme + '-m-border ' + getTheme : ''"
  66. class="line-input dir-left-nowrap main-center cross-center"
  67. >
  68. <img :src="item.pic_url" class="icon-square"
  69. :style="{'background-image': `url(${item.pic_url})`}"></img>
  70. <text>{{item.label}}</text>
  71. <icon v-if="item.value == selectForm.typesetting"
  72. :class="getTheme + '-m-back icon-active ' + getTheme"></icon>
  73. </view>
  74. </view>
  75. </view>
  76. <view class="dir-left-nowrap line" style="margin-bottom:5rpx">
  77. <view class="box-grow-0 main-center cross-center label">
  78. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  79. <text>类型</text>
  80. </view>
  81. <view class="dir-left-wrap box-grow-1" :class="getTheme">
  82. <view v-for="(item,key) in typeList" :key="key"
  83. @click="changeType(item.value)"
  84. :class="item.value == selectForm.type ? 'active ' + getTheme + '-m-border ' + getTheme : ''"
  85. class="style-input dir-left-nowrap main-center cross-center"
  86. >
  87. <view v-if="item.value === 1" class="type-pure"></view>
  88. <view v-if="item.value === 2" class="type-gradient"></view>
  89. <text>{{item.label}}</text>
  90. <icon v-if="item.value == selectForm.type"
  91. :class="getTheme + '-m-back icon-active ' + getTheme"></icon>
  92. </view>
  93. </view>
  94. </view>
  95. <view class="dir-left-nowrap line">
  96. <view class="box-grow-0 main-center cross-center label" style="margin-top: 19rpx">
  97. <icon :class="getTheme + '-m-back ' + getTheme"></icon>
  98. <text>颜色</text>
  99. </view>
  100. <view class="dir-left-wrap box-grow-1">
  101. <scroll-view scroll-x class="app-scroll" enable-flex="true">
  102. <view v-for="(color,key) in config.color" :key="key"
  103. @click="changeColor(color)"
  104. class="color-bg"
  105. :style="{'background': `${color}`}">
  106. <icon v-if="color == selectForm.color"
  107. :class="getTheme + '-m-back icon-active ' + getTheme"></icon>
  108. </view>
  109. </scroll-view>
  110. </view>
  111. </view>
  112. <view @click="submitSave" :class="getTheme + '-m-back button main-center cross-center ' + getTheme">保存图片
  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: {},
  175. posterConfig: '',
  176. posterGenerate: '',
  177. chooseImages: [],
  178. isChooseImages: true, // 是否选择图片
  179. chooseImagesLen: 5, // 最多能选择几张
  180. }
  181. },
  182. onLoad(options) {
  183. let { poster_config, poster_generate } = options;
  184. if (poster_config && poster_generate) {
  185. this.posterConfig = unescape(poster_config);
  186. this.posterGenerate = unescape(poster_generate);
  187. } else {
  188. return;
  189. }
  190. this.loadData();
  191. },
  192. methods: {
  193. calcMultiple() {
  194. let query = null;
  195. // #ifdef MP-ALIPAY
  196. query = uni.createSelectorQuery();
  197. // #endif
  198. // #ifndef MP-ALIPAY
  199. query = uni.createSelectorQuery().in(this);
  200. // #endif
  201. query.select('#head').boundingClientRect(item => {
  202. // #ifndef MP-TOUTIAO || MP-ALIPAY
  203. this.multiple = (item.height * (750 / uni.getSystemInfoSync().screenWidth) - 24 - 24) / 1334;
  204. // #endif
  205. // #ifdef MP-TOUTIAO || MP-ALIPAY
  206. this.multiple = 0.455;
  207. // #endif
  208. }).exec();
  209. },
  210. loadData() {
  211. this.$request({
  212. url: this.posterConfig,
  213. }).then(info => {
  214. this.$hideLoading();
  215. this.loadShow = true;
  216. let { code, data, msg } = info;
  217. if (code === 0) {
  218. this.config = data.config;
  219. this.info = data.info;
  220. this.info.chooseImages = [];
  221. if(this.info.multi_map){
  222. this.info.chooseImages.push(this.info.multi_map[0]);
  223. this.chooseImages.push(0);
  224. }
  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. this.$utils.batchSave(pic_url, 'image').then(() => {
  263. uni.showToast({title: '保存成功'});
  264. });
  265. } else {
  266. uni.showToast({title: msg, icon: 'none'});
  267. }
  268. }).catch(() => {
  269. this.$hideLoading();
  270. })
  271. },
  272. selectImages(index){
  273. let findIndex = this.info.chooseImages.findIndex(item => {
  274. return item == this.info.multi_map[index]
  275. });
  276. if(findIndex != -1){
  277. if(this.info.chooseImages.length > 1){
  278. this.chooseImages.splice(this.chooseImages.indexOf(index), 1)
  279. this.info.chooseImages.splice(findIndex,1)
  280. }
  281. }else{
  282. if(this.chooseImagesLen == this.info.chooseImages.length){
  283. uni.showToast({title: `最多只能选择${this.chooseImagesLen}张图片`, icon: 'none'});
  284. return true;
  285. }
  286. this.chooseImages.push(index)
  287. this.info.chooseImages.push(this.info.multi_map[index])
  288. }
  289. let length = this.info.chooseImages.length;
  290. this.selectForm.typesetting = this.typesettingList[length-1].value;
  291. this.selectForm.chooseImages = this.chooseImages;
  292. }
  293. },
  294. computed: {
  295. ...mapGetters('mallConfig', {
  296. getTheme: 'getTheme'
  297. })
  298. },
  299. }
  300. </script>
  301. <style scoped lang="scss">
  302. $box: #f7f7f7;
  303. .app-layout /deep/ .app-layout {
  304. overflow-y: auto;
  305. }
  306. ::-webkit-scrollbar {
  307. width: 0;
  308. height: 0;
  309. color: transparent;
  310. }
  311. .app-scroll {
  312. width: 100%;
  313. white-space: nowrap;
  314. padding: 0 #{14rpx};
  315. }
  316. .poster-goods {
  317. height: 100vh;
  318. .head {
  319. height: #{600rpx};
  320. width: 100%;
  321. }
  322. .setting {
  323. padding-top: #{20rpx};
  324. font-size: #{24rpx};
  325. color: #353535;
  326. background: #FFFFFF;
  327. padding-bottom: #{48rpx};
  328. .line {
  329. margin-bottom: #{24rpx};
  330. .label {
  331. height: #{56rpx};
  332. icon {
  333. background-image: url("../../static/image/poster/mark.png");
  334. background-size: 100% 100%;
  335. height: #{21rpx};
  336. width: #{21rpx};
  337. background-repeat: no-repeat;
  338. margin-left: #{24rpx};
  339. border-radius: 50%;
  340. }
  341. text {
  342. line-height: 1;
  343. padding-left: #{12rpx};
  344. padding-right: #{26rpx - 14rpx};
  345. }
  346. }
  347. .style-input {
  348. position: relative;
  349. height: #{56rpx};
  350. width: #{120rpx};
  351. background: $box;
  352. border-radius: #{5rpx};
  353. margin: 0 #{14rpx};
  354. .type-pure {
  355. height: #{32rpx};
  356. width: #{32rpx};
  357. margin-right: #{10rpx};
  358. background: #d8d8d8;
  359. }
  360. .type-gradient {
  361. height: #{32rpx};
  362. width: #{32rpx};
  363. margin-right: #{10rpx};
  364. background: linear-gradient(#d8d8d8, #FFFFFF);
  365. }
  366. }
  367. }
  368. .active {
  369. border-width: #{3rpx};
  370. border-style: solid;
  371. background: #FFFFFF !important;
  372. }
  373. .icon-active {
  374. background-image: url("../../static/image/poster/input-active.png");
  375. height: #{38rpx};
  376. width: #{38rpx};
  377. background-repeat: no-repeat;
  378. background-size: 100% 100%;
  379. position: absolute;
  380. top: #{-19rpx};
  381. right: #{-19rpx};
  382. z-index: 10;
  383. border-radius: 50%;
  384. }
  385. .line-input {
  386. position: relative;
  387. border-radius: #{5rpx};
  388. margin: 0 #{14rpx} #{14rpx};
  389. background: $box;
  390. width: #{140rpx};
  391. height: #{56rpx};
  392. .icon-square {
  393. background-size: 100% 100%;
  394. height: #{32rpx};
  395. width: #{32rpx};
  396. background-repeat: no-repeat;
  397. }
  398. text {
  399. margin-left: #{10rpx};
  400. }
  401. }
  402. .color-bg {
  403. position: relative;
  404. display: inline-block;
  405. height: #{60rpx};
  406. width: #{60rpx};
  407. border-radius: #{5rpx};
  408. border: 1px solid #e5e5e5;
  409. margin-right: #{26rpx};
  410. margin-top: #{19rpx};
  411. }
  412. }
  413. .button {
  414. font-size: #{32rpx};
  415. border-radius: #{40rpx};
  416. height: #{68rpx};
  417. margin: #{34rpx} auto 0;
  418. color: #ffffff;
  419. width: #{500rpx};
  420. }
  421. .choose-images{
  422. flex-direction: column;
  423. align-items: start;
  424. .images-group{
  425. padding: 0 24rpx;
  426. image{
  427. width: 120rpx;
  428. height: 120rpx;
  429. margin-bottom: 20rpx;
  430. margin-right: 20rpx;
  431. filter: grayscale(1);
  432. border: 1px solid #ddd;
  433. &.active{
  434. filter: grayscale(.0);
  435. border: 1px solid #ff0000;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. </style>