coupon.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. define({
  2. name:"coupon",
  3. template:`
  4. <div id="coupon">
  5. <div class="vue-main-title">
  6. <div class="vue-main-title-left"></div>
  7. <div class="vue-main-title-content">优惠券</div>
  8. </div>
  9. <div style="margin:0 auto;width:80%;">
  10. <el-form>
  11. <el-form-item label="赠送优惠券" label-width="155px">
  12. <el-switch v-model="form.is_give" active-color="#29BA9C" inactive-color="#ccc" :active-value="1" :inactive-value="0"></el-switch>
  13. <div class="form-item_tips">订单完成赠送优惠券</div>
  14. <template v-if="form.is_give">
  15. <el-radio v-model="form.send_type" :label="0">每月1号0:00发放</el-radio>
  16. <el-radio v-model="form.send_type" :label="1">订单完成后的1分钟后发放</el-radio>
  17. <el-radio v-model="form.send_type" :label="2">订单付款后的1分钟后发放</el-radio>
  18. <el-form-item v-if="form.send_type == 0" prop="month">
  19. <el-input style="width:300px;" v-model.trim="form.send_num" type="number" @keyup.native="prevent($event)">
  20. <template slot="prepend">连续发放</template>
  21. <template slot="append">月</template>
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item v-for="(item,index) in giveCouponItems" :key="index" >
  25. <div style="display:flex;margin-top:20px;">
  26. <el-input style="width:400px;" v-model="item.coupon_name" class="chooseCoupon" @click.native="openCouponDialog(index,'give')">
  27. <template slot="append">选择优惠券</template>
  28. </el-input>
  29. <el-form-item prop="giveCouponItems" >
  30. <el-input v-model="item.coupon_several" style="margin-left: -8px;" type="number" @keyup.native="prevent($event)">
  31. <template slot="append">张</template>
  32. </el-input>
  33. </el-form-item>
  34. <el-button type="danger" @click="removeCoupon(index,'give')">删除</el-button>
  35. </div>
  36. </el-form-item>
  37. <div>
  38. <el-button style="margin-top: 20px;color: #29BA9C;border: 2px solid #29BA9C;" @click="addCoupon('give')">+ 增加优惠券</el-button>
  39. </div>
  40. <div class="form-item_tips">两项都填写才能生效</div>
  41. <div class="form-item_tips">订单完成后,按照勾选发放规则发放</div>
  42. </template>
  43. </el-form-item>
  44. <el-form-item label="购买商品分享优惠券" label-width="155px">
  45. <el-switch v-model="form.shopping_share" active-color="#29BA9C" inactive-color="#ccc" :active-value="1" :inactive-value="0"></el-switch>
  46. <div class="form-item_tips">会员购买指定商品,获得优惠券分享资格</div>
  47. <div v-if="form.shopping_share" style="margin-top: 30px;">
  48. <el-form-item v-for="(item,index) in shareCouponItems" :key="index">
  49. <div style="display:flex;margin-top:10px;">
  50. <el-input style="width:400px;" v-model="item.coupon_name" class="chooseCoupon" @click.native="openCouponDialog(index,'share')">
  51. <template slot="append">选择优惠券</template>
  52. </el-input>
  53. <el-form-item>
  54. <el-input v-model="item.coupon_several" style="margin-left: -8px;" type="number" @keyup.native="prevent($event)">
  55. <template slot="append">张</template>
  56. </el-input>
  57. </el-form-item>
  58. <el-button type="danger" @click="removeCoupon(index,'share')">删除</el-button>
  59. </div>
  60. </el-form-item>
  61. <el-button class="add-coupon" @click="addCoupon('share')">+ 增加优惠券</el-button>
  62. <div class="tip">两项都填写才能生效;请勿重复选择优惠券</div>
  63. <div class="tip">订单支付后,按照勾选发放规则获得对应优惠券分享资格</div>
  64. </div>
  65. </el-form-item>
  66. <el-form-item label="禁止使用优惠券" label-width="155px">
  67. <el-switch v-model="form.no_use" active-color="#29BA9C" inactive-color="#ccc" :active-value="1" :inactive-value="0"></el-switch>
  68. <div class="form-item_tips">开启后购买该商品不能使用优惠券</div>
  69. </el-form-item>
  70. <el-form-item label="可使用优惠券数量限制" label-width="155px">
  71. <el-switch v-model="form.is_use_num" active-color="#29BA9C" inactive-color="#ccc" :active-value="1" :inactive-value="0"></el-switch>
  72. <div class="form-item_tips">开启后此商品订单可限制使用优惠券数量,注:开启拆单此设置不生效</div>
  73. <el-form-item v-if="form.is_use_num" style="margin: 30px 0 0 -155px;" label="可使用数量" label-width="155px" prop="isUse" >
  74. <el-input v-model="form.use_num" style="width:300px;" type="number" @keyup.native="prevent($event)"></el-input>
  75. <div class="form-item_tips">商品订单可使用优惠券数量,为0不限制,只能设置0或整数</div>
  76. <div class="form-item_tips">注:开启拆单此设置不生效</div>
  77. </el-form-item>
  78. </el-form-item>
  79. </el-form>
  80. </div>
  81. <el-dialog
  82. :visible.sync="couponDialog"
  83. width="40%"
  84. class="el-dialog-class"
  85. @close="handleCouponClose">
  86. <div slot="title">
  87. 选择优惠券
  88. </div>
  89. <div calss="dialog-content" style="height:600px;">
  90. <el-input
  91. style="width:80%"
  92. class="inline-input"
  93. v-model="keyword"
  94. placeholder="请输入优惠券名称"
  95. ></el-input>
  96. <el-button style="margin-left: -4px;" @click="queryBtn">搜索</el-button>
  97. <div>
  98. <el-table
  99. :data="couponList"
  100. style="width: 100%">
  101. <el-table-column
  102. prop="name"
  103. label="优惠券"
  104. width="450">
  105. </el-table-column>
  106. <el-table-column
  107. label="操作"
  108. width="90">
  109. <template slot-scope="scope">
  110. <el-button
  111. size="mini"
  112. @click="selectCoupon(scope.row)">选择</el-button>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. </div>
  117. </div>
  118. </el-dialog>
  119. </div>
  120. `,
  121. style:`
  122. .chooseCoupon .el-input-group__append {
  123. background-color: #29BA9C;
  124. color: #fff;
  125. cursor: pointer;
  126. },
  127. #coupon input::-webkit-outer-spin-button,
  128. #coupon input::-webkit-inner-spin-button {
  129. -webkit-appearance: none;
  130. }
  131. #coupon input[type="number"] {
  132. -moz-appearance: textfield;
  133. }
  134. .add-coupon{
  135. margin-top: 10px;
  136. margin-bottom:10px;
  137. color: #29BA9C;
  138. border: 2px solid #29BA9C;
  139. }
  140. .el-dialog-class .el-dialog__header{
  141. padding:25px !important;
  142. }
  143. .el-dialog-class .el-dialog__body{
  144. padding: 10px 20px !important;
  145. }
  146. `,
  147. props: {
  148. form: {
  149. default() {
  150. return {}
  151. }
  152. },
  153. http_url:{
  154. type:String,
  155. default() {
  156. return "";
  157. },
  158. }
  159. },
  160. data() {
  161. return {
  162. keyword:"",
  163. couponList:[],
  164. giveCouponItems:[],//赠送优惠券
  165. giveId:1,
  166. type:"",
  167. shareCouponItems:[],//分享优惠券
  168. couponDialog:false
  169. }
  170. },
  171. mounted(){
  172. this.giveCouponItems = this.form.coupon === null ? [] :this.form.coupon;
  173. this.shareCouponItems = this.form.share_coupon === null ? [] :this.form.share_coupon;
  174. },
  175. methods: {
  176. extraDate(){
  177. },
  178. validate(){
  179. let coupon = JSON.parse(JSON.stringify(this.giveCouponItems)).filter(item => {
  180. return item.coupon_name
  181. })
  182. let share_coupon= JSON.parse(JSON.stringify(this.shareCouponItems)).filter(item => {
  183. return item.coupon_name
  184. })
  185. return {
  186. is_give:this.form.is_give,
  187. send_type:this.form.send_type,
  188. send_num:this.form.send_num,
  189. shopping_share:this.form.shopping_share,
  190. no_use:this.form.no_use,
  191. is_use_num:this.form.is_use_num,
  192. use_num:this.form.use_num,
  193. coupon,
  194. share_coupon
  195. }
  196. },
  197. openCouponDialog(id,type){
  198. if(type == 'give'){
  199. this.type = type
  200. this.giveId = id;
  201. }
  202. if(type == 'share'){
  203. this.shareId = id
  204. this.type = type
  205. }
  206. this.couponDialog = true;
  207. },
  208. handleCouponClose(){
  209. this.couponDialog = false;
  210. },
  211. //搜索按钮
  212. queryBtn(){
  213. this.$http.post(this.http_url +'coupon.coupon.get-search-coupons-v2&keyword='+this.keyword).then(response => {
  214. if(response.data.result==1){
  215. this.$message({
  216. message: '成功',
  217. type: 'success'
  218. });
  219. this.couponList = response.data.data
  220. }
  221. else{
  222. this.$message.error(response.data);
  223. }
  224. }),function(res){
  225. console.log(res);
  226. };
  227. },
  228. //选择优惠券
  229. selectCoupon(data) {
  230. if(this.type == "give"){
  231. this.giveCouponItems[this.giveId].coupon_name = data.name
  232. this.giveCouponItems[this.giveId].coupon_id = data.id
  233. }
  234. if(this.type == "share"){
  235. this.shareCouponItems[this.shareId].coupon_name = data.name
  236. this.shareCouponItems[this.shareId].coupon_id = data.id
  237. }
  238. this.couponDialog = false;
  239. },
  240. prevent(e){
  241. let keynum = window.event ? e.keyCode : e.which; //获取键盘码
  242. if (keynum ==189|| keynum==190||keynum == 109 ||keynum == 110 ) {
  243. e.target.value = ""
  244. }
  245. },
  246. //增加优惠券
  247. addCoupon(type){
  248. if(type == 'give'){
  249. this.giveCouponItems.push(
  250. {
  251. coupon_id: "",
  252. coupon_name:'',
  253. coupon_several:'1',
  254. }
  255. );
  256. }
  257. if(type == 'share'){
  258. this.shareCouponItems.push(
  259. {
  260. coupon_id: "",
  261. coupon_name:'',
  262. coupon_several:'1'
  263. }
  264. );
  265. }
  266. },
  267. //删除优惠券
  268. removeCoupon(id,type){
  269. if(type == 'give'){
  270. this.giveCouponItems.splice(id,1)
  271. }
  272. if(type == 'share'){
  273. this.shareCouponItems.splice(id,1)
  274. }
  275. },
  276. }
  277. })