advertising.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <view class="advertising-page">
  3. <view class="cell-group">
  4. <view class="cell" v-if="form.carousel">
  5. <view class="label">轮播图</view>
  6. <view class="cont">
  7. <image class="banner" :src="form.carousel.imgUrl || ''" />
  8. </view>
  9. <view class="setting" @click="handSetting(1)">设置</view>
  10. </view>
  11. <view class="cell" v-if="form.specialFoodOne && form.specialFoodOne.specialFoodId">
  12. <view class="label">特价菜1</view>
  13. <view class="cont">
  14. <image class="cover" :src="form.specialFoodOne.pictureUrl" />
  15. <view class="name">{{form.specialFoodOne.goodsName || ''}}</view>
  16. <view class="price" v-if="form.specialFoodOne.costPrice">¥{{moneyConverter(form.specialFoodOne.costPrice)}}</view>
  17. <!-- <view class="price">¥{{moneyConverter(form.specialFoodOne.costPrice)}}</view> -->
  18. </view>
  19. <view class="setting" @click="handSetting(2)">设置</view>
  20. </view>
  21. <view class="cell" v-if="form.specialFoodTwo && form.specialFoodTwo.specialFoodId">
  22. <view class="label">特价菜2</view>
  23. <view class="cont">
  24. <image class="cover" :src="form.specialFoodTwo.pictureUrl" />
  25. <view class="name">{{form.specialFoodTwo.goodsName || ''}}</view>
  26. <view class="price" v-if="form.specialFoodTwo.costPrice">¥{{moneyConverter(form.specialFoodTwo.costPrice)}}</view>
  27. <!-- <view class="price">¥{{moneyConverter(form.specialFoodTwo.costPrice)}}</view> -->
  28. </view>
  29. <view class="setting" @click="handSetting(3)">设置</view>
  30. </view>
  31. <view class="cell dubble" v-if="form.indexStore != null ">
  32. <view class="label">优选店铺</view>
  33. <view class="cont cont-dubble">
  34. <view class="row">
  35. <image class="cover" :src="form.goodsList[0].pictureUrl" />
  36. <view class="name">{{form.goodsList[0].goodsName || ''}}</view>
  37. <!-- <view class="price">¥{{moneyConverter(form.goodsList[0].costPrice)}}</view> -->
  38. <view class="price" v-if="form.goodsList[0] && form.goodsList[0].costPrice">¥{{ moneyConverter(form.goodsList[0].costPrice)}}</view>
  39. </view>
  40. <view class="row">
  41. <image class="cover" :src="form.goodsList[1].pictureUrl" />
  42. <view class="name">{{form.goodsList[1].goodsName || ''}}</view>
  43. <view class="price" v-if="form.goodsList[1] && form.goodsList[1].costPrice">¥{{ moneyConverter(form.goodsList[1].costPrice)}}</view>
  44. </view>
  45. </view>
  46. <view class="setting" @click="handSetting(4)">设置</view>
  47. </view>
  48. </view>
  49. <u-modal
  50. :show="visible"
  51. title="轮播店铺图选择"
  52. closeOnClickOverlay
  53. showCancelButton
  54. @confirm="confirm"
  55. @cancel="visible = false"
  56. @close="visible = false">
  57. <view class="container">
  58. <view class="item">
  59. <view class="label">轮播图片</view>
  60. <u-upload
  61. :fileList="fileList"
  62. @afterRead="afterRead"
  63. @delete="deletePic"
  64. name="1"
  65. :previewFullImage="true"
  66. :maxCount="1"
  67. ></u-upload>
  68. </view>
  69. </view>
  70. </u-modal>
  71. <u-popup
  72. mode="right"
  73. closeable
  74. :zIndex="99"
  75. :overlay="false"
  76. :customStyle="{ width: '100vw', height: '100vh' }"
  77. :show="popupVisible"
  78. @close="popupClose"
  79. @open="popupOpen">
  80. <view class="popup-container" v-if="active == 2">
  81. <view class="title">特价菜品选择</view>
  82. <view class="item">
  83. <view class="label" v-if="!form.specialFoodOne.goodsId">选择商品</view>
  84. <view class="label" v-else>{{form.specialFoodOne.goodsName}}</view>
  85. <view class="value" @click="chooseGoods">
  86. <view class="name"></view>
  87. <u-icon name="arrow-right" size="18" color="#6c6c6c"></u-icon>
  88. </view>
  89. </view>
  90. <view class="item">
  91. <view class="label">商品图片</view>
  92. <view class="value">
  93. <image class="cover" :src="form.specialFoodOne.pictureUrl"></image>
  94. </view>
  95. </view>
  96. </view>
  97. <view class="popup-container" v-if="active == 3">
  98. <view class="title">特价菜品选择</view>
  99. <view class="item">
  100. <view class="label" v-if="!form.specialFoodTwo.goodsId">选择商品</view>
  101. <view class="label" v-else>{{form.specialFoodTwo.goodsName}}</view>
  102. <view class="value" @click="chooseGoods">
  103. <view class="name"></view>
  104. <u-icon name="arrow-right" size="18" color="#6c6c6c"></u-icon>
  105. </view>
  106. </view>
  107. <view class="item">
  108. <view class="label">商品图片</view>
  109. <view class="value">
  110. <image class="cover" :src="form.specialFoodTwo.pictureUrl"></image>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="popup-container" v-if="active == 4">
  115. <view class="title">优选店铺商品选择</view>
  116. <view class="item">
  117. <!-- <view class="label">选择商品</view> -->
  118. <view class="label" v-if="!form.goodsList[0].goodsId">选择商品</view>
  119. <view class="label" v-else>{{form.goodsList[0].goodsName}}</view>
  120. <view class="value" @click="chooseIndexGoods(1)">
  121. <view class="name"></view>
  122. <u-icon name="arrow-right" size="18" color="#6c6c6c"></u-icon>
  123. </view>
  124. </view>
  125. <view class="item">
  126. <view class="label">商品1图片</view>
  127. <view class="value">
  128. <image class="cover" :src="form.goodsList[0].pictureUrl"></image>
  129. </view>
  130. </view>
  131. <view class="item">
  132. <view class="label" v-if="!form.goodsList[1].goodsId">选择商品</view>
  133. <view class="label" v-else>{{form.goodsList[1].goodsName}}</view>
  134. <view class="value" @click="chooseIndexGoods(2)">
  135. <view class="name"></view>
  136. <u-icon name="arrow-right" size="18" color="#6c6c6c"></u-icon>
  137. </view>
  138. </view>
  139. <view class="item">
  140. <view class="label">商品2图片</view>
  141. <view class="value">
  142. <image class="cover" :src="form.goodsList[1].pictureUrl"></image>
  143. </view>
  144. </view>
  145. </view>
  146. </u-popup>
  147. <u-popup
  148. mode="bottom"
  149. :zIndex="10076"
  150. :show="popupGoodsVisible"
  151. @close="popupGoodsClose"
  152. @open="popupGoodsOpen">
  153. <view class="modal-container">
  154. <view class="search-wrap">
  155. <view class="input-wrap">
  156. <u-input border="none" fontSize="14" v-model="searchValue" placeholder="商品名称"></u-input>
  157. </view>
  158. <view class="btn" @click="getGoods()">搜索</view>
  159. </view>
  160. <scroll-view scroll-y class="goods-list">
  161. <view class="item" v-for="item in goodsList" :key="item.goodsId" @click="handItem(item)">
  162. <view class="cover">
  163. <image class="img" :src="item.pictureUrl"/>
  164. </view>
  165. <view class="cont">
  166. <view class="goods-name">
  167. {{item.goodsName}}
  168. </view>
  169. <view class="desc">
  170. 库存: {{item.maxNum}}, 价格: ¥{{item.costPrice ? moneyConverter(item.costPrice) : ''}}
  171. </view>
  172. </view>
  173. </view>
  174. </scroll-view>
  175. </view>
  176. </u-popup>
  177. </view>
  178. </template>
  179. <script>
  180. import { mapState } from 'vuex';
  181. export default {
  182. data () {
  183. return {
  184. infoUrl: '/storeAdvertisingManageApi/getAdvertisingInfo',
  185. uploadUrl: '/storeAdvertisingManageApi/upload',
  186. specialUrl: '/storeAdvertisingManageApi/getSpecialGoodsListByStoreIdForStore',
  187. updateSpecialUrl: '/storeAdvertisingManageApi/chooseFood',
  188. updateStoreUrl: '/storeAdvertisingManageApi/chooseIndexStoreGoods',
  189. getAllGoodslUrl: '/storeAdvertisingManageApi/getAllGoodsListByStoreIdForStore',
  190. popupGoodsVisible: false,
  191. popupVisible: false,
  192. bannerCount: 1,
  193. visible: false,
  194. modalTitle: '',
  195. active: 1,
  196. form: {},
  197. fileList: [],
  198. goodsList: [],
  199. indexV: 0,
  200. searchValue: '',
  201. imgUrl: ''
  202. }
  203. },
  204. computed: {
  205. ...mapState(['storeInfo'])
  206. },
  207. methods: {
  208. loadData () {
  209. uni.showLoading({
  210. title: '加载中'
  211. });
  212. var dateStr = (new Date()).getTime();
  213. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  214. this.requst({
  215. url: this.infoUrl,
  216. data: {
  217. timestamp: dateStr,
  218. sign: sign,
  219. storeId: this.storeInfo.storeId,
  220. storeUserId: this.storeInfo.storeUserId
  221. },
  222. success: res => {
  223. if (res.data.rtnBean.rtnCode == 0) {
  224. this.form = res.data.obj;
  225. if (this.form && this.form.carousel && this.form.imgUrl){
  226. let picUrl = this.form.carousel.imgUrl;
  227. this.fileList.push({
  228. url: picUrl
  229. })
  230. }
  231. uni.stopPullDownRefresh()
  232. uni.hideLoading()
  233. }
  234. },
  235. fail: (e) => {
  236. console.log("接口调用失败:" + JSON.stringify(e));
  237. uni.hideLoading()
  238. }
  239. })
  240. },
  241. getGoods () {
  242. if(this.active == 2 || this.active == 3){
  243. this.getGoodsList(this.searchValue)
  244. } else if (this.active == 4) {
  245. this.getAllGoodsList(this.searchValue)
  246. }
  247. },
  248. getGoodsList(name) {
  249. uni.showLoading({
  250. title: '加载中'
  251. });
  252. var dateStr = (new Date()).getTime();
  253. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  254. this.requst({
  255. url: this.specialUrl,
  256. data: {
  257. timestamp: dateStr,
  258. sign: sign,
  259. storeId: this.storeInfo.storeId,
  260. storeUserId: this.storeInfo.storeUserId,
  261. goodsName: name || ''
  262. },
  263. success: res => {
  264. this.goodsList = res.data.list;
  265. uni.hideLoading();
  266. },
  267. fail: (e) => {
  268. console.log("接口调用失败:" + JSON.stringify(e));
  269. uni.hideLoading();
  270. },
  271. })
  272. },
  273. getAllGoodsList(name) {
  274. uni.showLoading({
  275. title: '加载中'
  276. });
  277. var dateStr = (new Date()).getTime();
  278. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  279. this.requst({
  280. url: this.getAllGoodslUrl,
  281. data: {
  282. timestamp: dateStr,
  283. sign: sign,
  284. storeId: this.storeInfo.storeId,
  285. storeUserId: this.storeInfo.storeUserId,
  286. goodsName: name || ''
  287. },
  288. success: res => {
  289. this.goodsList = res.data.list;
  290. uni.hideLoading();
  291. },
  292. fail: (e) => {
  293. console.log("接口调用失败:" + JSON.stringify(e));
  294. uni.hideLoading();
  295. },
  296. })
  297. },
  298. // 删除图片
  299. deletePic(event) {
  300. this.fileList.splice(event.index, 1)
  301. this.imgUrl = ''
  302. },
  303. // 新增图片
  304. async afterRead(event) {
  305. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  306. let file = event.file
  307. let fileListLen = this.fileList.length
  308. // lists.map((item) => {
  309. this.fileList.push({
  310. ...file,
  311. status: 'success',
  312. // message: '上传中'
  313. })
  314. this.imgUrl = file.url
  315. },
  316. handSetting (v) {
  317. this.active = v
  318. if (v == 1) {
  319. this.visible = true
  320. }
  321. else {
  322. this.popupVisible = true
  323. }
  324. },
  325. addBanner (e) {
  326. },
  327. removeBanner (e) {
  328. },
  329. confirm (e) {
  330. uni.showLoading({
  331. title: '保存中'
  332. });
  333. var dateStr = (new Date()).getTime();
  334. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  335. return new Promise((resolve, reject) => {
  336. let a = uni.uploadFile({
  337. url: this.storeInfo.code + this.uploadUrl,
  338. filePath: this.imgUrl,
  339. name: 'file',
  340. formData: {
  341. timestamp: dateStr,
  342. sign: sign,
  343. storeId: this.storeInfo.storeId,
  344. storeUserId: this.storeInfo.storeUserId,
  345. carouselId: this.form.carousel.carouselId
  346. },
  347. success: (res) => {
  348. let data = JSON.parse(res.data)
  349. if (data.rtnBean.rtnCode == 0) {
  350. uni.hideLoading();
  351. uni.showToast({
  352. title: "提交成功",
  353. duration: 3000,
  354. icon: 'none',
  355. });
  356. this.loadData()
  357. this.visible = false
  358. } else {
  359. uni.hideLoading();
  360. if (data.rtnBean.rtnMsg != '') {
  361. this.$api.msg(data.rtnBean.rtnMsg);
  362. }
  363. }
  364. },
  365. fail: (res) => {
  366. uni.hideLoading();
  367. }
  368. });
  369. })
  370. },
  371. popupClose () {
  372. this.popupVisible = false
  373. this.loadData()
  374. },
  375. popupOpen () {
  376. },
  377. popupGoodsClose () {
  378. this.popupGoodsVisible = false
  379. this.searchValue = ''
  380. },
  381. popupGoodsOpen () {
  382. if (this.active == 2 || this.active == 3){
  383. this.getGoodsList()
  384. }
  385. if (this.active == 4) {
  386. this.getAllGoodsList()
  387. }
  388. },
  389. chooseGoods () {
  390. this.popupGoodsVisible = true
  391. },
  392. chooseIndexGoods (index) {
  393. this.indexV = index
  394. this.popupGoodsVisible = true
  395. },
  396. handItem (item) {
  397. // 特价菜一
  398. if(this.active == 2) {
  399. this.updateSpecial(item.goodsId,this.form.specialFoodOne.specialFoodId);
  400. this.form.specialFoodOne.goodsName = item.goodsName;
  401. this.form.specialFoodOne.pictureUrl = item.pictureUrl;
  402. this.form.specialFoodOne.goodsId = item.goodsId;
  403. }
  404. // 特价菜二
  405. if (this.active == 3) {
  406. this.updateSpecial(item.goodsId,this.form.specialFoodTwo.specialFoodId);
  407. this.form.specialFoodTwo.goodsName = item.goodsName;
  408. this.form.specialFoodTwo.pictureUrl = item.pictureUrl;
  409. this.form.specialFoodTwo.goodsId = item.goodsId;
  410. }
  411. // 优选店铺
  412. if (this.active == 4) {
  413. if (this.indexV == 1){
  414. if(this.form.goodsList[0]) {
  415. this.form.goodsList[0].goodsName = item.goodsName;
  416. this.form.goodsList[0].pictureUrl = item.pictureUrl;
  417. this.form.goodsList[0].goodsId = item.goodsId;
  418. } else {
  419. this.form.goodsList.push({
  420. goodsName: item.goodsName,
  421. pictureUrl: item.pictureUrl,
  422. goodsId: item.goodsId
  423. })
  424. }
  425. }
  426. if (this.indexV == 2) {
  427. if(this.form.goodsList[1]) {
  428. this.form.goodsList[1].goodsName = item.goodsName;
  429. this.form.goodsList[1].pictureUrl = item.pictureUrl;
  430. this.form.goodsList[1].goodsId = item.goodsId;
  431. } else {
  432. this.form.goodsList.push({
  433. goodsName: item.goodsName,
  434. pictureUrl: item.pictureUrl,
  435. goodsId: item.goodsId
  436. })
  437. }
  438. }
  439. this.updateStore(item.goodsId);
  440. }
  441. this.popupGoodsVisible = false
  442. },
  443. updateSpecial (goodsId,sepicalFoodId) {
  444. var dateStr = (new Date()).getTime();
  445. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  446. this.requst({
  447. url: this.updateSpecialUrl,
  448. data: {
  449. timestamp: dateStr,
  450. sign: sign,
  451. storeId: this.storeInfo.storeId,
  452. storeUserId: this.storeInfo.storeUserId,
  453. goodsId: goodsId,
  454. id: sepicalFoodId
  455. },
  456. success: res => {
  457. },
  458. fail: (e) => {
  459. console.log("接口调用失败:" + JSON.stringify(e));
  460. },
  461. })
  462. },
  463. updateStore (goodsId) {
  464. let id = ''
  465. if (this.indexV == 1) {
  466. if (this.form.goodsList[0]) {
  467. id = this.form.goodsList[0].indexStoreGoodsId || ''
  468. }
  469. }
  470. if (this.indexV == 2) {
  471. if (this.form.goodsList[1]) {
  472. id = this.form.goodsList[1].indexStoreGoodsId || ''
  473. }
  474. }
  475. var dateStr = (new Date()).getTime();
  476. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  477. this.requst({
  478. url: this.updateStoreUrl,
  479. data: {
  480. timestamp: dateStr,
  481. sign: sign,
  482. storeId: this.storeInfo.storeId,
  483. storeUserId: this.storeInfo.storeUserId,
  484. goodsId: goodsId,
  485. indexStoreGoodsId: id
  486. },
  487. success: res => {
  488. },
  489. fail: (e) => {
  490. console.log("接口调用失败:" + JSON.stringify(e));
  491. },
  492. })
  493. },
  494. onPullDownRefresh() {
  495. this.loadData();
  496. }
  497. },
  498. onLoad () {
  499. this.loadData();
  500. }
  501. }
  502. </script>
  503. <style lang="scss" scoped>
  504. .advertising-page {
  505. width: 100vw;
  506. min-height: 100vh;
  507. background-color: #f5f5f5;
  508. }
  509. .cell-group {
  510. border-top: 2rpx solid #f5f5f5;
  511. .cell {
  512. width: 100%;
  513. margin: 10rpx 0;
  514. background-color: #fff;
  515. height: 180rpx;
  516. @include flexStart;
  517. padding: 0 20rpx;
  518. box-sizing: border-box;
  519. font-size: $font-base;
  520. }
  521. .label {
  522. width: 160rpx;
  523. color: $text-color;
  524. }
  525. .cont {
  526. @include between;
  527. width: calc(100% - 160rpx - 160rpx);
  528. }
  529. .dubble {
  530. height: 360rpx;
  531. }
  532. .banner {
  533. width: 328rpx;
  534. height: 128rpx;
  535. }
  536. .cover {
  537. width: 128rpx;
  538. height: 128rpx;
  539. }
  540. .cont-dubble {
  541. display: flex;
  542. flex-direction: column;
  543. align-items: flex-start;
  544. justify-content: center;
  545. }
  546. .row {
  547. width: 100%;
  548. @include between;
  549. }
  550. .row:first-child {
  551. margin-bottom: 20rpx;
  552. }
  553. .setting {
  554. width: 100rpx;
  555. margin-left: 60rpx;
  556. padding: 6rpx 0;
  557. background-color: $theme-color;
  558. color: #fff;
  559. @include flexCenter;
  560. border-radius: 10rpx;
  561. }
  562. .name, .price {
  563. color: $title-color;
  564. }
  565. }
  566. .container {
  567. .item {
  568. @include flexCenter;
  569. .label {
  570. margin-right: 40rpx;
  571. }
  572. }
  573. }
  574. .popup-container {
  575. text-align: center;
  576. font-weight: bold;
  577. padding-top: 30rpx;
  578. .title {
  579. margin-bottom: 40rpx;
  580. }
  581. .item {
  582. @include between;
  583. padding: 20rpx;
  584. box-sizing: border-box;
  585. border-bottom: 2rpx solid #ececec;
  586. .label {
  587. margin-right: 40rpx;
  588. }
  589. .cover {
  590. width: 120rpx;
  591. height: 120rpx;
  592. }
  593. .value {
  594. flex: 1;
  595. @include flexEnd;
  596. }
  597. }
  598. }
  599. .modal-container {
  600. padding: 40rpx 40rpx 0;
  601. box-sizing: border-box;
  602. .search-wrap {
  603. width: 100%;
  604. @include flexCenter;
  605. border: 2rpx solid $theme-color;
  606. color: $theme-color;
  607. font-size: $font-base;
  608. padding-left: 20rpx;
  609. box-sizing: border-box;
  610. margin-bottom: 20rpx;
  611. .btn {
  612. width: 128rpx;
  613. height: 60rpx;
  614. @include flexCenter;
  615. border-left: 2rpx solid $theme-color;
  616. }
  617. .input-wrap {
  618. flex: 1;
  619. /deep/ .u-input {
  620. width: 100%;
  621. }
  622. }
  623. }
  624. .goods-list {
  625. height: 50vh;
  626. margin-top: 20rpx;
  627. .item {
  628. margin-bottom: 20rpx;
  629. @include flexStart;
  630. }
  631. .cover {
  632. width: 120rpx;
  633. height: 120rpx;
  634. border-radius: 10rpx;
  635. margin-right: 20rpx;
  636. .img {
  637. width: 120rpx;
  638. height: 120rpx;
  639. }
  640. }
  641. .cont {
  642. font-size: $font-base;
  643. .goods-name {
  644. width: 100%;
  645. text-overflow: -o-ellipsis-lastline;
  646. overflow: hidden;
  647. text-overflow: ellipsis;
  648. display: -webkit-box;
  649. -webkit-line-clamp: 2;
  650. -webkit-box-orient: vertical;
  651. color: $text-color;
  652. }
  653. .desc {
  654. color: $desc-color;
  655. }
  656. }
  657. }
  658. }
  659. </style>