edit.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <?php
  2. use common\helpers\ComponentHelper;
  3. ComponentHelper::loadComponentView('com-dialog-select');
  4. ComponentHelper::loadComponentView('com-select-cat');
  5. ComponentHelper::loadComponentView('com-dialog-select');
  6. ?>
  7. <div id="app" v-cloak>
  8. <el-card v-loading="cardLoading" style="border:0; min-width: 800px;" shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  9. <div slot="header">
  10. <el-breadcrumb separator="/">
  11. <el-breadcrumb-item>
  12. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'operation-center/level/index'})">
  13. 等级列表
  14. </span>
  15. </el-breadcrumb-item>
  16. <el-breadcrumb-item>{{ getTitle() }}</el-breadcrumb-item>
  17. </el-breadcrumb>
  18. </div>
  19. <el-form :model="ruleForm" ref="elForm" label-width="150px" style="position: relative" size="small" :rules="rules">
  20. <el-row>
  21. <el-col :span="24">
  22. <div class="form-body">
  23. <el-col :span="24">
  24. <!-- 等级名称 -->
  25. <el-form-item label="等级名称" prop="name">
  26. <el-input v-model="ruleForm.name" placeholder="请输入等级名称"></el-input>
  27. </el-form-item>
  28. <!-- 权重 -->
  29. <el-form-item label="等级权重" prop="level">
  30. <el-select style="width: 100%" v-model="ruleForm.level" placeholder="请选择" :disabled="levelDisabled()">
  31. <el-option v-for="item in weights" :key="item.level" :label="item.name" :value="item.level" :disabled="item.disabled && item.level!=origin_level">
  32. </el-option>
  33. </el-select>
  34. </el-form-item>
  35. <!-- 直推佣金类型 -->
  36. <el-form-item label="直推佣金类型" prop="commission1_type">
  37. <el-radio-group v-model="ruleForm.commission1_type">
  38. <el-radio :label="item.type" v-for="item in commissionType">
  39. {{ item.name }}
  40. </el-radio>
  41. </el-radio-group>
  42. </el-form-item>
  43. <!-- 直推佣金数量 -->
  44. <el-form-item label="直推佣金数量" prop="commission1_value">
  45. <el-input v-model="ruleForm.commission1_value" placeholder="请输入一级佣金数量">
  46. <template slot="append" v-if="ruleForm.commission1_type == 1">%</template>
  47. <template slot="append" v-if="ruleForm.commission1_type == 2">元</template>
  48. </el-input>
  49. </el-form-item>
  50. <!-- 间推佣金类型 -->
  51. <el-form-item label="间推佣金类型" prop="commission2_type">
  52. <el-radio-group v-model="ruleForm.commission2_type">
  53. <el-radio :label="item.type" v-for="item in commissionType">
  54. {{ item.name }}
  55. </el-radio>
  56. </el-radio-group>
  57. </el-form-item>
  58. <!-- 间推佣金数量 -->
  59. <el-form-item label="间推佣金数量" prop="commission2_value">
  60. <el-input v-model="ruleForm.commission2_value" placeholder="请输入二级佣金数量">
  61. <template slot="append" v-if="ruleForm.commission2_type == 1">%</template>
  62. <template slot="append" v-if="ruleForm.commission2_type == 2">元</template>
  63. </el-input>
  64. </el-form-item>
  65. <!-- 是否启用自动升级 -->
  66. <template v-if="ruleForm.level > 1">
  67. <el-form-item label="是否启用自动升级" prop="is_auto_upgrade">
  68. <el-switch v-model="ruleForm.is_auto_upgrade" :active-value="1" :inactive-value="0">
  69. </el-switch>
  70. <div class="tips-text" style="line-height: 24px;">
  71. 自动升级仅对于拥有等级的才能进行升级
  72. </div>
  73. </el-form-item>
  74. <!-- tpl -->
  75. <template v-if="ruleForm.is_auto_upgrade == 1">
  76. <el-form-item label="购买商品升级" prop="upgrade_type_goods">
  77. <el-switch v-model="ruleForm.upgrade_type_goods" :active-value="1" :inactive-value="0">
  78. </el-switch>
  79. </el-form-item>
  80. <el-form-item label="" prop="buy_goods_type">
  81. <el-radio-group v-model="ruleForm.buy_goods_type">
  82. <el-radio :label="0">
  83. 订单完成
  84. </el-radio>
  85. <el-radio :label="1">
  86. 支付完成
  87. </el-radio>
  88. </el-radio-group>
  89. </el-form-item>
  90. <el-form-item label="" prop="goods_type">
  91. <el-radio-group v-model="ruleForm.goods_type">
  92. <el-radio :label="1">
  93. 任意商品
  94. </el-radio>
  95. <el-radio :label="2">
  96. 指定商品
  97. </el-radio>
  98. </el-radio-group>
  99. </el-form-item>
  100. <el-form-item label="" v-if="ruleForm.goods_type == 2">
  101. <com-dialog-select :multiple="true" title="商品选择" @selected="goodsSelect">
  102. <el-button size="small">添加商品</el-button>
  103. </com-dialog-select>
  104. <template v-if="ruleForm.goods_list.length > 0">
  105. <div style="color: #ff4544;">最多可添加20个商品</div>
  106. <div style="max-height: 300px;overflow-y: auto">
  107. <el-table :data="ruleForm.goods_list" :show-header="false" border>
  108. <el-table-column label="">
  109. <template slot-scope="scope">
  110. <div flex>
  111. <div style="padding-right: 10px;flex-grow: 0">
  112. <img :src="scope.row.cover_pic" style="width: 50px; height: 50px; display: block;">
  113. </div>
  114. <div style="flex-grow: 1;">
  115. <com-ellipsis :line="2">{{ scope.row.name }}</com-ellipsis>
  116. </div>
  117. <div style="flex-grow: 0;">
  118. <el-button @click="deleteGoods(scope.$index)" type="text" circle size="mini">
  119. <el-tooltip class="item" effect="dark" content="删除" placement="top">
  120. <img src="resources/img/mall/del.png" alt="">
  121. </el-tooltip>
  122. </el-button>
  123. </div>
  124. </div>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. </div>
  129. </template>
  130. </el-form-item>
  131. </template>
  132. </template>
  133. <!-- 描述 -->
  134. <el-form-item label="等级描述" prop="explain">
  135. <el-input v-model="ruleForm.explain" type="textarea"></el-input>
  136. </el-form-item>
  137. <!-- 启用 -->
  138. <el-form-item label="是否启用" prop="status">
  139. <el-switch v-model="ruleForm.status" :active-value="1" :inactive-value="0" onInput="value=toNumber(value,2)">
  140. </el-switch>
  141. </el-form-item>
  142. </el-col>
  143. <div></div>
  144. <el-col :span="24">
  145. <el-form-item size="large">
  146. <el-button type="primary" size="small" :loading="submitLoading" @click="submitForm">提交</el-button>
  147. <!-- <el-button size="small" @click="resetForm">重置</el-button> -->
  148. </el-form-item>
  149. </el-col>
  150. </div>
  151. </el-col>
  152. </el-row>
  153. </el-form>
  154. </el-card>
  155. </div>
  156. <script>
  157. const app = new Vue({
  158. el: '#app',
  159. data() {
  160. return {
  161. id: 0,
  162. loading: false,
  163. submitLoading: false,
  164. cardLoading: false,
  165. commissionType: [{
  166. type: 1,
  167. name: '百分比',
  168. },
  169. {
  170. type: 2,
  171. name: '固定值',
  172. },
  173. ],
  174. weights: [],
  175. ruleForm: {
  176. level: '', // 当前选中等级
  177. name: '',
  178. commission1_type: 1,
  179. commission1_value: '',
  180. commission2_type: 1,
  181. commission2_value: '',
  182. status: 1,
  183. condition_type: 1,
  184. buy_goods_type: 0,
  185. is_auto_upgrade: 0,
  186. goods_type: 1,
  187. upgrade_type_condition: 0,
  188. upgrade_type_goods: 0,
  189. indicators_num: 0,
  190. explain: '',
  191. goods_ids: [],
  192. checked_condition_keys: [], // 对应条件的key
  193. goods_list: [],
  194. },
  195. rules: {
  196. name: [{
  197. required: true,
  198. message: '等级名称不能为空',
  199. }],
  200. status: [{
  201. required: true,
  202. message: '状态不能为空',
  203. }],
  204. level: [{
  205. required: true,
  206. message: '权重不能为空',
  207. }],
  208. commission1_value: [{
  209. required: true,
  210. message: '佣金不能为空',
  211. }],
  212. commission2_value: [{
  213. required: true,
  214. message: '佣金不能为空',
  215. }],
  216. },
  217. goodsCatsDialogVisible: false,
  218. currentGoodsCats: [],
  219. formLabelWidth: '150px',
  220. }
  221. },
  222. computed: {},
  223. watch: {},
  224. created() {
  225. getQuery('id') && (this.id = getQuery('id'))
  226. this.getLevelData()
  227. },
  228. mounted() {},
  229. methods: {
  230. submitForm() {
  231. let self = this;
  232. self.showConditionMsg = false;
  233. if (self.ruleForm.upgrade_type_goods == 1) {
  234. if (self.ruleForm.goods_type == 2 && self.ruleForm.goods_list.length == 0) { //选中的checkBox
  235. self.$message.error('请选择升级商品');
  236. return;
  237. }
  238. }
  239. // if (self.ruleForm.upgrade_type_condition == 1 && self.ruleForm.is_auto_upgrade == 1) { //选中升级条件
  240. // if (self.ruleForm.checked_condition_keys.length == 0) { //选中的checkBox
  241. // self.$message.error('请完善升级条件');
  242. // return;
  243. // }
  244. // let checked_condition_values = self.ruleForm.checked_condition_values;
  245. // self.ruleForm.checked_condition_keys.forEach(function(item, index) {
  246. // for (i in self.ruleForm.checked_condition_values[index].value) {
  247. // if (!self.ruleForm.checked_condition_values[index].value[i]) {
  248. // self.conditionMsg = '请完善条件:' + (parseInt(index) + 1);
  249. // return false;
  250. // }
  251. // }
  252. // })
  253. // if (self.showConditionMsg) {
  254. // this.$message.error(self.conditionMsg);
  255. // return
  256. // }
  257. // if (this.ruleForm.checked_condition_keys.length > 0) {
  258. // if (this.ruleForm.condition_type == 0) {
  259. // this.$message.error('请选择条件升级的方式升级类型');
  260. // return;
  261. // }
  262. // }
  263. // }
  264. this.$refs['elForm'].validate(valid => {
  265. if (valid) {
  266. this.submitLoading = true;
  267. let params = {
  268. r: 'operation-center/level/edit',
  269. }
  270. this.id && Object.assign(params, {
  271. id: this.id
  272. })
  273. request({
  274. params: params,
  275. method: 'post',
  276. data: this.ruleForm,
  277. }).then(e => {
  278. this.submitLoading = false
  279. if (e.data.code === 0) {
  280. this.$message.success(e.data.msg)
  281. setTimeout(() => {
  282. navigateTo({
  283. r: 'operation-center/level/index',
  284. });
  285. }, 1500)
  286. } else {
  287. this.$message.error(e.data.msg)
  288. }
  289. })
  290. }
  291. })
  292. },
  293. resetForm() {
  294. this.$refs['elForm'].resetFields()
  295. },
  296. getLevelData() {
  297. this.cardLoading = true
  298. request({
  299. params: {
  300. r: 'operation-center/level/edit',
  301. id: this.id,
  302. },
  303. method: 'get'
  304. }).then(e => {
  305. this.cardLoading = false;
  306. if (e.data.code == 0) {
  307. if (e.data.data.detail) {
  308. let detail = e.data.data.detail
  309. Object.assign(this.ruleForm, detail)
  310. this.origin_level = this.ruleForm.level
  311. }
  312. this.weights = e.data.data.weights
  313. } else {
  314. this.$message.error(e.data.msg)
  315. }
  316. })
  317. },
  318. getTitle() {
  319. return this.id ? '编辑等级' : '添加等级'
  320. },
  321. onChangGoodsCat(val) {
  322. this.$set(this.ruleForm.checked_condition_values[this.currentGoodsCatsIndex].value, this.currentGoodsCatsName, JSON.stringify(val))
  323. },
  324. goodsSelect(param) {
  325. for (let j in param) {
  326. let item = param[j];
  327. if (this.ruleForm.goods_ids.length >= 20) {
  328. this.$message.error('指定商品不能大于20个');
  329. return;
  330. }
  331. let flag = true;
  332. for (let i in this.ruleForm.goods_ids) {
  333. if (this.ruleForm.goods_ids[i] == param[j].id) {
  334. flag = false;
  335. break;
  336. }
  337. }
  338. if (flag) {
  339. this.ruleForm.goods_ids.push(param[j].id);
  340. this.ruleForm.goods_list.push({
  341. id: param[j].id,
  342. name: param[j].goods_name,
  343. cover_pic: param[j].cover_pic,
  344. });
  345. }
  346. }
  347. },
  348. deleteGoods(index) {
  349. this.ruleForm.goods_list.splice(index, 1);
  350. this.ruleForm.goods_ids.splice(index, 1);
  351. },
  352. setCondition() {
  353. navigateTo({
  354. r: 'operation-center/level/condition',
  355. });
  356. },
  357. levelDisabled() {
  358. return this.id ? true : false
  359. },
  360. }
  361. })
  362. </script>
  363. <style>
  364. .form-body {
  365. padding-bottom: 5px;
  366. display: flex;
  367. flex-direction: column;
  368. }
  369. .title {
  370. display: flex;
  371. align-items: center;
  372. padding: 18px 20px;
  373. border-bottom: 1px solid #F3F3F3;
  374. background-color: #fff;
  375. }
  376. .title-line {
  377. width: 4px;
  378. height: 20px;
  379. background-color: #1479F0;
  380. margin-right: 10px;
  381. }
  382. .padding-top {
  383. margin-bottom: 10px;
  384. }
  385. .form-body {
  386. padding: 20px;
  387. background-color: #fff;
  388. margin-bottom: 20px;
  389. padding-right: 20%;
  390. min-width: 900px;
  391. }
  392. .form-body .el-form-item {
  393. padding-right: 25%;
  394. min-width: 850px;
  395. }
  396. .form-button {
  397. margin: 0;
  398. }
  399. .form-button .el-form-item__content {
  400. margin-left: 0 !important;
  401. }
  402. .button-item {
  403. padding: 9px 25px;
  404. }
  405. .check-group {
  406. font-size: 14px !important;
  407. }
  408. .check-group .el-col {
  409. display: flex;
  410. }
  411. .check-group .el-input {
  412. margin: 0 5px;
  413. }
  414. .check-group .el-col .el-checkbox {
  415. display: flex;
  416. align-items: center;
  417. }
  418. .check-group .el-col .el-input {
  419. width: 100px;
  420. }
  421. .check-group .el-col .el-input .el-input__inner {
  422. height: 30px;
  423. width: 100px;
  424. }
  425. .el-checkbox-group .el-col {
  426. margin-bottom: 10px;
  427. }
  428. .condition_common {
  429. display: flex;
  430. align-items: center;
  431. }
  432. .condition_common_five {
  433. display: flex;
  434. }
  435. </style>