goods.vue 20 KB

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