add-edit.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-select');
  4. ?>
  5. <style>
  6. .el-form-item {
  7. margin-bottom: 15px;
  8. }
  9. .table-body {
  10. padding: 20px;
  11. background-color: #fff;
  12. }
  13. .input-item {
  14. display: inline-block;
  15. width: 250px;
  16. margin: 0 0 20px;
  17. }
  18. .input-item .el-input__inner {
  19. border-right: 0;
  20. }
  21. .input-item .el-input__inner:hover {
  22. border: 1px solid #dcdfe6;
  23. border-right: 0;
  24. outline: 0;
  25. }
  26. .input-item .el-input__inner:focus {
  27. border: 1px solid #dcdfe6;
  28. border-right: 0;
  29. outline: 0;
  30. }
  31. .input-item .el-input-group__append {
  32. background-color: #fff;
  33. border-left: 0;
  34. width: 10%;
  35. padding: 0;
  36. }
  37. .input-item .el-input-group__append .el-button {
  38. padding: 0;
  39. }
  40. .input-item .el-input-group__append .el-button {
  41. margin: 0;
  42. }
  43. /* .table-body .el-button {
  44. padding: 0 !important;
  45. border: 0;
  46. margin: 0 5px;
  47. } */
  48. .form-body {
  49. background-color: #fff;
  50. /* margin-bottom: 20px; */
  51. }
  52. .el-tabs__header {
  53. background-color: #fff;
  54. }
  55. .el-tabs__item {
  56. width: 100px;
  57. text-align: center;
  58. }
  59. .check-group {
  60. font-size: 14px !important;
  61. }
  62. .check-group .el-col {
  63. display: flex;
  64. }
  65. .check-group .el-input {
  66. margin: 0 5px;
  67. }
  68. .check-group .el-col .el-checkbox {
  69. display: flex;
  70. align-items: center;
  71. }
  72. .check-group .el-col .el-input {
  73. width: 100px;
  74. }
  75. .check-group .el-col .el-input .el-input__inner {
  76. height: 30px;
  77. width: 100px;
  78. }
  79. .el-checkbox-group .el-col {
  80. margin-bottom: 10px;
  81. }
  82. </style>
  83. <div id="app" v-cloak>
  84. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;" style="min-width: 1000px;">
  85. <div slot="header">
  86. <el-breadcrumb separator="/">
  87. <el-breadcrumb-item>
  88. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'lucky-group/level/list'})">
  89. <!--mall/stock/level -->
  90. 拼团等级
  91. </span>
  92. </el-breadcrumb-item>
  93. <el-breadcrumb-item>{{titleName}}</el-breadcrumb-item>
  94. </el-breadcrumb>
  95. </div>
  96. <div class="table-body">
  97. <el-form label-width="110px" ref="ruleForm" :model="ruleForm" :rules="rules" v-loading="loading">
  98. <el-form-item label="等级权重" prop="level">
  99. <el-select size="small" class="select" v-model="ruleForm.level" placeholder="请选择等级">
  100. <!-- v-model="search.status" @change='toSearch' -->
  101. <el-option :key="index" :label="item.name" :value="item.level" v-for="(item, index) in weights" :disabled="item.disabled"></el-option>
  102. </el-select>
  103. </el-form-item>
  104. <el-form-item label="等级名称" prop="name">
  105. <el-input size="small" style="width: 300px;" v-model="ruleForm.name" placeholder='请输入等级名称'></el-input>
  106. </el-form-item>
  107. <br />
  108. <br />
  109. <el-form-item label="渠道奖励1" prop="team_commission">
  110. <!-- <div v-show="false">
  111. <el-radio v-model="ruleForm.is_percent_team" :label="1" size="small">百分比</el-radio>
  112. <el-radio v-model="ruleForm.is_percent_team" :label="0" size="small">固定金额</el-radio>
  113. </div> -->
  114. <el-input size="small" v-model="ruleForm.team_commission" onInput="value=toNumber(value,2)" placeholder="请输入渠道奖励" size="small" style="width: 300px;">
  115. <template slot="append">{{ruleForm.is_percent_team == 1?'%':'元'}}</template>
  116. </el-input>
  117. </el-form-item>
  118. <el-form-item label="平级奖励" prop="equal_commission">
  119. <!-- <div v-show="false">
  120. <el-radio v-model="ruleForm.is_percent_equal" :label="1" size="small">百分比</el-radio>
  121. <el-radio v-model="ruleForm.is_percent_equal" :label="0" size="small">固定金额</el-radio>
  122. </div> -->
  123. <el-input size="small" v-model="ruleForm.equal_commission" onInput="value=toNumber(value,2)" placeholder="请输入渠道奖佣金" size="small" style="width: 300px;">
  124. <template slot="append">{{ruleForm.is_percent_equal == 1?'%':'元'}}</template>
  125. </el-input>
  126. </el-form-item>
  127. <el-form-item label="越级奖" prop="over_commission">
  128. <el-input size="small" v-model="ruleForm.over_commission" onInput="value=toNumber(value,2)" placeholder="请输入渠道奖佣金" size="small" style="width: 300px;">
  129. <template slot="append">元</template>
  130. </el-input>
  131. </el-form-item>
  132. <el-form-item label="每日参团次数" prop="init_attend_times">
  133. <el-input size="small" type="number" v-model="ruleForm.init_attend_times" onchange="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" placeholder="请输入每日参团次数" size="small" style="width: 300px;">
  134. </el-input>
  135. </el-form-item>
  136. <br />
  137. <br />
  138. <el-form-item label="是否启用升级" prop="is_auto_upgrade">
  139. <el-switch v-model="ruleForm.is_auto_upgrade" :active-value="1" :inactive-value="0">
  140. </el-switch>
  141. </el-form-item>
  142. <template v-if="ruleForm.is_auto_upgrade == 1">
  143. <?php echo $tpl ?>
  144. </template>
  145. <br />
  146. <br />
  147. <el-form-item label="等级说明" prop="desc">
  148. <el-input type="textarea" v-model="ruleForm.desc" size="small" style="width: 300px;" placeholder='请输入权益说明'></el-input type="textarea">
  149. </el-form-item>
  150. </el-form>
  151. <el-button type="primary" size="small" style="margin-left: 20px;margin-top: 10px;" :loading="btnLoading" @click="saveFun">保存</el-button>
  152. </div>
  153. </el-card>
  154. </div>
  155. <script>
  156. const app = new Vue({
  157. el: '#app',
  158. data() {
  159. return {
  160. titleName: "添加拼团等级",
  161. loading: false,
  162. btnLoading: false,
  163. // goods_list: [],
  164. weights: [],
  165. options_list: <?= $source_list ?>,
  166. checkbox_list: <?= $checkbox_list ?>,
  167. ruleForm: {
  168. level: '',
  169. name: '',
  170. is_auto_upgrade: 0, //是否开启升级
  171. team_commission: 0, //渠道奖
  172. equal_commission: 0, //平级奖
  173. over_commission: 0, //越级奖
  174. desc: '', // 等级说明
  175. upgrade_type_goods: 0, //购买商品升级 0关,1开
  176. upgrade_type_condition: 0, //条件升级开关,0关,1开
  177. condition_type: 1, // 条件升级方式,1:满足其一可升级;2:满足所有才可升级
  178. goods_type: 1, // 购买商品升级类型,1:任意商品;2:指定商品
  179. buy_goods_type: 1, //购买商品升级时间场景【1订单完成 2支付】
  180. goods_ids: [], //指定商品集合
  181. init_attend_times: 3, // 每日参团次数
  182. checked_condition_values: <?= $key_arr ?>,
  183. checked_condition_keys: [], //对应条件的key
  184. goods_list: [],
  185. },
  186. rules: {
  187. level: {
  188. required: true,
  189. message: '请选择等级',
  190. trigger: 'blur'
  191. },
  192. name: {
  193. required: true,
  194. message: '请输入等级名称',
  195. trigger: 'blur'
  196. },
  197. // team_commission:{pattern:/^\d+(\.\d{0,2})?$/, message: '渠道奖佣金格式为数字,最多保留两位小数', trigger: 'blur'}
  198. },
  199. formLabelWidth: '110px',
  200. }
  201. },
  202. mounted: function() {
  203. if (getQuery('id')) {
  204. this.titleName = "编辑拼团等级";
  205. this.ruleForm.id = getQuery('id');
  206. this.loadData(getQuery('id')); //请求详情的数据
  207. } else {
  208. this.loadData();
  209. }
  210. },
  211. methods: {
  212. loadData(id) {
  213. // console.log('请求前的参数id='+id)
  214. this.loading = true;
  215. let params = {
  216. r: '/lucky-group/group-level/storage',
  217. id: id
  218. };
  219. request({
  220. params: params,
  221. method: 'get',
  222. }).then(e => {
  223. this.loading = false;
  224. // console.log('等级详情==', e)
  225. if (e.data.code == 0) {
  226. e.data.data.weights && (this.weights = e.data.data.weights);
  227. if (e.data.data.level_info.goods_ids.length > 0) {
  228. // this.goods_list = e.data.data.level_info.goods_list
  229. this.ruleForm.goods_type = 2
  230. }
  231. if (e.data.data.level_info.checked_condition_values.length) {
  232. this.ruleForm = e.data.data.level_info;
  233. } else {
  234. let checked_condition_values = this.ruleForm.checked_condition_values;
  235. this.ruleForm = e.data.data.level_info;
  236. this.ruleForm.checked_condition_values = checked_condition_values;
  237. }
  238. } else {
  239. this.$message.error(e.data.msg)
  240. }
  241. }).catch(e => {
  242. this.loading = false;
  243. });
  244. },
  245. goodsSelect(param) {
  246. console.log('kkkkk: ', this.ruleForm);
  247. for (let j in param) {
  248. let item = param[j];
  249. if (this.ruleForm.goods_ids.length >= 99) {
  250. this.$message.error('指定商品不能大于99个');
  251. return;
  252. }
  253. let flag = true;
  254. for (let i in this.ruleForm.goods_ids) {
  255. if (this.ruleForm.goods_ids[i] == param[j].id) {
  256. flag = false;
  257. break;
  258. }
  259. }
  260. if (flag) {
  261. this.ruleForm.goods_ids.push(param[j].id);
  262. this.ruleForm.goods_list.push({
  263. id: param[j].id,
  264. name: param[j].goods_name,
  265. cover_pic: param[j].cover_pic,
  266. });
  267. }
  268. }
  269. },
  270. deleteGoods(index) {
  271. this.ruleForm.goods_list.splice(index, 1);
  272. this.ruleForm.goods_ids.splice(index, 1);
  273. },
  274. saveFun() {
  275. if (this.ruleForm.is_auto_upgrade == 1 && this.ruleForm.upgrade_type_goods == 1 && this.ruleForm.goods_type == 2 && !this.ruleForm.goods_ids.length) {
  276. return this.$message.error("请选择商品");
  277. }
  278. // 升级条件验证
  279. // console.log(this.ruleForm);
  280. try {
  281. if (this.ruleForm.is_auto_upgrade == 1 && this.ruleForm.upgrade_type_condition == 1) {
  282. // console.log(this.ruleForm.checked_condition_keys, this.ruleForm.checked_condition_values);return null;
  283. if (this.ruleForm.checked_condition_keys.length) {
  284. var checked_condition_values = [];
  285. for (key in this.ruleForm.checked_condition_values) {
  286. checked_condition_values[this.ruleForm.checked_condition_values[key].key] = this.ruleForm.checked_condition_values[key].value
  287. }
  288. for (index in this.ruleForm.checked_condition_keys) {
  289. let i = this.ruleForm.checked_condition_keys[index];
  290. if (checked_condition_values[i]) {
  291. for (j in checked_condition_values[i]) {
  292. if (!checked_condition_values[i][j]) {
  293. throw '请完善所选择的第 ' + (parseInt(index) + 1) + ' 个条件';
  294. }
  295. }
  296. }
  297. }
  298. } else {
  299. throw '请完善升级条件';
  300. }
  301. }
  302. } catch (error) {
  303. this.$message.error(error);
  304. return false;
  305. }
  306. /* let checked_condition_keys = this.ruleForm.checked_condition_keys;
  307. console.log(checked_condition_keys);return null;
  308. let forNum = checked_condition_keys.length;
  309. if (forNum) {
  310. for (let i = 0; i < checked_condition_keys.length; i++) {
  311. let key = checked_condition_keys[i];
  312. this.ruleForm.checked_condition_keys[i] = this.ruleForm.checked_condition_values[i].key
  313. }
  314. } */
  315. // console.log(this.ruleForm);return null;
  316. this.$refs['ruleForm'].validate((valid) => {
  317. if (valid) {
  318. // console.log(this.goods_type)
  319. if (this.ruleForm.goods_type == 1) {
  320. this.ruleForm.goods_ids = [];
  321. }
  322. // console.log('ruleForm=', this.ruleForm)
  323. this.btnLoading = true;
  324. request({
  325. params: {
  326. r: 'lucky-group/group-level/storage',
  327. },
  328. method: 'post',
  329. data: this.ruleForm
  330. }).then(e => {
  331. this.btnLoading = false;
  332. //console.log('提交的结果='+JSON.stringify(e))
  333. if (e.data.code == 0) {
  334. this.$message.success(e.data.msg);
  335. navigateTo({
  336. r: 'lucky-group/group-level/index'
  337. });
  338. } else {
  339. this.$message.error(e.data.msg);
  340. }
  341. }).catch(e => {
  342. this.$message.error(e);
  343. this.btnLoading = false;
  344. })
  345. } else {
  346. this.$message.error('请填写必要的参数!');
  347. return false;
  348. }
  349. });
  350. },
  351. setCondition() {
  352. navigateTo({
  353. r: 'lucky-group/group-level/condition'
  354. });
  355. },
  356. },
  357. });
  358. </script>