add.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view>
  3. <view class="from flex justify-center">
  4. <view class="from-box flex justify-center">
  5. <view class="from-box-c">
  6. <u-form :model="form" label-position="top" ref="uForm">
  7. <u-form-item label="优惠券名称">
  8. <u-input v-model="form.couponName" placeholder="请输入优惠券名称" />
  9. </u-form-item>
  10. <u-form-item label="有效期天数">
  11. <u-input v-model="form.endDate" type="number" placeholder="请选择有效期天数" />
  12. </u-form-item>
  13. <u-form-item label="可使用订单最低金额">
  14. <u-input v-model="form.minMoney" type="number" placeholder="请输入可使用订单最低金额" />
  15. </u-form-item>
  16. <!-- <u-form-item label="所需积分数">
  17. <u-input v-model="form.needIntegral" type="number" placeholder="请输入所需积分数" />
  18. </u-form-item> -->
  19. <u-form-item label="优惠券金额">
  20. <u-input v-model="form.money" type="number" placeholder="请输入优惠券金额" />
  21. </u-form-item>
  22. <u-form-item label="优惠券图片">
  23. <u-upload ref="uUpload" :multiple="false" max-count="1" :action="action" @on-remove="onRemove" @on-change="onChange"></u-upload>
  24. </u-form-item>
  25. </u-form>
  26. </view>
  27. </view>
  28. </view>
  29. <!-- 保存 -->
  30. <view class="button flex justify-center align-center">
  31. <view class="button-box flex justify-center align-center" @click="sumbit()">
  32. 保存
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import config from '../../common/config.js'
  39. export default {
  40. data() {
  41. return {
  42. action: 'https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload',
  43. // action: config.APIHOST+'/alioss/upload',
  44. fileList: [],
  45. form: {
  46. couponName: '',
  47. endDate: '',
  48. minMoney: '',
  49. // needIntegral: '',
  50. money: '',
  51. shopId: uni.getStorageSync('shopId'),
  52. couponPicture: '',
  53. },
  54. };
  55. },
  56. methods: {
  57. onRemove(e){
  58. this.form.couponPicture = ''
  59. },
  60. onChange(e){
  61. if(e.data){
  62. let obj = JSON.parse(e.data)
  63. if(obj.code!=0){
  64. uni.showToast({
  65. title:'上传失败,请重新上传!',
  66. icon:'none'
  67. })
  68. this.$refs.uUpload.clear()
  69. }else{
  70. this.form.couponPicture = obj.data
  71. }
  72. }else{
  73. uni.showToast({
  74. title:'上传失败,请重新上传!',
  75. icon:'none'
  76. })
  77. this.$refs.uUpload.clear()
  78. }
  79. },
  80. //提交
  81. sumbit(){
  82. if(!this.form.couponName){
  83. uni.showToast({
  84. title:'请输入优惠券名称',
  85. icon:'none'
  86. })
  87. return
  88. }
  89. if(!this.form.endDate){
  90. uni.showToast({
  91. title:'请输入有效期天数',
  92. icon:'none'
  93. })
  94. return
  95. }
  96. if(!this.form.minMoney){
  97. uni.showToast({
  98. title:'请输入可使用订单最低金额',
  99. icon:'none'
  100. })
  101. return
  102. }
  103. // if(!this.form.needIntegral){
  104. // uni.showToast({
  105. // title:'请输入所需积分数',
  106. // icon:'none'
  107. // })
  108. // return
  109. // }
  110. if(!this.form.money){
  111. uni.showToast({
  112. title:'请输入优惠券金额',
  113. icon:'none'
  114. })
  115. return
  116. }
  117. if(!this.form.couponPicture){
  118. uni.showToast({
  119. title:'请上传优惠券图片',
  120. icon:'none'
  121. })
  122. return
  123. }
  124. uni.showLoading({
  125. title:'提交中...'
  126. })
  127. this.$Request.postJson("/admin/coupon/issueCoupon", this.form).then(res => {
  128. if (res.code == 0) {
  129. uni.showToast({
  130. title:'发布成功'
  131. })
  132. setTimeout(()=>{
  133. uni.navigateBack()
  134. },1000)
  135. }else{
  136. uni.showToast({
  137. title:res.msg,
  138. icon:'none'
  139. })
  140. }
  141. uni.hideLoading()
  142. });
  143. },
  144. },
  145. }
  146. </script>
  147. <style lang="scss">
  148. .from {
  149. width: 100%;
  150. height: auto;
  151. margin-top: 30rpx;
  152. .from-box {
  153. width: 686rpx;
  154. height: 100%;
  155. border-radius: 16rpx;
  156. background-color: #ffffff;
  157. .from-box-c {
  158. width: 646rpx;
  159. }
  160. }
  161. }
  162. .button {
  163. width: 100%;
  164. height: 120rpx;
  165. background-color: rgb(241, 241, 241);
  166. position: fixed;
  167. bottom: 0;
  168. z-index: 999;
  169. .button-box {
  170. width: 686rpx;
  171. height: 80rpx;
  172. border-radius: 40rpx;
  173. background-color: #FCD202;
  174. }
  175. }
  176. </style>