add.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 configdata from '@/common/config.js';
  39. export default {
  40. data() {
  41. return {
  42. action: '',
  43. fileList: [],
  44. form: {
  45. couponName: '',
  46. endDate: '',
  47. minMoney: '',
  48. // needIntegral: '',
  49. money: '',
  50. shopId: uni.getStorageSync('shopId'),
  51. couponPicture: '',
  52. },
  53. };
  54. },
  55. onShow() {
  56. let that = this
  57. that.action=that.config("APIHOST1") + '/admin/new-file/upload'
  58. },
  59. methods: {
  60. onRemove(e){
  61. this.form.couponPicture = ''
  62. },
  63. onChange(e){
  64. if(e.data){
  65. let obj = JSON.parse(e.data)
  66. if(obj.code!=0){
  67. uni.showToast({
  68. title:'上传失败,请重新上传!',
  69. icon:'none'
  70. })
  71. this.$refs.uUpload.clear()
  72. }else{
  73. this.form.couponPicture = obj.data
  74. }
  75. }else{
  76. uni.showToast({
  77. title:'上传失败,请重新上传!',
  78. icon:'none'
  79. })
  80. this.$refs.uUpload.clear()
  81. }
  82. },
  83. //提交
  84. sumbit(){
  85. if(!this.form.couponName){
  86. uni.showToast({
  87. title:'请输入优惠券名称',
  88. icon:'none'
  89. })
  90. return
  91. }
  92. if(!this.form.endDate){
  93. uni.showToast({
  94. title:'请输入有效期天数',
  95. icon:'none'
  96. })
  97. return
  98. }
  99. if(!this.form.minMoney){
  100. uni.showToast({
  101. title:'请输入可使用订单最低金额',
  102. icon:'none'
  103. })
  104. return
  105. }
  106. // if(!this.form.needIntegral){
  107. // uni.showToast({
  108. // title:'请输入所需积分数',
  109. // icon:'none'
  110. // })
  111. // return
  112. // }
  113. if(!this.form.money){
  114. uni.showToast({
  115. title:'请输入优惠券金额',
  116. icon:'none'
  117. })
  118. return
  119. }
  120. if(!this.form.couponPicture){
  121. uni.showToast({
  122. title:'请上传优惠券图片',
  123. icon:'none'
  124. })
  125. return
  126. }
  127. uni.showLoading({
  128. title:'提交中...',
  129. mask: true, // 是否显示透明蒙层,防止触摸穿透
  130. })
  131. this.$Request.postJson("/admin/coupon/issueCoupon", this.form).then(res => {
  132. if (res.code == 0) {
  133. uni.showToast({
  134. title:'发布成功'
  135. })
  136. setTimeout(()=>{
  137. uni.navigateBack()
  138. },1000)
  139. }else{
  140. uni.showModal({
  141. title: '提示',
  142. content: res.msg,
  143. success: function (res) {
  144. if (res.confirm) {
  145. } else if (res.cancel) {
  146. }
  147. }
  148. });
  149. }
  150. uni.hideLoading()
  151. });
  152. },
  153. config: function(name) {
  154. var info = null;
  155. if (name) {
  156. var name2 = name.split("."); //字符分割
  157. if (name2.length > 1) {
  158. info = configdata[name2[0]][name2[1]] || null;
  159. } else {
  160. info = configdata[name] || null;
  161. }
  162. if (info == null) {
  163. let web_config = cache.get("web_config");
  164. if (web_config) {
  165. if (name2.length > 1) {
  166. info = web_config[name2[0]][name2[1]] || null;
  167. } else {
  168. info = web_config[name] || null;
  169. }
  170. }
  171. }
  172. }
  173. return info;
  174. },
  175. },
  176. }
  177. </script>
  178. <style lang="scss">
  179. .from {
  180. width: 100%;
  181. height: auto;
  182. margin-top: 30rpx;
  183. .from-box {
  184. width: 686rpx;
  185. height: 100%;
  186. border-radius: 16rpx;
  187. background-color: #ffffff;
  188. .from-box-c {
  189. width: 646rpx;
  190. }
  191. }
  192. }
  193. .button {
  194. width: 100%;
  195. height: 120rpx;
  196. background-color: rgb(241, 241, 241);
  197. position: fixed;
  198. bottom: 0;
  199. z-index: 999;
  200. .button-box {
  201. width: 686rpx;
  202. height: 80rpx;
  203. border-radius: 40rpx;
  204. background-color: #FCD202;
  205. }
  206. }
  207. </style>