1
0

goods.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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.stop="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. console.log(this.info.multi_map[index])
  274. let findIndex = this.info.chooseImages.findIndex(item => {
  275. return item == this.info.multi_map[index]
  276. });
  277. console.log(findIndex)
  278. if(findIndex > -1){
  279. if(this.info.chooseImages.length > 1){
  280. this.chooseImages.splice(this.chooseImages.indexOf(index), 1)
  281. this.info.chooseImages.splice(findIndex,1)
  282. }
  283. }else{
  284. if(this.chooseImagesLen == this.info.chooseImages.length){
  285. uni.showToast({title: `最多只能选择${this.chooseImagesLen}张图片`, icon: 'none'});
  286. return true;
  287. }
  288. this.chooseImages.push(index)
  289. this.info.chooseImages.push(this.info.multi_map[index])
  290. }
  291. let length = this.info.chooseImages.length;
  292. this.selectForm.typesetting = this.typesettingList[length-1].value;
  293. this.selectForm.chooseImages = this.chooseImages;
  294. }
  295. },
  296. computed: {
  297. ...mapGetters('mallConfig', {
  298. getTheme: 'getTheme'
  299. })
  300. },
  301. }
  302. </script>
  303. <style scoped lang="scss">
  304. $box: #f7f7f7;
  305. .app-layout /deep/ .app-layout {
  306. overflow-y: auto;
  307. }
  308. ::-webkit-scrollbar {
  309. width: 0;
  310. height: 0;
  311. color: transparent;
  312. }
  313. .app-scroll {
  314. width: 100%;
  315. white-space: nowrap;
  316. padding: 0 #{14rpx};
  317. }
  318. .poster-goods {
  319. height: 100vh;
  320. .head {
  321. height: #{600rpx};
  322. width: 100%;
  323. }
  324. .setting {
  325. padding-top: #{20rpx};
  326. font-size: #{24rpx};
  327. color: #353535;
  328. background: #FFFFFF;
  329. padding-bottom: #{48rpx};
  330. .line {
  331. margin-bottom: #{24rpx};
  332. .label {
  333. height: #{56rpx};
  334. icon {
  335. background-image: url("../../static/image/poster/mark.png");
  336. background-size: 100% 100%;
  337. height: #{21rpx};
  338. width: #{21rpx};
  339. background-repeat: no-repeat;
  340. margin-left: #{24rpx};
  341. border-radius: 50%;
  342. }
  343. text {
  344. line-height: 1;
  345. padding-left: #{12rpx};
  346. padding-right: #{26rpx - 14rpx};
  347. }
  348. }
  349. .style-input {
  350. position: relative;
  351. height: #{56rpx};
  352. width: #{120rpx};
  353. background: $box;
  354. border-radius: #{5rpx};
  355. margin: 0 #{14rpx};
  356. .type-pure {
  357. height: #{32rpx};
  358. width: #{32rpx};
  359. margin-right: #{10rpx};
  360. background: #d8d8d8;
  361. }
  362. .type-gradient {
  363. height: #{32rpx};
  364. width: #{32rpx};
  365. margin-right: #{10rpx};
  366. background: linear-gradient(#d8d8d8, #FFFFFF);
  367. }
  368. }
  369. }
  370. .active {
  371. border-width: #{3rpx};
  372. border-style: solid;
  373. background: #FFFFFF !important;
  374. }
  375. .icon-active {
  376. background-image: url("../../static/image/poster/input-active.png");
  377. height: #{38rpx};
  378. width: #{38rpx};
  379. background-repeat: no-repeat;
  380. background-size: 100% 100%;
  381. position: absolute;
  382. top: #{-19rpx};
  383. right: #{-19rpx};
  384. z-index: 10;
  385. border-radius: 50%;
  386. }
  387. .line-input {
  388. position: relative;
  389. border-radius: #{5rpx};
  390. margin: 0 #{14rpx} #{14rpx};
  391. background: $box;
  392. width: #{140rpx};
  393. height: #{56rpx};
  394. .icon-square {
  395. background-size: 100% 100%;
  396. height: #{32rpx};
  397. width: #{32rpx};
  398. background-repeat: no-repeat;
  399. }
  400. text {
  401. margin-left: #{10rpx};
  402. }
  403. }
  404. .color-bg {
  405. position: relative;
  406. display: inline-block;
  407. height: #{60rpx};
  408. width: #{60rpx};
  409. border-radius: #{5rpx};
  410. border: 1px solid #e5e5e5;
  411. margin-right: #{26rpx};
  412. margin-top: #{19rpx};
  413. }
  414. }
  415. .button {
  416. font-size: #{32rpx};
  417. border-radius: #{40rpx};
  418. height: #{68rpx};
  419. margin: #{34rpx} auto 0;
  420. color: #ffffff;
  421. width: #{500rpx};
  422. }
  423. .choose-images{
  424. flex-direction: column;
  425. align-items: start;
  426. .images-group{
  427. padding: 0 24rpx;
  428. image{
  429. width: 120rpx;
  430. height: 120rpx;
  431. margin-bottom: 20rpx;
  432. margin-right: 20rpx;
  433. filter: grayscale(1);
  434. border: 1px solid #ddd;
  435. &.active{
  436. filter: grayscale(.0);
  437. border: 1px solid #ff0000;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. </style>