edit.php 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. <?php defined('YII_ENV') or exit('Access Denied'); ?>
  2. <style>
  3. .list {
  4. margin-top: 10px;
  5. width: 100%;
  6. }
  7. .choose {
  8. border: 1px solid #e2e2e2;
  9. height: 125px;
  10. width: 120px;
  11. padding-top: 15px;
  12. text-align: center;
  13. margin: 0 10px 20px 0;
  14. border-radius: 0 !important;
  15. position: relative;
  16. }
  17. .choose i {
  18. position: absolute;
  19. top: 5px;
  20. right: 5px;
  21. cursor: pointer;
  22. }
  23. .choose .name {
  24. margin-top: -10px;
  25. }
  26. .item .el-checkbox-button__inner {
  27. border: 1px solid #e2e2e2;
  28. height: 125px;
  29. width: 120px;
  30. padding-top: 15px;
  31. text-align: center;
  32. margin: 0 20px 20px 0;
  33. cursor: pointer;
  34. border-radius: 0 !important;
  35. }
  36. .item.active {
  37. background-color: #50A0E4;
  38. color: #fff;
  39. }
  40. .list .img {
  41. height: 60px;
  42. width: 60px;
  43. border-radius: 30px;
  44. }
  45. .name {
  46. margin-top: 10px;
  47. font-size: 13px;
  48. overflow: hidden;
  49. text-overflow: ellipsis;
  50. white-space: nowrap;
  51. }
  52. .el-tabs__header {
  53. padding: 0 20px;
  54. height: 56px;
  55. line-height: 56px;
  56. background-color: #fff;
  57. margin-bottom: 0;
  58. }
  59. .form-body {
  60. background-color: #fff;
  61. /* padding: 20px 50% 20px 20px; */
  62. padding: 0;
  63. min-width: 1000px;
  64. }
  65. .el-form-item{
  66. padding-right: 40%
  67. }
  68. .button-item {
  69. /*margin-top: 12px;*/
  70. padding: 9px 25px;
  71. }
  72. .del-btn {
  73. position: absolute;
  74. right: -8px;
  75. top: -8px;
  76. padding: 4px 4px !important;
  77. }
  78. .header-box {
  79. padding: 20px;
  80. background-color: #fff;
  81. margin-bottom: 10px;
  82. border-top-left-radius: 4px;
  83. border-top-right-radius: 4px;
  84. }
  85. .el-card,
  86. .el-message {
  87. border-radius: 0;
  88. border-bottom-left-radius: 4px;
  89. border-bottom-right-radius: 4px;
  90. }
  91. .text {
  92. cursor: pointer;
  93. color: #419EFB;
  94. }
  95. .coupon-type {
  96. border: 1px solid #E0E0E0;
  97. padding: 20px 16px;
  98. font-size: 16px;
  99. line-height: 30px;
  100. margin-right: 24px;
  101. min-width: 160px;
  102. border-radius: 8px;
  103. color: #E0E0E0;
  104. font-weight: 400;
  105. }
  106. .coupon-type-name {
  107. color: #666;
  108. font-size: 24px;
  109. font-weight: bold;
  110. }
  111. .coupon-type-img{
  112. margin-right: 12px;
  113. }
  114. .coupon-type:hover,
  115. .click-so {
  116. cursor: pointer;
  117. }
  118. .sel-coupon-type {
  119. border: 2px solid #409EFF;
  120. color: #666;
  121. }
  122. .sel-coupon-type-name {
  123. color: #409EFF;
  124. }
  125. .discount-text {
  126. line-height: 30px;
  127. }
  128. .add-goods-info{
  129. margin-left: 12px;
  130. font-size: 16px;
  131. color: #333;
  132. line-height: 24px;
  133. }
  134. .coupon-form .el-input-group__prepend{
  135. background: transparent;
  136. }
  137. .coupon-form .el-input-group__append{
  138. background: #F2F3F4;
  139. border: 1px solid #E0E0E0;
  140. border-left: 0;
  141. font-size: 14px;
  142. color: #666666;
  143. }
  144. .coupon-form .el-input__inner[type="number"]{
  145. padding-right: 0;
  146. }
  147. .expire_type_model{
  148. margin-bottom: 10px;
  149. }
  150. .coupon_expire_type,.coupon_expire_type_text{
  151. display: flex;
  152. align-items: center;
  153. }
  154. .coupon_expire_type .el-input-group{
  155. margin: 0 6px;
  156. }
  157. .coupon-model-title{
  158. padding: 0 16px 20px;
  159. margin-bottom: 20px;
  160. font-size: 18px;
  161. font-weight: 500;
  162. line-height: 31px;
  163. color: #333333;
  164. border-bottom: 1px solid #F2F2F2;
  165. }
  166. .coupon-model-title:first-child{
  167. padding-top: 20px;
  168. }
  169. .coupon-award>div{
  170. margin-bottom: 20px;
  171. }
  172. </style>
  173. <div id="app" v-cloak>
  174. <div slot="header" class="header-box">
  175. <div flex="cross:center box:first">
  176. <div><span @click="$navigate({r:'mall/coupon/index'})" class="text">优惠券管理</span> / 优惠券编辑</div>
  177. <div flex="dir:right">
  178. <div>
  179. <el-button :disabled="!is_can_edit" class="button-item" type="primary" size="small" :loading=submitLoading @click="onSubmit">保存</el-button>
  180. <el-button :disabled="!is_can_edit" class="button-item" type="primary" size="small" :loading=submitLoading v-if="coupon_id>0"@click="delCoupon(coupon_id)">删除</el-button>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <el-card v-loading="loading" style="border:0" shadow="never" body-style="background-color: #f3f3f3;padding: 0 0;">
  186. <el-form class="coupon-form" :model="form" label-width="10.5rem" :rules="FormRules" ref="form">
  187. <div class="form-body">
  188. <div class="coupon-model-title">
  189. 规则设置
  190. </div>
  191. <el-form-item label="优惠券类型" prop="type">
  192. <div flex>
  193. <div class="coupon-type" flex :class="{'sel-coupon-type': form.type == 2}" @click="selectType(2)">
  194. <div class="coupon-type-img">
  195. <el-image style="width: 52px; height: 52px" :src="form.type == 2?'resources/img/plugins/coupon/selCoupon.png':'resources/img/plugins/coupon/noCoupon.png'"></el-image>
  196. </div>
  197. <div>
  198. <div class="coupon-type-name" :class="{'sel-coupon-type-name': form.type == 2}">满减券</div>
  199. <div>例:满100减20</div>
  200. </div>
  201. </div>
  202. <div class="coupon-type" flex :class="{'sel-coupon-type': form.type == 1}" @click="selectType(1)">
  203. <div class="coupon-type-img">
  204. <el-image style="width: 52px; height: 52px" :src="form.type == 1?'resources/img/plugins/coupon/selCoupon.png':'resources/img/plugins/coupon/noCoupon.png'"></el-image>
  205. </div>
  206. <div>
  207. <div class="coupon-type-name" :class="{'sel-coupon-type-name': form.type == 1}">折扣券</div>
  208. <div>例:满100打9折</div>
  209. </div>
  210. </div>
  211. </div>
  212. </el-form-item>
  213. <el-form-item prop="discount">
  214. <template slot='label'>
  215. <span class="discount-text">优惠内容</span>
  216. </template>
  217. <!-- 满减 -->
  218. <div v-if="form.type == 2" style="display: flex;">
  219. <el-input size="small" @input="handleMinPrice" ref="min_price" style="width: 30%;margin-right: 6px;" type="number" v-model="form.min_price" autocomplete="off">
  220. <div class="discount-text" slot="prepend">消费满</div>
  221. <template slot="append">元</template>
  222. </el-input>
  223. <el-input size="small" @input="handleSubPrice" ref="sub_price" style="width: 30%;margin: 0 6px;" type="number" v-model="form.sub_price" autocomplete="off">
  224. <div class="discount-text" slot="prepend" style="text-align: center;">减</div>
  225. <template slot="append">元</template>
  226. </el-input>
  227. </div>
  228. <!-- 折扣 -->
  229. <div v-if="form.type == 1" style="display: flex;">
  230. <el-input size="small" @input="handleMinPrice" style="margin-right: 6px;" ref="fold_min_price" prop="min_price" type="number" v-model="form.min_price" autocomplete="off">
  231. <div class="discount-text" slot="prepend" >消费满</div>
  232. <template slot="append">元</template>
  233. </el-input>
  234. <el-input size="small" @input="handleSubPrice" style="margin: 0 6px;" type="number" v-model="form.discount" autocomplete="off" prop="discount">
  235. <div class="discount-text" slot="prepend" >打</div>
  236. <template slot="append">折</template>
  237. </el-input>
  238. <el-checkbox ref="is_discount_limit" @change="discount_limit_change" v-model="is_discount_limit" :true-label="1" :false-label="0" style="display: flex;justify-content: center;align-items: center;margin: 0 6px;">最多优惠</el-checkbox>
  239. <el-input size="small" @input="handleDiscountLimit" style="margin: 0 6px;" ref="fold_discount_limit" type="number" v-model="form.discount_limit" autocomplete="off" prop="discount_limit">
  240. <template slot="append">元</template>
  241. </el-input>
  242. </div>
  243. </el-form-item>
  244. <el-form-item label="优惠券名称" prop="name">
  245. <el-input size="small" minlength="1" maxlength="150" show-word-limit v-model="form.name" autocomplete="off" placeholder="请输入优惠券名称"></el-input>
  246. </el-form-item>
  247. <el-form-item prop="total_count">
  248. <template slot='label'>
  249. <span>发放总数</span>
  250. <el-tooltip effect="dark" content="优惠券总数量不能为 0" placement="top">
  251. <i class="el-icon-info"></i>
  252. </el-tooltip>
  253. </template>
  254. <el-input size="small" style="width: 260px;" @input="numForm($event,'total_count')" v-model.number="form.total_count" :min="1" autocomplete="off">
  255. <template slot="append">张</template>
  256. </el-input>
  257. </el-form-item>
  258. <el-form-item label="优惠券有效期" prop="expire_type">
  259. <div class="expire_type_model">
  260. <el-radio class="coupon_expire_type" :disabled="is_can_change_time" v-model="form.expire_type" :label="1">
  261. <span class="coupon_expire_type_text" style="color: #333;">
  262. 领券后立即生效,有效
  263. <el-input size="small" style="width: 30%;" min="1" :disabled="is_can_change_time" v-model="form.expire_day" autocomplete="off" @input="numForm($event,'expire_day')">
  264. <template slot="append">天</template>
  265. </el-input>
  266. </span>
  267. </el-radio>
  268. </div>
  269. <div class="expire_type_model">
  270. <el-radio class="coupon_expire_type" :disabled="is_can_change_time" v-model="form.expire_type" :label="3">
  271. <span class="coupon_expire_type_text" style="color: #333;">
  272. 领券
  273. <el-input size="small" style="width: 30%;" min="1" :disabled="is_can_change_time" v-model="form.effect_days" autocomplete="off" @input="numForm($event,'effect_days')" >
  274. <template slot="append">天</template>
  275. </el-input>
  276. 后生效,有效期
  277. <el-input size="small" style="width: 30%;" min="1" :disabled="is_can_change_time" v-model="form.effect_expire_days" autocomplete="off" @input="numForm($event,'effect_expire_days')">
  278. <template slot="append">天</template>
  279. </el-input>
  280. </span>
  281. </el-radio>
  282. </div>
  283. <div class="expire_type_model">
  284. <el-radio class="coupon_expire_type" :disabled="is_can_change_time" v-model="form.expire_type" :label="2">
  285. <el-date-picker size="small" :disabled="is_can_change_time" v-model="expire_time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="select_expire_time">
  286. </el-date-picker>
  287. </el-radio>
  288. </div>
  289. </el-form-item>
  290. <el-form-item label="视频封面:" prop="" >
  291. <div style="float: left;">
  292. <com-attachment v-model="form.first_frame" :multiple="false" :max="1">
  293. <el-tooltip class="item" effect="dark" content="建议尺寸:420 * 336" placement="top">
  294. <el-button size="mini">选择图片</el-button>
  295. </el-tooltip>
  296. </com-attachment>
  297. <div class="customize-share-title">
  298. <com-image mode="aspectFill" width='80px' height='80px' :src="form.first_frame ? form.first_frame : ''"></com-image>
  299. </div>
  300. </div>
  301. </el-form-item>
  302. <el-form-item label="视频上传" prop="video_url">
  303. <com-attachment :multiple="false" :max="1" @selected="videoUrl" type="videos">
  304. <el-tooltip class="item" effect="dark" content="支持格式mp4;支持编码H.264;" placement="top">
  305. <el-button size="mini">选择视频</el-button>
  306. </el-tooltip>
  307. </com-attachment>
  308. <a class="box-grow-0" type="primary" style="font-size:12px" title="播放视频" v-if="form.video_url" :underline="false" target="_blank" :href="form.video_url">
  309. <el-button type="primary" size="mini">播放</el-button>
  310. </a>
  311. </el-form-item>
  312. <el-form-item prop="watch_times">
  313. <template slot='label'>
  314. <span>观看秒数</span>
  315. </template>
  316. <el-input size="small" style="width: 260px;" type="number" onInput="value=toNumber(value,2)" v-model="form.watch_times" :min="1" autocomplete="off">
  317. <template slot="append">秒</template>
  318. </el-input>
  319. </el-form-item>
  320. <el-form-item label="使用范围" prop="appoint_type">
  321. <el-radio v-model="form.appoint_type" :label="3">全店通用</el-radio>
  322. <el-radio v-model="form.appoint_type" @click.native="goodsListVisible = true" :label="2">
  323. 指定商品可用
  324. </el-radio>
  325. <el-radio v-model="form.appoint_type" :label="1">指定商品分类可用</el-radio>
  326. <div v-if="form.appoint_type ==1">
  327. <el-cascader size="small" v-model="cat_id_list" :options="cats_list" :props="{ multiple: true,checkStrictly: true,emitPath: false, }" clearable></el-cascader>
  328. </div>
  329. <div v-if="form.appoint_type == 2">
  330. <el-button :disabled="!is_can_edit" type="text" @click.native="goodsAddVisible = true">选择商品</el-button>
  331. <el-table :data="selected_goods" style="width: 100%" del-max-height="99999px">
  332. <el-table-column prop="goods_id" label="ID" width="80"></el-table-column>
  333. <el-table-column prop="cover_pic" label="商品" width="280">
  334. <template slot-scope="scope">
  335. <div flex>
  336. <com-image mode="aspectFill" :src="scope.row.cover_pic"></com-image>
  337. <div class="add-goods-info">
  338. <div>{{scope.row.goods_name}}</div>
  339. <div style="font-size: 14px;color: #B2B2B2;">{{scope.row.price}} - {{scope.row.original_price}}</div>
  340. </div>
  341. </div>
  342. </template>
  343. </el-table-column>
  344. <el-table-column label="操作" width="120">
  345. <template slot-scope="scope">
  346. <el-button plain size="mini" type="danger" @click="goodsDestroy(scope.$index)">删除</el-button>
  347. </template>
  348. </el-table-column>
  349. </el-table>
  350. </div>
  351. </el-form-item>
  352. <!-- <el-form-item label="过期提醒" prop="is_remind">-->
  353. <!-- <div style="display: flex;align-items: center;">-->
  354. <!-- <el-checkbox v-model="form.is_remind" :true-label="1" :false-label="0">-->
  355. <!-- <span style="color: #333;">优惠券过期前</span>-->
  356. <!-- </el-checkbox>-->
  357. <!-- <el-input size="small" prop="remind_days" :disabled="form.is_remind!=1" style="width: 20%;margin: 0 10px;" v-model="form.remind_days" autocomplete="off" @input="numForm($event,'remind_days')">-->
  358. <!-- <template slot="append">天</template>-->
  359. <!-- </el-input>-->
  360. <!-- <div>提醒</div>-->
  361. <!-- <el-tooltip effect="dark" content="建议设置的天数小于优惠券的有效期,否则用户无法收到过期提醒"-->
  362. <!-- placement="top">-->
  363. <!-- <i class="el-icon-question" style="font-size: 20px;color: #858585;margin-left: 10px;"></i>-->
  364. <!-- </el-tooltip>-->
  365. <!-- </div>-->
  366. <!-- </el-form-item>-->
  367. <el-form-item label="优惠叠加" prop="is_original_use">
  368. <el-checkbox v-model="form.is_original_use" :true-label="1" :false-label="0">
  369. <span style="color: #333;">优惠券仅原价购买时可用</span>
  370. </el-checkbox>
  371. </el-form-item>
  372. <el-form-item label="使用说明" prop="rule">
  373. <el-input size="small" v-model="form.rule" type="textarea" :rows="4" placeholder="请输入内容">
  374. </el-input>
  375. </el-form-item>
  376. <div class="coupon-model-title">
  377. 领取规则
  378. </div>
  379. <el-form-item label="每人最多可领取" prop="receive_count">
  380. <el-input size="small" v-model="form.receive_count" autocomplete="off" style="width: 260px;" @input="numForm($event,'receive_count')">
  381. <template slot="append">张</template>
  382. </el-input>
  383. <div style="color: #999;font-size: 14px;">编辑保存后,仅对后续领取的客户生效,对之前已领取的客户无法生效。</div>
  384. </el-form-item>
  385. <el-form-item label="是否设为开屏优惠券" prop="is_open_screen">
  386. <el-switch v-model="form.is_open_screen" active-color="#13ce66" :active-value="1" :inactive-value="0"></el-switch>
  387. </el-form-item>
  388. <el-form-item label="优惠券允许公开领取" prop="is_public_receive">
  389. <el-switch :disabled="!is_can_edit" v-model="form.is_public_receive" active-color="#13ce66" :active-value="1" :inactive-value="0"></el-switch>
  390. <span style="color: #999; font-size: 14px;line-height:24px;margin-left: 4px;">开启后会在商详区域展示</span>
  391. </el-form-item>
  392. <el-form-item label="转赠设置" prop="is_giving">
  393. <div>
  394. <el-switch :disabled="!is_can_edit" @change="updateGiving" v-model="form.is_giving" active-color="#13ce66" :active-value="1" :inactive-value="0"></el-switch>
  395. <span>优惠券允许转赠给好友</span>
  396. <el-tooltip effect="dark" content="转赠的优惠券被领取后不扣减优惠券库存,只做所属权的转移" placement="top">
  397. <i class="el-icon-question" style="font-size: 20px;color: #858585 ;"></i>
  398. </el-tooltip>
  399. </div>
  400. </el-form-item>
  401. <el-form-item label="领取人限制" prop="is_member">
  402. <div>
  403. <el-radio v-model="form.is_member" :label="0">不限制,所有人可领</el-radio>
  404. <el-radio v-model="form.is_member" :label="1">指定会员等级可领取</el-radio>
  405. </div>
  406. <div v-if="form.is_member==1">
  407. <el-checkbox :indeterminate="isIndeterminate" v-model="member_check_all" @change="handleCheckAllChange">全选</el-checkbox>
  408. <el-checkbox-group v-model="member_level_limits" @change="handleCheckedMemberChange">
  409. <el-checkbox v-for="(item, key) in member_levels" :label="item.level" :key="key">{{item.name}}</el-checkbox>
  410. </el-checkbox-group>
  411. </div>
  412. </el-form-item>
  413. <div class="coupon-model-title">
  414. 奖励规则
  415. </div>
  416. <el-form-item label="奖励使用者" prop="is_consume_reward">
  417. <div>
  418. <el-switch :disabled="!is_can_edit" v-model="form.is_consume_reward" active-color="#13ce66" :active-value="1" :inactive-value="0"></el-switch>
  419. <span style="color: #999; font-size: 14px;line-height:24px;margin-left: 4px;">会员使用优惠券获得奖励</span>
  420. </div>
  421. <div class="coupon-award" v-if="form.is_consume_reward==1">
  422. <div>
  423. <span>余额</span>
  424. <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'balance','double','consume_reward')" @blur="blurNumForm('consume_reward','balance')" v-model="consume_reward.balance" autocomplete="off">
  425. <template slot="append">元</template>
  426. </el-input>
  427. </div>
  428. <div>
  429. <span>积分</span>
  430. <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'score','double','consume_reward')" @blur="blurNumForm('consume_reward','score')" v-model="consume_reward.score" autocomplete="off">
  431. <template slot="append">分</template>
  432. </el-input>
  433. </div>
  434. <!-- <div>-->
  435. <!-- <span>红包</span>-->
  436. <!-- <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'red_packet','double','consume_reward')" @blur="blurNumForm('consume_reward','red_packet')" v-model="consume_reward.red_packet" autocomplete="off">-->
  437. <!-- <template slot="append">元</template> -->
  438. <!-- </el-input>-->
  439. <!-- </div>-->
  440. </div>
  441. </el-form-item>
  442. <el-form-item label="奖励转赠者" prop="is_giving_reward">
  443. <div>
  444. <el-switch :disabled="!is_can_edit || form.is_giving == 0" v-model="form.is_giving_reward" active-color="#13ce66" :active-value="1" :inactive-value="0"></el-switch>
  445. <span style="color: #999; font-size: 14px;line-height:24px;margin-left: 4px;">会员使用优惠券转赠者获得奖励</span>
  446. </div>
  447. <div class="coupon-award" v-if="form.is_giving_reward==1">
  448. <div>
  449. <span>余额</span>
  450. <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'balance','double','giving_reward')" @blur="blurNumForm('giving_reward','balance')" v-model="giving_reward.balance" autocomplete="off">
  451. <template slot="append">元</template>
  452. </el-input>
  453. </div>
  454. <div>
  455. <span>积分</span>
  456. <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'score','double','giving_reward')" @blur="blurNumForm('giving_reward','score')" v-model="giving_reward.score" autocomplete="off">
  457. <template slot="append">分</template>
  458. </el-input>
  459. </div>
  460. <!-- <div>-->
  461. <!-- <span>红包</span>-->
  462. <!-- <el-input size="small" style="width: 30%;margin: 0 10px;" @input="numForm($event,'red_packet','double','giving_reward')" @blur="blurNumForm('giving_reward','red_packet')" v-model="giving_reward.red_packet" autocomplete="off">-->
  463. <!-- <template slot="append">元</template>-->
  464. <!-- </el-input>-->
  465. <!-- </div>-->
  466. </div>
  467. </el-form-item>
  468. </div>
  469. </el-form>
  470. <!--指定商品分类-->
  471. <el-dialog title="已指定商品类别" :visible.sync="catsListVisible" width="35%">
  472. <el-tree style="margin-left:30px" :indent="40" :data="cats_list" show-checkbox default-expand-all :default-checked-keys="cat_id_list" node-key="id" ref="tree" highlight-current :props="defaultProps"></el-tree>
  473. <div slot="footer" class="dialog-footer">
  474. <el-button plain type="submit" @click="catsListVisible = false">取消</el-button>
  475. <el-button plain type="primary" @click="catsAdd">确定</el-button>
  476. </div>
  477. </el-dialog>
  478. <!-- 添加商品弹窗 -->
  479. <el-dialog title="添加商品" :visible.sync="goodsAddVisible" append-to-body>
  480. <el-form>
  481. <el-form-item>
  482. <el-input size="small" v-model="keyword" autocomplete="off" placeholder="商品名称"
  483. style="width: 40%"></el-input>
  484. <el-button size="small" :loading="btnLoading"
  485. @click="search('store/client/coupon/search-goods','goods')">查找商品
  486. </el-button>
  487. <el-button size="small" style="float:right" @click="goodsBatchAdd">批量添加</el-button>
  488. </el-form-item>
  489. </el-form>
  490. <el-table :data="goods_list" @selection-change="selsChange" style="width: 100%">
  491. <el-table-column type="selection" width="55"></el-table-column>
  492. <el-table-column prop="goods_id" label="ID" width="80"></el-table-column>
  493. <el-table-column prop="cover_pic" label="商品图" width="180">
  494. <template slot-scope="scope">
  495. <com-image mode="aspectFill" :src="scope.row.cover_pic"></com-image>
  496. </template>
  497. </el-table-column>
  498. <el-table-column prop="name" label="商品名称">
  499. <template slot-scope="scope">
  500. <com-ellipsis :line="2">{{scope.row.goods_name}}</com-ellipsis>
  501. </template>
  502. </el-table-column>
  503. <el-table-column label="操作">
  504. <template slot-scope="scope">
  505. <el-button v-if="goods_id_list.indexOf(scope.row.goods_id) == -1" plain size="mini"
  506. type="primary" @click="goodsAdd(scope.$index, scope.row.goods_id)">添加
  507. </el-button>
  508. <el-button v-else plain size="mini" type="primary" disabled>已添加</el-button>
  509. </template>
  510. </el-table-column>
  511. </el-table>
  512. <div slot="footer" class="dialog-footer">
  513. <el-pagination
  514. v-if="pagination"
  515. background
  516. @current-change="pageChange"
  517. layout="prev, pager, next"
  518. :page-count="pageCount">
  519. </el-pagination>
  520. </div>
  521. </el-dialog>
  522. </el-card>
  523. </div>
  524. <script>
  525. const app = new Vue({
  526. el: '#app',
  527. data() {
  528. var check_min_price = (rule, value, callback) => {
  529. if (!value) {
  530. return callback(new Error('最低消费金额不能为空'));
  531. }
  532. if (value <= 0) {
  533. return callback(new Error('最低消费金额必须大于0'));
  534. }
  535. callback();
  536. };
  537. var check_sub_price = (rule, value, callback) => {
  538. if (this.form.type == 2) {
  539. if (!value) {
  540. return callback(new Error('优惠金额不能为空'));
  541. }
  542. if (value <= 0) {
  543. return callback(new Error('优惠金额必须大于0'));
  544. }
  545. if (value >= this.form.min_price) {
  546. return callback(new Error('优惠减免金额必须小于等于优惠券使用门槛金额'));
  547. }
  548. callback();
  549. } else {
  550. callback();
  551. }
  552. };
  553. var check_discount = (rule, value, callback) => {
  554. if (this.form.type == 1) {
  555. let foldMinPrice = Number(this.$refs.fold_min_price.value);
  556. let isDiscountLimit = Number(this.$refs.is_discount_limit.value);
  557. let foldDiscountLimit = Number(this.$refs.fold_discount_limit.value);
  558. if(!foldMinPrice || foldMinPrice <= 0){
  559. return callback(new Error('请输入消费金额活或消费金额不能小于等于0'));
  560. }
  561. if (!value) {
  562. return callback(new Error('请输入优惠折扣'));
  563. }
  564. if (value < 1 || value > 9.9) {
  565. return callback(new Error('折扣券:优惠券折扣必须大于等于1, 且最大不能超过9.9优惠券折扣最多支持一位小数'));
  566. }
  567. if(isDiscountLimit == 1 && (!foldDiscountLimit || foldDiscountLimit <= 0)){
  568. return callback(new Error('请输入最多优惠金额活最多优惠不能小于等于0'));
  569. }
  570. callback();
  571. } else {
  572. let minPrice = Number(this.$refs.min_price.value);
  573. let subPrice = Number(this.$refs.sub_price.value);
  574. console.info(minPrice,subPrice,Boolean(minPrice));
  575. if(!minPrice || minPrice <= 0){
  576. return callback(new Error('请输入消费金额或消费金额不能小于等于0'));
  577. }
  578. if(!subPrice || subPrice <= 0){
  579. return callback(new Error('请输入满减金额或满减金额不能小于等于0'));
  580. }
  581. if(subPrice > minPrice){
  582. return callback(new Error('满减金额不能大于消费金额'));
  583. }
  584. callback();
  585. }
  586. };
  587. var check_discount_limit = (rule, value, callback) => {
  588. if (this.form.type == 1) {
  589. if (this.is_discount_limit && !this.form.discount_limit) {
  590. return callback(new Error('请填写优惠限额'));
  591. }
  592. callback();
  593. } else {
  594. callback();
  595. }
  596. };
  597. var check_expire_type = (rule, value, callback) => {
  598. if (this.form.expire_type == 1) {
  599. if(!this.form.expire_day){
  600. return callback(new Error('请填写有效天数'));
  601. } else if(Number(this.form.expire_day) < 1){
  602. return callback(new Error('领券后立即生效,有效天数不能小于1'));
  603. }
  604. callback();
  605. } else if (this.form.expire_type == 2 && !this.expire_time.length) {
  606. return callback(new Error('请选择有效期起止时间'));
  607. } else if (this.form.expire_type == 3) {
  608. if (!this.form.effect_days) {
  609. return callback(new Error('请填写生效的延后天数'));
  610. }
  611. if (!this.form.effect_expire_days) {
  612. return callback(new Error('请填写有效天数'));
  613. } else if(Number(this.form.effect_expire_days) < 1){
  614. return callback(new Error('领券后立即生效,有效天数不能小于1'));
  615. }
  616. callback();
  617. } else {
  618. callback();
  619. }
  620. };
  621. var check_appoint_type = (rule, value, callback) => {
  622. if (this.form.appoint_type == 2 && !this.goods_id_list) {
  623. return callback(new Error('请选择指定商品'));
  624. } else if (this.form.appoint_type == 1 && !this.cat_id_list.length) {
  625. return callback(new Error('请选择指定的商品分类'));
  626. } else if (this.form.appoint_type == 4 && !this.form.store_id) {
  627. return callback(new Error('请选择指定的门店'));
  628. } else {
  629. callback();
  630. }
  631. };
  632. var check_is_member = (rule, value, callback) => {
  633. if (this.form.is_member == 1 && !this.member_level_limits.length) {
  634. return callback(new Error('请选择会员等级'));
  635. } else {
  636. callback();
  637. }
  638. };
  639. var total_count_t = (rule, value, callback) => {
  640. if(value <= 0){
  641. return callback(new Error('发放总数不能小于1'));
  642. }
  643. callback();
  644. };
  645. var remind_days = (rule, value, callback) => {
  646. if(this.form.is_remind == 1 && value <= 0){
  647. return callback(new Error('过期前提醒天数不能小于 0'));
  648. }
  649. callback();
  650. };
  651. return {
  652. goods_status: -1,
  653. //添加商品
  654. pagination: null,
  655. pageCount: 1,
  656. currPage: 1,
  657. goodsListVisible: false,
  658. goodsAddVisible: false,
  659. goodsBatchList: [],
  660. //添加分类
  661. catsListVisible: false,
  662. defaultProps: {
  663. children: 'child',
  664. label: 'name'
  665. },
  666. activeName: 'first',
  667. form: {
  668. store_id: 0,
  669. name: '',
  670. type: 2,
  671. discount: '',
  672. discount_limit: '',
  673. min_price: '',
  674. sub_price: '',
  675. total_count: 9999,
  676. sort: 99,
  677. expire_type: 1,
  678. expire_day: 30,
  679. effect_expire_days: 30,
  680. begin_at: 0,
  681. end_at: 0,
  682. appoint_type: 3,
  683. rule: '',
  684. is_remind: 0,
  685. remind_days: 3,
  686. effect_days: 3,
  687. is_receive_limit: 1,
  688. receive_count: 1,
  689. is_member: 0,
  690. is_original_use: 0,
  691. is_public_receive: 1,
  692. is_giving: 0,
  693. is_giving_reward: 0,
  694. is_consume_reward: 0,
  695. is_open_screen: 0,
  696. goods_id_list: [],
  697. },
  698. btnLoading: false,
  699. submitLoading: false,
  700. loading: false,
  701. cats_list: [],
  702. goods_list: [],
  703. cat: [],
  704. keyword: null,
  705. time: [],
  706. goods: [],
  707. cat_id: null,
  708. goods_id: null,
  709. cat_id_list: [
  710. // [21, 69],
  711. // [21, 70],
  712. // [21, 228, 229]
  713. ], // 已经选中的商品分类
  714. checkAll: false,
  715. couponMember: [],
  716. membersList: [],
  717. isIndeterminate: false,
  718. FormRules: {
  719. name: [{ required: true, message: '优惠券名称不能为空', trigger: 'blur' }],
  720. type: [{ required: true, message: '请选择优惠券类型', trigger: 'blur' }],
  721. // total_count:[{required: true, message: '请填写优惠券数量', trigger: 'blur'}],
  722. // min_price: [{ required: true, message: '最低消费金额不能为空', trigger: 'blur' }],
  723. min_price: [{ validator: check_min_price, trigger: 'blur' }, ],
  724. sub_price: [{ validator: check_sub_price, trigger: 'blur' }, ],
  725. discount: [{required: true,validator: check_discount, trigger: 'blur' },],
  726. discount_limit: [{required: true,validator: check_discount_limit, trigger: 'blur' }],
  727. expire_type: [{ required: true, message: '请选择优惠券生效方式', trigger: 'blur'}, {validator: check_expire_type, trigger: 'blur' }],
  728. // expire_day: [{ required: true, message: '优惠券有效天数不能为空', trigger: 'blur' }],
  729. appoint_type: [{ required: true, message: '请选择优惠券使用场景', trigger: 'blur'}, {validator: check_appoint_type, trigger: 'blur' }],
  730. total_count: [{ required: true, message: '发放总数不能为空', trigger: 'blur' },{ validator: total_count_t, trigger: 'blur' }],
  731. receive_count: [{ required: true, message: '请填写每人可领取的数量', trigger: 'blur' }],
  732. sort: [{ required: true, pattern: /^[0-9]\d{0,8}$/, message: '排序必须在9位整数内' }],
  733. remind_days: [{validator: remind_days, trigger: 'blur' }],
  734. },
  735. receive: [],
  736. isScanCodePayShow: false,
  737. activeNames: true,
  738. is_discount_limit: 0, // 是否限制折扣上限
  739. member_level_limits: [], // 限制领取的等级
  740. member_levels: [], // 全部的会员等级
  741. member_check_all: false, // 会员全选
  742. goods_id_list: [], // 已选中的商品 id
  743. selected_goods: [], // 已经选中的商品信息
  744. expire_time: [], // 有效期起止时间
  745. giving_reward: { // 转赠奖励
  746. balance: 0, score: 0, red_packet: 0
  747. },
  748. consume_reward: { // 使用奖励
  749. balance: 0, score: 0, red_packet: 0
  750. },
  751. expire_day: 1, // 有效期天数
  752. is_can_change_time: false, // 是否可以更改时间
  753. is_can_edit: true, // 整个页面是否可以编辑
  754. coupon_id: 0, // 优惠券id
  755. coupon_name: '', // 暂存自动生成的优惠券名称
  756. storeList: [], // 门店列表
  757. selectedStores: [], // 已选中门店
  758. storeAddVisible: false,
  759. };
  760. },
  761. methods: {
  762. enter(index) {
  763. this.goods_status = index;
  764. },
  765. leave() {
  766. this.goods_status = -1;
  767. },
  768. catDestroy(index) {
  769. this.cat_id_list.splice(index, 1);
  770. this.form.cat.splice(index, 1);
  771. },
  772. handleCheckAllChange(value) {
  773. if (value) {
  774. let checked_levels = [];
  775. let number = this.member_levels.length;
  776. for (let i = 0; i < number; i++) {
  777. checked_levels.push(this.member_levels[i].level);
  778. }
  779. this.member_level_limits = checked_levels;
  780. } else {
  781. this.member_level_limits = [];
  782. }
  783. this.isIndeterminate = false;
  784. },
  785. handleCheckedMemberChange(value) {
  786. let checkedCount = value.length;
  787. this.member_check_all = checkedCount === this.member_levels.length;
  788. this.isIndeterminate = checkedCount > 0 && checkedCount < this.member_levels.length;
  789. },
  790. //分页
  791. pageChange(page) {
  792. this.currPage = page;
  793. this.search('coupon/coupon/search-goods', 'goods', page);
  794. },
  795. storePageChange(page) {
  796. this.currPage = page;
  797. },
  798. catsAdd() {
  799. let cat_id_list = this.$refs.tree.getCheckedKeys();
  800. this.cat_id_list = cat_id_list;
  801. let array = [];
  802. this.cats.map(v => {
  803. if (cat_id_list.indexOf(v.id) != -1) {
  804. array.push(v);
  805. }
  806. v.child.map(v1 => {
  807. if (cat_id_list.indexOf(v1.id) != -1) {
  808. array.push(v1);
  809. }
  810. v1.child.map(v2 => {
  811. if (cat_id_list.indexOf(v2.id) != -1) {
  812. array.push(v2);
  813. }
  814. })
  815. })
  816. })
  817. this.form.cat = array;
  818. this.$message({
  819. message: '添加成功',
  820. type: 'success'
  821. });
  822. this.catsListVisible = false;
  823. },
  824. //指定商品
  825. goodsDestroy(index) {
  826. this.goods_id_list.splice(index, 1);
  827. this.selected_goods.splice(index, 1);
  828. },
  829. selsChange(row) {
  830. this.goodsBatchList = row;
  831. },
  832. goodsBatchAdd() {
  833. this.goodsBatchList.forEach(goods => {
  834. this.setGoods(goods);
  835. })
  836. this.goodsAddVisible = false;
  837. },
  838. goodsAdd(index, row) {
  839. let goods = this.goods_list[index];
  840. this.setGoods(goods);
  841. this.goodsAddVisible = false;
  842. },
  843. storeAdd(index, row) {
  844. let store = this.storeList[index];
  845. this.form.store_id = store.id;
  846. this.selectedStores = [];
  847. this.selectedStores.push(store);
  848. this.storeAddVisible = false;
  849. },
  850. storeDestroy(index) {
  851. this.form.store_id = 0;
  852. this.selectedStores = [];
  853. },
  854. setGoods(goods) {
  855. let sentinel = true;
  856. this.selected_goods.forEach(v => {
  857. if (v.id == goods.goods_id) {
  858. sentinel = false;
  859. }
  860. })
  861. if (sentinel) {
  862. this.selected_goods.push(goods);
  863. this.goods_id_list.push(goods.goods_id);
  864. // this.$message({
  865. // message: '添加成功',
  866. // type: 'success'
  867. // });
  868. // this.goodsAddVisible = false;
  869. }
  870. },
  871. //分类
  872. catsDestroy(index, row) {
  873. this.form.cat.splice(index, 1);
  874. },
  875. // 返回上一页
  876. Cancel() {
  877. window.history.go(-1)
  878. },
  879. // 点击获取商品分类列表或者商品列表
  880. search(url, attr, page = 1) {
  881. this.btnLoading = true;
  882. request({
  883. params: {
  884. r: url,
  885. keyword: this.keyword,
  886. page: this.currPage,
  887. limit: 7,
  888. },
  889. }).then(e => {
  890. this.btnLoading = false;
  891. if (e.data.code == 0) {
  892. if (attr == 'cats') {
  893. this.cats_list = e.data.data.list;
  894. } else if (attr == 'goods') {
  895. this.goods_list = e.data.data.list;
  896. this.pagination = e.data.data.pagination;
  897. this.pageCount = e.data.data.page_count;
  898. }
  899. }
  900. }).catch(e => {
  901. this.btnLoading = false;
  902. });
  903. },
  904. // 提交数据
  905. onSubmit() {
  906. let self = this;
  907. if (self.form.is_giving) {
  908. self.form.is_giving = 1;
  909. } else {
  910. self.form.is_giving = 0;
  911. }
  912. if (self.form.is_original_use) {
  913. self.form.is_original_use = 1;
  914. } else {
  915. self.form.is_original_use = 0;
  916. }
  917. if (self.form.is_remind) {
  918. self.form.is_remind = 1;
  919. } else {
  920. self.form.is_remind = 0;
  921. self.form.remind_days = 0;
  922. }
  923. if (!self.form.discount) {
  924. self.form.discount = 0;
  925. }
  926. if (!self.form.discount_limit || self.form.discount_limit < 0) {
  927. self.form.discount_limit = 0;
  928. }
  929. if (!self.form.min_price) {
  930. self.form.min_price = 0;
  931. }
  932. if (!self.form.sub_price) {
  933. self.form.sub_price = 0;
  934. }
  935. if (self.form.is_remind == 1 && self.form.remind_days <= 0) {
  936. self.$message.error('过期前提醒天数不能小于 0');
  937. return false;
  938. }
  939. if (getQuery('is_copy')) {
  940. self.form.id = 0;
  941. }
  942. if(self.form.expire_type == 3){
  943. self.form.expire_day = self.form.effect_expire_days;
  944. }
  945. self.$refs.form.validate((valid, obj) => {
  946. if (valid) {
  947. self.submitLoading = true;
  948. request({
  949. params: {
  950. r: 'store/client/coupon/edit',
  951. },
  952. data: {
  953. coupon_info: self.form,
  954. member_level_limits: self.member_level_limits,
  955. goods_id_list: self.goods_id_list,
  956. giving_reward: self.giving_reward,
  957. consume_reward: self.consume_reward,
  958. category_ids: self.cat_id_list,
  959. },
  960. method: 'post'
  961. }).then(e => {
  962. self.submitLoading = false;
  963. if (e.data.code === 0) {
  964. self.$message({
  965. message: e.data.msg,
  966. type: 'success'
  967. });
  968. setTimeout(function() {
  969. navigateTo({ r: 'store/client/coupon/index' });
  970. }, 500);
  971. } else {
  972. self.$message.error(e.data.msg);
  973. }
  974. }).catch(e => {
  975. self.submitLoading = false;
  976. console.log(e);
  977. self.$message.error(e.data.msg)
  978. });
  979. } else {
  980. console.log('validate result: ', obj);
  981. self.loading = false;
  982. }
  983. });
  984. },
  985. delCoupon(id){
  986. this.$confirm('确认删除该记录吗?', '提示', {
  987. type: 'warning'
  988. }).then(() => {
  989. this.loading = true;
  990. let para = {
  991. id: id
  992. };
  993. request({
  994. params: {
  995. r: 'store/client/coupon/del'
  996. },
  997. data: para,
  998. method: 'post'
  999. }).then(e => {
  1000. this.loading = false;
  1001. if (e.data.code === 0) {
  1002. const h = this.$createElement;
  1003. this.$message({
  1004. message: '删除成功',
  1005. type: 'success'
  1006. });
  1007. setTimeout(() => {
  1008. navigateTo({ r: 'store/client/coupon/index'});
  1009. }, 300);
  1010. } else {
  1011. this.$alert(e.data.msg, '提示', {
  1012. confirmButtonText: '确定'
  1013. })
  1014. }
  1015. }).catch(e => {
  1016. this.$alert(e.data.msg, '提示', {
  1017. confirmButtonText: '确定'
  1018. })
  1019. });
  1020. })
  1021. },
  1022. //获取列表
  1023. getList() {
  1024. this.loading = true;
  1025. let self = this;
  1026. request({
  1027. params: {
  1028. r: 'store/client/coupon/edit',
  1029. coupon_id: this.coupon_id,
  1030. },
  1031. }).then(e => {
  1032. console.log(e);
  1033. self.loading = false;
  1034. if (e.data.code == 0) {
  1035. if (this.coupon_id) {
  1036. self.form = e.data.data.coupon_info;
  1037. if (self.form.expire_type == 2) {
  1038. self.expire_time.push(self.form.begin_at*1000);
  1039. self.expire_time.push(self.form.end_at*1000);
  1040. } else if (self.form.expire_type == 3) {
  1041. self.form.effect_expire_days = self.form.expire_day;
  1042. }
  1043. if (e.data.data.coupon_info.type == 1 && e.data.data.coupon_info.discount_limit) {
  1044. self.is_discount_limit = 1;
  1045. }
  1046. if (e.data.data.member_level_limits) {
  1047. self.member_level_limits = e.data.data.member_level_limits;
  1048. }
  1049. if (e.data.data.good_lists) {
  1050. self.selected_goods = e.data.data.good_lists;
  1051. }
  1052. if (e.data.data.giving_rewards) {
  1053. self.giving_reward = e.data.data.giving_rewards;
  1054. }
  1055. if (e.data.data.consume_rewards) {
  1056. self.consume_reward = e.data.data.consume_rewards;
  1057. }
  1058. e.data.data.checked_categorys.forEach(v => {
  1059. self.cat_id_list.push(v[0])
  1060. })
  1061. if (e.data.data.goods_id_list) {
  1062. this.goods_id_list = e.data.data.goods_id_list;
  1063. }
  1064. }
  1065. self.member_levels = e.data.data.member_levels;
  1066. self.cats_list = e.data.data.good_category;
  1067. } else {
  1068. self.$message.error(e.data.msg);
  1069. }
  1070. if (self.status == 3 || self.status == 4) {
  1071. // 锁定整个页面,不可修改
  1072. self.is_can_edit = false;
  1073. self.$nextTick(() => {
  1074. let domArr = document.getElementsByTagName('input');
  1075. let domTextarea = document.getElementsByTagName('textarea');
  1076. let conponType = document.getElementsByClassName('coupon-type');
  1077. for(let i = 0; i < domArr.length;i++){
  1078. domArr[i].setAttribute("disabled",true);
  1079. domArr[i].parentNode.classList.add("is-disabled");
  1080. }
  1081. for(let i = 0; i < domTextarea.length;i++){
  1082. domTextarea[i].setAttribute("disabled",true);
  1083. domTextarea[i].parentNode.classList.add("is-disabled");
  1084. }
  1085. for (let i = 0; i < conponType.length; i++) {
  1086. conponType[i].setAttribute('style', 'cursor:not-allowed');
  1087. }
  1088. })
  1089. }
  1090. }).catch(e => {
  1091. console.log(e);
  1092. this.$message.error('网络错误');
  1093. });
  1094. },
  1095. // 选中时间处理方法
  1096. select_expire_time(date) {
  1097. console.log(date,"dateUUUU");
  1098. this.form.begin_at = parseInt(date[0] / 1000);
  1099. this.form.end_at = parseInt(date[1] / 1000);
  1100. },
  1101. // 优惠限额选中/取消处理方法
  1102. discount_limit_change(val) {
  1103. if (!val) {
  1104. this.form.discount_limit = 0;
  1105. }
  1106. this.handleDiscountLimit(this.form.discount_limit);
  1107. },
  1108. // 选中优惠券类型
  1109. selectType(type) {
  1110. if (this.is_can_edit) {
  1111. let name = '';
  1112. this.form.type = type;
  1113. this.form.name = '';
  1114. if (!this.form.min_price) {
  1115. this.form.min_price = '';
  1116. } else {
  1117. name += '消费满' + this.form.min_price + '元';
  1118. }
  1119. if (!this.form.sub_price) {
  1120. this.form.sub_price = '';
  1121. } else {
  1122. if (this.form.type == 2) name += '优惠' + this.form.sub_price + '元';
  1123. }
  1124. if (!this.form.discount) {
  1125. this.form.discount = '';
  1126. } else {
  1127. if (this.form.type == 1) name += '打' + this.form.discount + '折';
  1128. }
  1129. if (!this.form.discount_limit) {
  1130. this.form.discount_limit = '';
  1131. } else {
  1132. if (this.form.is_discount_limit && this.form.type == 1) {
  1133. name += '最多优惠' + this.form.discount_limit + '元';
  1134. }
  1135. }
  1136. this.form.name = name;
  1137. this.is_discount_limit = false;
  1138. }
  1139. },
  1140. // 最低消费金额值改变
  1141. handleMinPrice(val) {
  1142. if (!val) {
  1143. return ;
  1144. }
  1145. let coupon_name = '';
  1146. coupon_name = '消费满' + val + '元';
  1147. if (this.form.type == 1) {
  1148. // 折扣券
  1149. if (this.form.discount) {
  1150. coupon_name += '打' . this.form.discount + '折'
  1151. }
  1152. } else {
  1153. // 满减券
  1154. if (this.form.sub_price) {
  1155. coupon_name += '减' + this.form.sub_price + '元';
  1156. }
  1157. }
  1158. this.form.name = coupon_name;
  1159. },
  1160. // 满减券减免金额 / 折扣券折扣
  1161. handleSubPrice(val) {
  1162. let min_price = this.form.min_price;
  1163. let coupon_name = '消费满' + min_price + '元';
  1164. if (this.form.type == 1) {
  1165. // 折扣券
  1166. if (this.form.discount) {
  1167. coupon_name += '打' + this.form.discount + '折';
  1168. }
  1169. } else {
  1170. // 满减券
  1171. if (min_price) {
  1172. coupon_name += '减' + this.form.sub_price + '元';
  1173. }
  1174. }
  1175. this.form.name = coupon_name;
  1176. },
  1177. // 最高优惠金额
  1178. handleDiscountLimit(val) {
  1179. let coupon_name = '';
  1180. if (this.form.type == 1 && this.form.min_price && this.form.discount) {
  1181. coupon_name = '消费满' + this.form.min_price + '元打 ' + this.form.discount + '折';
  1182. // 折扣券
  1183. if (this.is_discount_limit && val) {
  1184. coupon_name += ', 最高优惠' + val + '元';
  1185. }
  1186. this.form.name = coupon_name;
  1187. }
  1188. },
  1189. // 数值类型不让输入小于0
  1190. numForm(val,key,type = 'int',valueKey){
  1191. console.info(val,type)
  1192. let reg = /^[0-9]*$/;
  1193. let point = val.indexOf(".");
  1194. let regT = /[0-9]+|\./;
  1195. let tIndex = -1;
  1196. for(let j = 0;j < val.length; j++){
  1197. if(!regT.test(val[j])){
  1198. tIndex = j;
  1199. break;
  1200. }
  1201. }
  1202. if(tIndex != -1){
  1203. val = val.substr(0,tIndex);
  1204. }
  1205. if(val < 0){
  1206. val = 0;
  1207. }else if(!reg.test(val) && type == 'int'){
  1208. val = val.substr(0,point);
  1209. } else if(type == 'double'){
  1210. let doubleReg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
  1211. let pointIndex = val.lastIndexOf(".");
  1212. if(pointIndex != -1 && point != pointIndex){
  1213. val = val.substr(0,pointIndex)
  1214. }
  1215. if(pointIndex != -1 && !doubleReg.test(val) && pointIndex != val.length){
  1216. val = val.substr(0,point + 3);
  1217. }
  1218. }
  1219. //
  1220. if(valueKey){
  1221. this[valueKey][key] = val;
  1222. }else{
  1223. this.form[key] = val;
  1224. }
  1225. },
  1226. blurNumForm(valueKey,key){
  1227. let val = this[valueKey][key];
  1228. if(!val){
  1229. this[valueKey][key] = 0;
  1230. }
  1231. },
  1232. //
  1233. updateGiving(val){
  1234. if(val == 0 && this.form.is_giving_reward == 1){
  1235. this.form.is_giving_reward = 0;
  1236. }
  1237. },
  1238. // 商品视频
  1239. videoUrl(e) {
  1240. if (e.length) {
  1241. this.form.video_url = e[0].url;
  1242. }
  1243. this.$forceUpdate();
  1244. },
  1245. },
  1246. mounted: function() {
  1247. this.coupon_id = getQuery('coupon_id');
  1248. let is_copy = getQuery('is_copy');
  1249. if (this.coupon_id && !is_copy) {
  1250. this.is_can_change_time = true;
  1251. }
  1252. this.status = getQuery('status');
  1253. if (this.status == 3 || this.status == 4) {
  1254. this.is_can_edit = false;
  1255. }
  1256. this.search('store/client/coupon/search-goods', 'goods');
  1257. this.getList();
  1258. },
  1259. })
  1260. </script>