update-full-discounts.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="update-coupon-page">
  3. <scroll-view scroll-y class="scroll-content">
  4. <view class="note">
  5. <view class="label">满减介绍</view>
  6. <view class="text">用户下单金额达到满减活动设置的门槛金额,总支付金额即可减去对应的优惠金额。</view>
  7. </view>
  8. <view class="list-wrap">
  9. <view class="row" v-for="item in list" :key="item.sort">
  10. <text class="m">满</text>
  11. <view class="input-wrap">
  12. <u-input
  13. border="none"
  14. inputAlign="center"
  15. fontSize="12"
  16. v-model="item.conditionFee"
  17. placeholder="门槛金额">
  18. </u-input>
  19. </view>
  20. <text class="y">元</text>
  21. <text class="j">减</text>
  22. <view class="input-wrap">
  23. <u-input
  24. border="none"
  25. inputAlign="center"
  26. fontSize="12"
  27. v-model="item.discountsFee"
  28. placeholder="力度金额">
  29. </u-input>
  30. </view>
  31. <text class="y">元</text>
  32. <u-icon name="minus-circle-fill" size="20" color="red" @click="handRemove(item)"></u-icon>
  33. </view>
  34. <view class="line"></view>
  35. <view class="add-item" v-if="list.length < 5" @click="pushItem">+ 加一级满减,最多5级</view>
  36. </view>
  37. <view class="choose-date">
  38. <view class="label">选择活动执行期间</view>
  39. <view class="value" @click="selectDate" v-if="form.fullDiscountsStartDate != null && form.fullDiscountsStartDate != ''">
  40. {{ form.fullDiscountsStartDate|formatDate('yyyy-M-d') }} ~ {{ form.fullDiscountsEndDate|formatDate('yyyy-M-d') }}
  41. </view>
  42. <view class="value" @click="selectDate" v-else>
  43. 请选择活动时间
  44. </view>
  45. <!-- :formatter="formatter" -->
  46. </view>
  47. </scroll-view>
  48. <uni-calendar ref="calendar" class="uni-calendar--hook" :clear-date="true" :insert="false" :range="true" @confirm="confirm" />
  49. <view class="update-events">
  50. <view class="btn" @click="submit">保存</view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import { mapState } from 'vuex';
  56. export default {
  57. data () {
  58. return {
  59. fullDiscountsUrl: '/storeFullDiscountsManageApi/getDiscountsInfo',
  60. updateUrl: '/storeFullDiscountsManageApi/updateFullDiscounts',
  61. chooseDateVisible: false,
  62. form: {
  63. fullDiscountsStartDate: '',
  64. fullDiscountsEndDate: ''
  65. },
  66. list: [
  67. {
  68. fullDiscountsRoleId: '',
  69. conditionFee: '',
  70. discountsFee: '',
  71. sort: 1,
  72. }
  73. ]
  74. }
  75. },
  76. computed: {
  77. ...mapState(['storeInfo'])
  78. },
  79. methods: {
  80. loadData () {
  81. uni.showLoading({
  82. title: '加载中'
  83. });
  84. var dateStr = (new Date()).getTime();
  85. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  86. this.requst({
  87. url: this.fullDiscountsUrl,
  88. data: {
  89. timestamp: dateStr,
  90. sign: sign,
  91. storeId: this.storeInfo.storeId,
  92. storeUserId: this.storeInfo.storeUserId
  93. },
  94. success: res => {
  95. if (res.data.rtnBean.rtnCode == 0) {
  96. this.form = res.data.obj;
  97. if (this.form.roleList.length > 0){
  98. this.list = this.form.roleList
  99. }
  100. }
  101. uni.hideLoading();
  102. },
  103. fail: (e) => {
  104. console.log("接口调用失败:" + JSON.stringify(e));
  105. uni.hideLoading();
  106. }
  107. })
  108. },
  109. formatter(day) {
  110. const d = new Date()
  111. let month = d.getMonth() + 1
  112. const date = d.getDate()
  113. if(day.month == month && day.day == date + 3)
  114. {
  115. day.bottomInfo = '有优惠'
  116. day.dot = true
  117. }
  118. return day
  119. },
  120. selectDate() {
  121. this.$refs.calendar.open();
  122. },
  123. handRemove (item) {
  124. if (this.list.length == 1) {
  125. return;
  126. }
  127. const idx = this.list.findIndex(i => i.sort === item.sort)
  128. this.list.splice(idx, 1)
  129. },
  130. pushItem () {
  131. if (this.list.length >= 5) {
  132. return
  133. }
  134. this.list.push({ sort: this.list[this.list.length - 1].sort + 1 })
  135. },
  136. confirm(e) {
  137. if (e.range.before > e.range.after){
  138. this.$api.msg("开始时间不能大于结束时间");
  139. return;
  140. }
  141. if (e.range.before != '' && e.range.before != undefined && e.range.before != null){
  142. this.form.fullDiscountsStartDate = e.range.before;
  143. }
  144. if (e.range.after != '' && e.range.after != undefined && e.range.after != null){
  145. this.form.fullDiscountsEndDate = e.range.after;
  146. }
  147. },
  148. submit () {
  149. if (this.list.length > 0) {
  150. for (var i = 0; i < this.list.length; i++) {
  151. if (this.list[i].conditionFee == '' || this.list[i].conditionFee == undefined ||
  152. this.list[i].conditionFee == null || this.list[i].discountsFee == ''
  153. || this.list[i].discountsFee == undefined || this.list[i].discountsFee == null) {
  154. this.$api.msg("门槛金额,力度金额不能为空");
  155. return;
  156. }
  157. if (Number(this.list[i].conditionFee) <= Number(this.list[i].discountsFee)) {
  158. this.$api.msg("门槛金额必须大于力度金额");
  159. return;
  160. }
  161. if (i > 0 ) {
  162. if (Number(this.list[i].conditionFee) == Number(this.list[i-1].conditionFee)) {
  163. this.$api.msg("门槛金额不能相同");
  164. return;
  165. }
  166. }
  167. }
  168. }
  169. if (this.form.fullDiscountsStartDate == null || this.form.fullDiscountsStartDate == undefined || this.form.fullDiscountsStartDate == ""){
  170. this.$api.msg("请选择开始时间");
  171. return;
  172. }
  173. if (this.form.fullDiscountsEndDate == null || this.form.fullDiscountsEndDate == undefined || this.form.fullDiscountsEndDate == ""){
  174. this.$api.msg("请选择结束时间");
  175. return;
  176. }
  177. uni.showLoading({
  178. title: '保存中'
  179. });
  180. var dateStr = (new Date()).getTime();
  181. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  182. this.requst({
  183. url: this.updateUrl,
  184. data: {
  185. timestamp: dateStr,
  186. sign: sign,
  187. storeId: this.storeInfo.storeId,
  188. storeUserId: this.storeInfo.storeUserId,
  189. fullDiscountsStartDate: this.form.fullDiscountsStartDate,
  190. fullDiscountsEndDate: this.form.fullDiscountsEndDate,
  191. roleListStr: JSON.stringify(this.list)
  192. },
  193. success: res => {
  194. if (res.data.rtnBean.rtnCode == 0) {
  195. uni.showToast({
  196. title: "保存成功",
  197. duration: 3000,
  198. icon: 'none',
  199. });
  200. var pages = getCurrentPages();
  201. var prevPage = pages[pages.length - 2]; //上一个页面
  202. prevPage.$vm.loadData()
  203. uni.navigateBack();
  204. } else {
  205. if (res.data.rtnBean.rtnMsg != '') {
  206. this.$api.msg(res.data.rtnBean.rtnMsg);
  207. }
  208. }
  209. uni.hideLoading();
  210. },
  211. fail: (e) => {
  212. this.isDisable = false;
  213. console.log("接口调用失败:" + JSON.stringify(e));
  214. uni.hideLoading();
  215. },
  216. });
  217. }
  218. },
  219. onShow () {},
  220. onLoad() {
  221. this.loadData();
  222. }
  223. }
  224. </script>
  225. <style lang="scss" scoped>
  226. .update-coupon-page {
  227. border-top: 2rpx solid #f5f5f5;
  228. height: 100vh;
  229. background-color: #f5f5f5;
  230. }
  231. .update-events {
  232. width: 100vw;
  233. @include flexCenter;
  234. margin-top: 40rpx;
  235. .btn {
  236. width: 80vw;
  237. height: 80rpx;
  238. border-radius: 40rpx;
  239. background-color: $theme-color;
  240. color: #fff;
  241. @include flexCenter;
  242. }
  243. }
  244. .scroll-content {
  245. height: calc(100vh - 120rpx - env(safe-area-inset-bottom));
  246. height: calc(100vh - 120rpx - constant(safe-area-inset-bottom));
  247. }
  248. .note {
  249. width: calc(100% - 40rpx);
  250. height: 148rpx;
  251. border-radius: 10rpx;
  252. background-color: $theme-color;
  253. padding: 20rpx 30rpx;
  254. box-sizing: border-box;
  255. @include flexStart;
  256. margin: 20rpx;
  257. .label {
  258. min-width: 100rpx;
  259. font-weight: bold;
  260. color: #FFF5A7;
  261. font-size: 36rpx;
  262. }
  263. .text {
  264. font-size: $font-base;
  265. color: #fff;
  266. }
  267. }
  268. .list-wrap {
  269. background-color: #fff;
  270. margin: 20rpx 0;
  271. padding: 20rpx 0;
  272. .row {
  273. @include between;
  274. padding: 0 40rpx;
  275. box-sizing: border-box;
  276. margin-bottom: 30rpx;
  277. }
  278. .input-wrap {
  279. background-color: #f5f5f5;
  280. width: 160rpx;
  281. }
  282. .y {
  283. margin-right: 30rpx;
  284. }
  285. .line {
  286. width: 100%;
  287. height: 2rpx;
  288. background-color: #f5f5f5;
  289. margin: 30rpx 0;
  290. }
  291. .add-item {
  292. font-size: $font-base;
  293. color: $theme-color;
  294. text-decoration: underline;
  295. text-align: center;
  296. }
  297. }
  298. .choose-date {
  299. @include between;
  300. height: 120rpx;
  301. background-color: #fff;
  302. padding: 0 40rpx;
  303. box-sizing: border-box;
  304. font-size: $font-base;
  305. .label {
  306. color: $text-color;
  307. }
  308. .value {
  309. color: $title-color;
  310. background-color: #f5f5f5;
  311. padding: 10rpx 20rpx;
  312. box-sizing: border-box;
  313. }
  314. }
  315. </style>