special-item-edit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <template>
  2. <view class="special-item-edit-page">
  3. <scroll-view scroll-y class="scroll-content">
  4. <view class="cell-wrap">
  5. <view class="item">
  6. <view class="label">活动主题</view>
  7. <view class="value">
  8. <input border="none" inputAlign="right" maxlength="15" fontSize="14" v-model="form.activityName" placeholder="请填写"></input>
  9. </view>
  10. </view>
  11. <view class="item">
  12. <view class="label">活动描述</view>
  13. <view class="value">
  14. <input border="none" inputAlign="right" maxlength="15" fontSize="14" v-model="form.activityComment" placeholder="请填写"></input>
  15. </view>
  16. </view>
  17. <view class="item">
  18. <view class="label">活动时间</view>
  19. <view class="value" @click="selectDate">
  20. {{ form.startDate }} ~ {{ form.endDate }}
  21. </view>
  22. </view>
  23. </view>
  24. <view class="activities-title">
  25. 参与的活动(不支持多规格商品)
  26. </view>
  27. <view class="goods-list">
  28. <uni-swipe-action>
  29. <uni-swipe-action-item :right-options="addFlag ? options : options1" :index="index" v-for="(item, index) in goodsList"
  30. @click="deleteGoods(index,item)" :key="item.goodsId">
  31. <view class="goods">
  32. <view class="cover">
  33. <image class="img" :src="item.pictureUrl"/>
  34. </view>
  35. <view class="cont">
  36. <view class="name">{{item.goodsName}}</view>
  37. <view class="tools">
  38. <view class="price">¥{{moneyConverter(item.activityPrice)}}</view>
  39. <view class="origin-price">¥{{moneyConverter(item.costPrice)}}</view>
  40. </view>
  41. <view class="desc between">
  42. <view class="desc">每单限购{{item.maxNum}}份,活动库存{{item.activityNum}}份</view>
  43. <u-icon name="edit-pen" size="28" color="#6c6c6c" @click="handEditGoods(item, index)"></u-icon>
  44. </view>
  45. </view>
  46. </view>
  47. </uni-swipe-action-item>
  48. </uni-swipe-action>
  49. <view class="add-goods" v-if="addFlag" @click="handAddGoods">添加商品</view>
  50. </view>
  51. </scroll-view>
  52. <u-modal
  53. :show="updateStatusVisible"
  54. title="注意"
  55. closeOnClickOverlay
  56. showCancelButton
  57. @confirm="pushGoods"
  58. @close="updateStatusVisible = false"
  59. @cancel="updateStatusVisible = false">
  60. <view class="container">
  61. 活动中的商品如果参加首页推荐,活动状态改变后将会在首页、店铺同步下架,您是否确定改变?
  62. </view>
  63. </u-modal>
  64. <uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :insert="false" :range="true" @confirm="confirm" />
  65. <view class="update-events">
  66. <view class="btn" @click="save">保存</view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {mapState} from 'vuex';
  72. import { computed } from "vue";
  73. export default {
  74. data () {
  75. return {
  76. getStoreSpecialActivityByIdUrl: '/storeSpecialActivityApi/getStoreSpecialActivityByIdForStore',
  77. saveStoreSpecialActivityUrl: '/storeSpecialActivityApi/saveStoreSpecialActivityForStore',
  78. updateStatusVisible: false,
  79. form: {
  80. storeSpecialActivityId: '',
  81. activityName: '',
  82. activityComment: '',
  83. startDate: '',
  84. endDate: '',
  85. status: ''
  86. },
  87. goodsList: [],
  88. options: [
  89. {
  90. text: '删除',
  91. style: {
  92. fontSize: '28rpx',
  93. backgroundColor: '#FF0000',
  94. marginBottom: '20rpx'
  95. }
  96. }
  97. ],
  98. options1:[],
  99. addFlag: true
  100. }
  101. },
  102. computed: {
  103. ...mapState(['storeInfo'])
  104. },
  105. methods: {
  106. loadData() {
  107. uni.showLoading({
  108. title: '加载中'
  109. });
  110. var dateStr = (new Date()).getTime();
  111. var sign = this.getSign('' + this.storeInfo.storeId + dateStr);
  112. this.requst({
  113. url: this.getStoreSpecialActivityByIdUrl,
  114. data: {
  115. timestamp: dateStr,
  116. sign: sign,
  117. storeId: this.storeInfo.storeId,
  118. id: this.form.storeSpecialActivityId
  119. },
  120. success: res => {
  121. this.form = res.data.obj;
  122. this.goodsList = res.data.list;
  123. uni.hideLoading();
  124. },
  125. fail: (e) => {
  126. console.log("接口调用失败:" + JSON.stringify(e));
  127. uni.hideLoading();
  128. },
  129. })
  130. },
  131. pushGoods() {
  132. this.updateStatusVisible = false
  133. },
  134. handEditGoods (goods, index) {
  135. const params = encodeURIComponent(JSON.stringify(goods));
  136. uni.navigateTo({
  137. url: `/pages/activity/add-goods?goods=${params}&index=${index}`
  138. })
  139. },
  140. handAddGoods() {
  141. if (this.goodsList.length > 0) {
  142. const ids = this.goodsList.map(item => item.goodsId);
  143. const idsStr = ids.join(',');
  144. const params = encodeURIComponent(JSON.stringify(idsStr));
  145. uni.navigateTo({
  146. url: `/pages/activity/add-goods?idsStr=${params}`
  147. })
  148. } else {
  149. uni.navigateTo({
  150. url: `/pages/activity/add-goods`
  151. })
  152. }
  153. },
  154. selectDate() {
  155. this.$refs.calendar.open();
  156. },
  157. confirm(e) {
  158. this.form.startDate = e.range.before;
  159. this.form.endDate = e.range.after;
  160. },
  161. save () {
  162. if (!this.form.activityName) {
  163. this.$api.msg("请输入活动主题");
  164. return;
  165. }
  166. if (!this.form.activityComment) {
  167. this.$api.msg("请输入活动描述");
  168. return;
  169. }
  170. if (!this.form.startDate || !this.form.endDate) {
  171. this.$api.msg("请选择活动时间范围");
  172. return;
  173. }
  174. let start = new Date(this.form.startDate)
  175. let end = new Date(this.form.endDate)
  176. if (start > end) {
  177. this.$api.msg("开始时间不能大于结束时间");
  178. return;
  179. }
  180. if (!this.goodsList || this.goodsList.length == 0) {
  181. this.$api.msg("请选择特价菜商品列表");
  182. return;
  183. }
  184. let find = false
  185. let name = ''
  186. for (var i = 0; i < this.goodsList.length; i++) {
  187. for (var j = i + 1; j < this.goodsList.length; j++) {
  188. if (this.goodsList[i].goodsId == this.goodsList[j].goodsId && this.goodsList[i].goodsName==this.goodsList[j].goodsName) {
  189. find = true;
  190. name = this.goodsList[i].goodsName;
  191. break;
  192. }
  193. }
  194. if (find) break;
  195. }
  196. if (find) {
  197. this.$api.msg('商品:'+ name + "已存在请勿重复添加");
  198. return;
  199. }
  200. uni.showLoading({
  201. title: '保存中'
  202. });
  203. var dateStr = (new Date()).getTime();
  204. var sign = this.getSign('' + this.storeInfo.storeId + dateStr);
  205. this.requst({
  206. url: this.saveStoreSpecialActivityUrl,
  207. data: {
  208. timestamp: dateStr,
  209. sign: sign,
  210. storeId: this.storeInfo.storeId,
  211. storeSpecialActivityId: this.form.storeSpecialActivityId,
  212. activityName: this.form.activityName,
  213. activityComment: this.form.activityComment,
  214. startDate: this.form.startDate,
  215. endDate: this.form.endDate,
  216. goodsListStr: JSON.stringify(this.goodsList)
  217. },
  218. success: res => {
  219. if (res.data.rtnBean.rtnCode == 0) {
  220. uni.hideLoading();
  221. uni.showToast({
  222. title: "保存成功",
  223. duration: 3000,
  224. icon: 'none',
  225. });
  226. if (this.addFlag) {
  227. uni.redirectTo({
  228. url: '/pages/activity/special-item-info?id=' + res.data.obj
  229. })
  230. } else {
  231. let pages = getCurrentPages();
  232. let prevpage = pages[pages.length - 2];
  233. prevpage.$vm.loadData();
  234. uni.navigateBack();
  235. }
  236. } else {
  237. uni.hideLoading();
  238. this.$api.msg(res.data.rtnBean.rtnMsg);
  239. }
  240. },
  241. fail: (e) => {
  242. console.log("接口调用失败:" + JSON.stringify(e));
  243. uni.hideLoading();
  244. },
  245. })
  246. },
  247. deleteGoods(index, item) {
  248. let that = this
  249. uni.showModal({
  250. title: '提示',
  251. content: '确定移除该商品吗?',
  252. success: function(res) {
  253. if (res.confirm) {
  254. that.goodsList.splice(index, 1);
  255. }
  256. }
  257. });
  258. },
  259. },
  260. onShow () {
  261. },
  262. onLoad (options) {
  263. if (options && options.id) {
  264. uni.setNavigationBarTitle({
  265. title:'编辑特价菜活动'
  266. });
  267. this.form.storeSpecialActivityId = options.id;
  268. this.loadData();
  269. this.addFlag = false;
  270. } else {
  271. uni.setNavigationBarTitle({
  272. title:'新增特价菜活动'
  273. })
  274. this.addFlag = true;
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. .special-item-edit-page {
  281. background-color: #f5f5f5;
  282. border-top: 2rpx solid #f5f5f5;
  283. width: 100vw;
  284. height: 100vh;
  285. }
  286. .scroll-content {
  287. height: calc(100vh - 120rpx - env(safe-area-inset-bottom));
  288. height: calc(100vh - 120rpx - constant(safe-area-inset-bottom));
  289. }
  290. .between {
  291. @include between;
  292. }
  293. .cell-wrap {
  294. width: 100vw;
  295. padding: 0 40rpx;
  296. box-sizing: border-box;
  297. background-color: #fff;
  298. }
  299. .item {
  300. @include between;
  301. height: 100rpx;
  302. background-color: #fff;
  303. border-bottom: 2rpx solid #ececec;
  304. font-size: $font-base;
  305. .label {
  306. width: 200rpx;
  307. color: $title-color;
  308. }
  309. .value {
  310. width: calc(100% - 200rpx);
  311. color: $desc-color;
  312. text-align: right;
  313. }
  314. }
  315. .activities-title {
  316. height: 80rpx;
  317. @include flexStart;
  318. padding: 20rpx 40rpx 0;
  319. box-sizing: border-box;
  320. font-size: $font-base;
  321. color: $title-color;
  322. }
  323. .goods-list {
  324. .goods {
  325. background-color: #fff;
  326. @include flexStart;
  327. padding: 20rpx;
  328. box-sizing: border-box;
  329. margin-bottom: 20rpx;
  330. width: 100%;
  331. .cover {
  332. width: 166rpx;
  333. height: 166rpx;
  334. border-radius: 10rpx;
  335. margin-right: 24rpx;
  336. .img {
  337. width: 166rpx;
  338. height: 166rpx;
  339. }
  340. }
  341. .cont {
  342. width: calc(100% - 200rpx);
  343. font-size: $font-base;
  344. height: 166rpx;
  345. overflow: hidden;
  346. }
  347. .name {
  348. width: 100%;
  349. text-overflow: -o-ellipsis-lastline;
  350. overflow: hidden;
  351. text-overflow: ellipsis;
  352. display: -webkit-box;
  353. -webkit-line-clamp: 2;
  354. -webkit-box-orient: vertical;
  355. }
  356. .tools {
  357. @include flexStart;
  358. }
  359. .price {
  360. margin-right: 40rpx;
  361. color: $uni-color-button;
  362. }
  363. .origin-price {
  364. color: $desc-color;
  365. }
  366. .desc {
  367. color: $desc-color;
  368. }
  369. }
  370. .add-goods {
  371. margin-top: 40rpx;
  372. width: 180rpx;
  373. height: 60rpx;
  374. border: 2rpx solid $theme-color;
  375. color: $theme-color;
  376. @include flexCenter;
  377. margin-left: 20rpx;
  378. }
  379. }
  380. .update-events {
  381. width: 100vw;
  382. @include flexCenter;
  383. margin-top: 40rpx;
  384. .btn {
  385. width: 80vw;
  386. height: 80rpx;
  387. border-radius: 40rpx;
  388. background-color: $theme-color;
  389. color: #fff;
  390. @include flexCenter;
  391. }
  392. }
  393. </style>