add.vue 5.0 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. // 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. onShow() {
  57. let that = this
  58. that.action=that.config("APIHOST1") + '/alioss/upload'
  59. },
  60. methods: {
  61. onRemove(e){
  62. this.form.couponPicture = ''
  63. },
  64. onChange(e){
  65. if(e.data){
  66. let obj = JSON.parse(e.data)
  67. if(obj.code!=0){
  68. uni.showToast({
  69. title:'上传失败,请重新上传!',
  70. icon:'none'
  71. })
  72. this.$refs.uUpload.clear()
  73. }else{
  74. this.form.couponPicture = obj.data
  75. }
  76. }else{
  77. uni.showToast({
  78. title:'上传失败,请重新上传!',
  79. icon:'none'
  80. })
  81. this.$refs.uUpload.clear()
  82. }
  83. },
  84. //提交
  85. sumbit(){
  86. if(!this.form.couponName){
  87. uni.showToast({
  88. title:'请输入优惠券名称',
  89. icon:'none'
  90. })
  91. return
  92. }
  93. if(!this.form.endDate){
  94. uni.showToast({
  95. title:'请输入有效期天数',
  96. icon:'none'
  97. })
  98. return
  99. }
  100. if(!this.form.minMoney){
  101. uni.showToast({
  102. title:'请输入可使用订单最低金额',
  103. icon:'none'
  104. })
  105. return
  106. }
  107. // if(!this.form.needIntegral){
  108. // uni.showToast({
  109. // title:'请输入所需积分数',
  110. // icon:'none'
  111. // })
  112. // return
  113. // }
  114. if(!this.form.money){
  115. uni.showToast({
  116. title:'请输入优惠券金额',
  117. icon:'none'
  118. })
  119. return
  120. }
  121. if(!this.form.couponPicture){
  122. uni.showToast({
  123. title:'请上传优惠券图片',
  124. icon:'none'
  125. })
  126. return
  127. }
  128. uni.showLoading({
  129. title:'提交中...'
  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>