edit.vue 5.5 KB

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