edit.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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" :file-list="fileList" :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. couponId:'',
  47. couponName: '',
  48. endDate: '',
  49. minMoney: '',
  50. // needIntegral: '',
  51. money: '',
  52. shopId: uni.getStorageSync('shopId'),
  53. couponPicture: '',
  54. },
  55. };
  56. },
  57. onLoad(option) {
  58. let info = JSON.parse(option.info)
  59. this.fileList = [
  60. {url:info.couponPicture}
  61. ]
  62. this.form = {
  63. couponId:info.couponId,
  64. couponName: info.couponName,
  65. endDate: info.endDate,
  66. minMoney: info.minMoney,
  67. // needIntegral: info.needIntegral,
  68. money: info.money,
  69. shopId: uni.getStorageSync('shopId'),
  70. couponPicture: info.couponPicture,
  71. },
  72. console.log(this.form)
  73. },
  74. methods: {
  75. onRemove(e){
  76. this.form.couponPicture = ''
  77. },
  78. onChange(e){
  79. if(e.data){
  80. let obj = JSON.parse(e.data)
  81. if(obj.code!=0){
  82. uni.showToast({
  83. title:'上传失败,请重新上传!',
  84. icon:'none'
  85. })
  86. this.$refs.uUpload.clear()
  87. }else{
  88. this.form.couponPicture = obj.data
  89. }
  90. }else{
  91. uni.showToast({
  92. title:'上传失败,请重新上传!',
  93. icon:'none'
  94. })
  95. this.$refs.uUpload.clear()
  96. }
  97. },
  98. //提交
  99. sumbit(){
  100. if(!this.form.couponName){
  101. uni.showToast({
  102. title:'请输入优惠券名称',
  103. icon:'none'
  104. })
  105. return
  106. }
  107. if(!this.form.endDate){
  108. uni.showToast({
  109. title:'请输入有效期天数',
  110. icon:'none'
  111. })
  112. return
  113. }
  114. if(!this.form.minMoney){
  115. uni.showToast({
  116. title:'请输入可使用订单最低金额',
  117. icon:'none'
  118. })
  119. return
  120. }
  121. // if(!this.form.needIntegral){
  122. // uni.showToast({
  123. // title:'请输入所需积分数',
  124. // icon:'none'
  125. // })
  126. // return
  127. // }
  128. if(!this.form.money){
  129. uni.showToast({
  130. title:'请输入优惠券金额',
  131. icon:'none'
  132. })
  133. return
  134. }
  135. if(!this.form.couponPicture){
  136. uni.showToast({
  137. title:'请上传优惠券图片',
  138. icon:'none'
  139. })
  140. return
  141. }
  142. uni.showLoading({
  143. title:'提交中...'
  144. })
  145. this.$Request.postJson("/admin/coupon/updateCoupon", this.form).then(res => {
  146. if (res.code == 0) {
  147. uni.showToast({
  148. title:'修改成功'
  149. })
  150. setTimeout(()=>{
  151. uni.navigateBack()
  152. },1000)
  153. }else{
  154. uni.showToast({
  155. title:res.msg,
  156. icon:'none'
  157. })
  158. }
  159. uni.hideLoading()
  160. });
  161. },
  162. },
  163. }
  164. </script>
  165. <style lang="scss">
  166. .from {
  167. width: 100%;
  168. height: auto;
  169. margin-top: 30rpx;
  170. .from-box {
  171. width: 686rpx;
  172. height: 100%;
  173. border-radius: 16rpx;
  174. background-color: #ffffff;
  175. .from-box-c {
  176. width: 646rpx;
  177. }
  178. }
  179. }
  180. .button {
  181. width: 100%;
  182. height: 120rpx;
  183. background-color: rgb(241, 241, 241);
  184. position: fixed;
  185. bottom: 0;
  186. z-index: 999;
  187. .button-box {
  188. width: 686rpx;
  189. height: 80rpx;
  190. border-radius: 40rpx;
  191. background-color: #FCD202;
  192. }
  193. }
  194. </style>