give-coupon.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. use common\helpers\AddonHelper;
  4. ComponentHelper::loadComponentView('coupon-select', AddonHelper::getAddonRootPath('Coupon') . 'backend/views/components');
  5. ?>
  6. <template id="give-coupon">
  7. <el-dialog width="60%" :title="'补货赠送设置'" class="dialogClass" center :visible.sync="visible" :before-close="cancel"><!-- 添加库存商品 -->
  8. <div style="height: 600px;overflow-y: auto;">
  9. <el-form :model="form" size="small">
  10. <el-form-item label="是否开启补货赠送优惠券" prop="is_buhuo">
  11. <el-switch :active-value="1" :inactive-value="0" v-model="form.is_buhuo"></el-switch>
  12. </el-form-item>
  13. <div v-if="form.is_buhuo == 1" style="margin-left: 100px">
  14. <el-row :gutter="10" v-for="(data,index) in form.coupon_data">
  15. <el-form-item>
  16. <span style="margin-right: 10px">
  17. {{data.level_name}}
  18. </span>
  19. <el-input type="number" :min="0" class="member-money" v-model="data.num" placeholder="" style="width: 300px">
  20. <template slot="prepend">一次性补货满</template>
  21. <template slot="append">件</template>
  22. </el-input>
  23. </el-form-item>
  24. <el-form-item label="选择优惠券">
  25. <el-button type="primary" size="mini" @click="handle('select',null,index)">选择优惠券</el-button>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-row>
  29. <el-col :span="2">已选优惠券</el-col>
  30. <el-col :span="20">
  31. <el-col :span="5" v-for="(item,i_index) in data.multiple_selection" :key="i_index" style="margin-bottom: 10px">
  32. <el-card shadow="always" style="position: relative; margin-right: 10px;">
  33. <div>{{item.name}}</div>
  34. <div>优惠方式:{{ item.discount_method }}</div>
  35. <div>赠送数量:<span>{{item.num}}</span></div>
  36. <el-button type="danger" icon="el-icon-delete" circle style="position: absolute; right: 8px;top: 10px;" @click="handle('delete', i_index,index)"></el-button>
  37. </el-card>
  38. </el-col>
  39. </el-col>
  40. </el-row>
  41. </el-form-item>
  42. </el-row>
  43. </div>
  44. <el-form-item label="配货是否触发补货规则" prop="is_peihuo">
  45. <el-tooltip class='item' effect='dark' content='上级配货数量满足补货赠送规则,也会获得对应的优惠券奖励' placement='top'>
  46. <i class='el-icon-info'></i></el-tooltip>
  47. <el-switch :active-value="1" :inactive-value="0" v-model="form.is_peihuo"></el-switch>
  48. </el-form-item>
  49. </el-form>
  50. </div>
  51. <span slot="footer" class="dialog-footer">
  52. <el-button @click="cancel" type="default" size="small">取消</el-button>
  53. <el-button type="primary" :loading="btnLoading" style="margin-bottom: 10px;" size="small"
  54. @click="save">保存</el-button>
  55. </span>
  56. <coupon-select :coupon-loading="couponLoading" :coupon_arr="multiple_selection" @submit="handleCoupon" @close="couponLoading = false" :index="index"></coupon-select>
  57. </el-dialog>
  58. </template>
  59. <script>
  60. Vue.component('give-coupon', {
  61. template: "#give-coupon",
  62. props: {
  63. visible: {
  64. type: Boolean,
  65. default: false
  66. },
  67. goods_id: {
  68. type: Number | String,
  69. default: 0
  70. }
  71. },
  72. data() {
  73. return {
  74. couponLoading: false,
  75. form: {
  76. goods_id: 0,
  77. num: 0,
  78. is_buhuo: 0,
  79. coupon_data: [],
  80. is_peihuo: 0
  81. },
  82. multiple_selection: [],
  83. index: -1,
  84. btnLoading: false,
  85. }
  86. },
  87. watch: {
  88. form: {
  89. deep: true,
  90. immediate: true,
  91. handler(value) {
  92. this.$emit("select", {
  93. Coupon: this.form
  94. });
  95. }
  96. },
  97. visible: {
  98. deep: true,
  99. immediate: true,
  100. handler(value) {
  101. if (value) {
  102. this.form.goods_id = this.goods_id;
  103. this.coupon();
  104. }
  105. }
  106. }
  107. },
  108. mounted: function() {
  109. if (this.goods_id) this.coupon();
  110. },
  111. methods: {
  112. handleCoupon(data) {
  113. this.couponLoading = false;
  114. this.multiple_selection = data;
  115. this.form.coupon_data[this.index].multiple_selection = data;
  116. },
  117. handle(type, data = null, index = -1) {
  118. let selection = this.form.coupon_data[index].multiple_selection;
  119. this.multiple_selection = selection;
  120. switch (type) {
  121. case 'select':
  122. this.couponLoading = true;
  123. this.index = index;
  124. break;
  125. case 'delete':
  126. this.form.coupon_data[index].multiple_selection.splice(data, 1);
  127. break;
  128. }
  129. },
  130. cancel() {
  131. this.$emit("cancel");
  132. },
  133. save() {
  134. request({
  135. params: {
  136. r: 'cloud-stock/goods/set-setting'
  137. },
  138. method: 'post',
  139. data: this.form,
  140. }).then(response => {
  141. this.btnLoading = false;
  142. if (response.data.code == 0) {
  143. this.$message.success('保存成功');
  144. this.$emit("save");
  145. this.cancel()
  146. } else {
  147. this.$message.error(response.data.msg);
  148. }
  149. }).catch(response => {
  150. this.btnLoading = false;
  151. });
  152. },
  153. //优惠券列表
  154. coupon() {
  155. request({
  156. params: {
  157. r: 'cloud-stock/goods/get-coupon-setting',
  158. },
  159. method: 'post',
  160. data: {
  161. goods_id: this.goods_id
  162. }
  163. }).then(res => {
  164. this.form.is_buhuo = res.data.data.is_buhuo
  165. this.form.is_peihuo = res.data.data.is_peihuo
  166. this.form.coupon_data = res.data.data.coupon_data
  167. })
  168. },
  169. }
  170. });
  171. </script>
  172. <style>
  173. .dialogClass .el-dialog__body {
  174. padding: 15px 20px;
  175. color: #606266;
  176. font-size: 14px;
  177. word-break: break-all;
  178. padding-bottom: 0;
  179. }
  180. input::-webkit-outer-spin-button,
  181. input::-webkit-inner-spin-button {
  182. -webkit-appearance: none;
  183. }
  184. input[type="number"] {
  185. -moz-appearance: textfield;
  186. }
  187. </style>