com-distribution.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. <template id="com-distribution">
  2. <div class="com-distribution">
  3. <el-card class="edit-card" shadow="never">
  4. <div slot="header" class="clearfix">
  5. <div class="card-title">分销设置<span class="card-sub-title"></span></div>
  6. </div>
  7. <el-form :model="form" size="small">
  8. <el-tabs v-model="activeName" @tab-click="handleClick">
  9. <el-tab-pane v-for="(config,key) in form" v-if="commission_type_map[key]" :label="commission_type_map[key]" :name="key" :key="key">
  10. <el-form-item label="是否开启分销" prop="is_enable">
  11. <el-switch :active-value="1" :inactive-value="0" v-model="config.is_enable"></el-switch>
  12. </el-form-item>
  13. <el-row :gutter="24" v-if="config.is_enable == 1">
  14. <el-col :span="24">
  15. <el-card shadow="always">
  16. <el-form-item label="分销类型" prop="is_percent">
  17. <el-radio-group v-model="config.is_percent">
  18. <el-radio :label="0" class="grid-content bg-purple">百分比</el-radio>
  19. <el-radio :label="1" class="grid-content bg-purple">固定{{commission_type_map[config.commission_type]}}</el-radio>
  20. </el-radio-group>
  21. </el-form-item>
  22. <el-form-item>
  23. <template v-if="config.settings == 0 || is_attr == 0">
  24. <el-table ref="normal" :data="level_arr.Distribution" border stripe style="width: 100%;" @selection-change="handleSelectionChange">
  25. <el-table-column width="100" label="等级名称" prop="name"></el-table-column>
  26. <el-table-column label="一级分销" width="300" v-if="levels>=1">
  27. <template slot-scope="scope">
  28. <el-input v-model="config.detail[scope.row.level].first_prize" onInput="value=toNumber(value,2)">
  29. <template slot="append" v-if="config.is_percent == 0">%</template>
  30. <template slot="append" v-if="config.is_percent == 1">
  31. <template v-if="config.commission_type == 'commission'">元</template>
  32. <template v-else-if="config.commission_type == 'hi_bei' || config.commission_type == 'hi_value'">枚</template>
  33. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  34. </template>
  35. </el-input>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="二级分销" width="300" v-if="levels>=2">
  39. <template slot-scope="scope">
  40. <el-input v-model="config.detail[scope.row.level].second_prize" onInput="value=toNumber(value,2)">
  41. <template slot="append" v-if="config.is_percent == 0">%</template>
  42. <template slot="append" v-if="config.is_percent == 1">
  43. <template v-if="config.commission_type == 'commission'">元</template>
  44. <template v-else-if="config.commission_type == 'hi_value' || config.commission_type == 'hi_bei'">枚</template>
  45. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  46. </template>
  47. </el-input>
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="三级分销" width="300" v-if="levels>=3">
  51. <template slot-scope="scope">
  52. <el-input v-model="config.detail[scope.row.level].third_prize" onInput="value=toNumber(value,2)">
  53. <template slot="append" v-if="config.is_percent == 0">%</template>
  54. <template slot="append" v-if="config.is_percent == 1">
  55. <template v-if="config.commission_type == 'commission'">元</template>
  56. <template v-else-if="config.commission_type == 'hi_value' || config.commission_type == 'hi_bei'">枚</template>
  57. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  58. </template>
  59. </el-input>
  60. </template>
  61. </el-table-column>
  62. </el-table>
  63. </template>
  64. </el-form-item>
  65. </el-card>
  66. </el-col>
  67. </el-row>
  68. <template v-if="config.is_enable == 1 && key == 'score'">
  69. <div style="padding-top:20px"></div>
  70. <el-form-item label="是否开启发放等级">
  71. <template>
  72. <el-switch :active-value="1" :inactive-value="0" v-model="form[key].extra.score.enable_limit_level"></el-switch>
  73. <p style="color:#C0C4CC">开关开启后选的等级下单才会触发奖励</p>
  74. </template>
  75. <template v-if="form[key].extra.score.enable_limit_level == 1">
  76. <el-checkbox-group v-model="form[key].extra.score.limit_level">
  77. <el-checkbox v-for="(item, index) in level_list" :label="item.level" :key="index">{{item.name}}</el-checkbox>
  78. </el-checkbox-group>
  79. </template>
  80. </el-form-item>
  81. </template>
  82. </el-tab-pane>
  83. </el-tabs>
  84. <el-form-item label="单独设置复购等于报单">
  85. <el-switch v-model="form.distribution_is_alone" :active-value="1" :inactive-value="0">
  86. </el-switch>
  87. </el-form-item>
  88. <el-form-item label="是否单独设置计算方式" v-if="extend_data?.is_show_alone_computing_method">
  89. <el-switch v-model="form.is_alone_computing_method" :active-value="1" :inactive-value="0">
  90. </el-switch>
  91. <el-form-item prop="computing_method" label="" v-if="form.is_alone_computing_method == 1">
  92. <el-radio-group v-model="form.computing_method" size="small">
  93. <el-radio :label="0" border>支付价格</el-radio>
  94. <el-radio :label="1" border>商品售价</el-radio>
  95. <el-radio :label="2" border>商品利润</el-radio>
  96. </el-radio-group>
  97. </el-form-item>
  98. </el-form-item>
  99. <template v-if="is_install_regular_bonus == 1">
  100. <template v-if="activeName == 'commission'">
  101. <el-form-item label="是否启用返佣设置">
  102. <el-switch v-model="is_enable_regular_bonus" :active-value="1" :inactive-value="0" @change="handleEnableRegularBonus">
  103. </el-switch>
  104. </el-form-item>
  105. <el-row :gutter="24" v-if="is_enable_regular_bonus == 1">
  106. <el-col :span="24">
  107. <el-card shadow="always" v-for="(config,key) in form.commission.extra.RegularBonus" :key="key">
  108. <el-form-item label="分销类型" prop="is_percent">
  109. <el-radio-group v-model="config.is_percent">
  110. <el-radio :label="0" class="grid-content bg-purple">百分比</el-radio>
  111. <el-radio :label="1" class="grid-content bg-purple">固定{{commission_type_map[config.commission_type]}}</el-radio>
  112. </el-radio-group>
  113. </el-form-item>
  114. <el-form-item>
  115. <template>
  116. <el-table ref="normal" :data="level_arr.Distribution" border stripe style="width: 100%;" @selection-change="handleSelectionChange">
  117. <el-table-column width="100" label="等级名称" prop="name"></el-table-column>
  118. <el-table-column label="一级分销" width="300" v-if="levels>=1">
  119. <template slot-scope="scope">
  120. <el-input v-model="config.detail[scope.row.level].first_prize" onInput="value=toNumber(value,2)">
  121. <template slot="append" v-if="config.is_percent == 0">%</template>
  122. <template slot="append" v-if="config.is_percent == 1">
  123. <template v-if="config.commission_type == 'commission'">元</template>
  124. <template v-else-if="config.commission_type == 'hi_bei' || config.commission_type == 'hi_value'">枚</template>
  125. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  126. </template>
  127. </el-input>
  128. </template>
  129. </el-table-column>
  130. <el-table-column label="二级分销" width="300" v-if="levels>=2">
  131. <template slot-scope="scope">
  132. <el-input v-model="config.detail[scope.row.level].second_prize" onInput="value=toNumber(value,2)">
  133. <template slot="append" v-if="config.is_percent == 0">%</template>
  134. <template slot="append" v-if="config.is_percent == 1">
  135. <template v-if="config.commission_type == 'commission'">元</template>
  136. <template v-else-if="config.commission_type == 'hi_value' || config.commission_type == 'hi_bei'">枚</template>
  137. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  138. </template>
  139. </el-input>
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="三级分销" width="300" v-if="levels>=3">
  143. <template slot-scope="scope">
  144. <el-input v-model="config.detail[scope.row.level].third_prize" onInput="value=toNumber(value,2)">
  145. <template slot="append" v-if="config.is_percent == 0">%</template>
  146. <template slot="append" v-if="config.is_percent == 1">
  147. <template v-if="config.commission_type == 'commission'">元</template>
  148. <template v-else-if="config.commission_type == 'hi_value' || config.commission_type == 'hi_bei'">枚</template>
  149. <template v-else="config.commission_type == 'score'">{{commission_type_map[config.commission_type]}}</template>
  150. </template>
  151. </el-input>
  152. </template>
  153. </el-table-column>
  154. </el-table>
  155. </template>
  156. </el-form-item>
  157. </el-card>
  158. </el-col>
  159. </el-row>
  160. </template>
  161. </template>
  162. </el-form>
  163. </el-card>
  164. </div>
  165. </template>
  166. <script>
  167. Vue.component('com-distribution', {
  168. template: "#com-distribution",
  169. props: {
  170. level_arr: {
  171. type: Object,
  172. default: () => {
  173. return {};
  174. }
  175. },
  176. setting: {
  177. type: Object,
  178. default: () => {
  179. return {};
  180. }
  181. },
  182. commission_type_map: {
  183. type: Object,
  184. default: () => {
  185. return {};
  186. }
  187. },
  188. extend_data: {
  189. type: Object,
  190. default: () => {
  191. return {
  192. is_show_alone_computing_method: false,
  193. };
  194. }
  195. }
  196. },
  197. data: function() {
  198. return {
  199. levels: 2,
  200. activeName: 'commission',
  201. form: {
  202. },
  203. black_list: [
  204. 'distribution_is_alone',
  205. 'distribution_setting'
  206. ],
  207. is_attr: 0,
  208. install: { // 初始化数据
  209. is_enable: 0,
  210. is_percent: 0,
  211. item_type: 'goods',
  212. commission_type: '',
  213. settings: 0,
  214. detail: {},
  215. extra:{
  216. },
  217. is_enable_regular_bonus: 0,
  218. },
  219. extra:{
  220. score: {
  221. enable_limit_level: 0,
  222. limit_level: []
  223. },
  224. RegularBonus: {
  225. commission: {
  226. is_percent: 0,
  227. commission_type: 'commission',
  228. detail: [],
  229. },
  230. }
  231. },
  232. level_list: [],
  233. is_install_regular_bonus: 0,
  234. is_enable_regular_bonus: 0,
  235. }
  236. },
  237. mounted() {
  238. this.loadData();
  239. },
  240. watch: {
  241. setting: {
  242. deep: true,
  243. immediate: true,
  244. handler(value) {
  245. if (!isEmpty(value)) {
  246. this.form = value;
  247. this.is_enable_regular_bonus = this.form.commission ? Number(this.form.commission.is_enable_regular_bonus) : 0
  248. }
  249. if (!this.form.distribution_is_alone) {
  250. this.$set(this.form, 'distribution_is_alone', 0)
  251. }
  252. }
  253. },
  254. level_arr: {
  255. deep: true,
  256. immediate: true,
  257. handler(value) {
  258. if (!isEmpty(value)) {
  259. let self = this;
  260. var data = value.Distribution;
  261. // 初始化赋值
  262. for (let name in self.commission_type_map) {
  263. let detail = {};
  264. var prize = isEmpty(self.form[name]) ? {} : self.form[name].detail;
  265. if (data) {
  266. Object.keys(data).forEach(function(key) {
  267. var formKey = data[key].level;
  268. Object.assign(detail, {
  269. [formKey]: {
  270. level: data[key].level,
  271. first_prize: !isEmpty(prize[formKey]) ? prize[formKey].first_prize : 0,
  272. second_prize: !isEmpty(prize[formKey]) ? prize[formKey].second_prize : 0,
  273. third_prize: !isEmpty(prize[formKey]) ? prize[formKey].third_prize : 0,
  274. }
  275. });
  276. });
  277. }
  278. // let extra = self.form[name] && !isEmpty(self.form[name].extra) ? self.form[name].extra : self.extra
  279. let extra = {}
  280. let baseExtra = JSON.parse(JSON.stringify(self.extra))
  281. let extra_fields = Object.keys(baseExtra)
  282. extra_fields.forEach(function(fields, key){
  283. let exists = false
  284. if(!isEmpty(self.form[name]) && !isEmpty(self.form[name].extra)){
  285. if(!isEmpty(self.form[name].extra[fields])){
  286. exists = true
  287. }
  288. }
  289. if(!exists) {
  290. extra[fields] = {}
  291. Object.assign(extra[fields], baseExtra[fields])
  292. let ckey = Object.keys(baseExtra[fields])[0]
  293. extra[fields][name] = JSON.parse(JSON.stringify(baseExtra[fields][ckey]))
  294. baseExtra[fields].ckey = undefined
  295. extra[fields] = JSON.parse(JSON.stringify(baseExtra[fields]))
  296. }else{
  297. extra[fields] = self.form[name].extra[fields]
  298. }
  299. if(fields == 'RegularBonus'){
  300. let detail2 = {}
  301. let prize2 = {}
  302. if(!isEmpty(self.form[name]) && !isEmpty(self.form[name].extra) && !isEmpty(self.form[name].extra[fields]) && !isEmpty(self.form[name].extra[fields][name]) && !isEmpty(self.form[name].extra[fields][name].detail)){
  303. prize2 = self.form[name].extra[fields][name]['detail']
  304. }
  305. if (data) {
  306. Object.keys(data).forEach(function(key) {
  307. let formKey = data[key].level
  308. Object.assign(detail2, {
  309. [formKey]: {
  310. level: data[key].level,
  311. first_prize: !isEmpty(prize2[formKey]) ? prize2[formKey].first_prize : 0,
  312. second_prize: !isEmpty(prize2[formKey]) ? prize2[formKey].second_prize : 0,
  313. third_prize: !isEmpty(prize2[formKey]) ? prize2[formKey].third_prize : 0,
  314. }
  315. });
  316. });
  317. if(!isEmpty(extra[fields]) && !isEmpty(extra[fields][name])){
  318. extra[fields][name]['detail'] = detail2
  319. }
  320. }
  321. }
  322. })
  323. self.install = {
  324. is_enable: isEmpty(self.form[name]) ? 0 : self.form[name].is_enable,
  325. is_percent: isEmpty(self.form[name]) ? 0 : self.form[name].is_percent,
  326. item_type: isEmpty(self.form[name]) ? 'goods' : self.form[name].item_type,
  327. commission_type: name,
  328. detail: detail,
  329. extra,
  330. is_enable_regular_bonus: isEmpty(self.form[name]) ? 0 : self.form[name].is_enable_regular_bonus
  331. };
  332. this.$set(self.form, name, JSON.parse(JSON.stringify(self.install)));
  333. }
  334. }
  335. }
  336. },
  337. form: {
  338. deep: true,
  339. immediate: true,
  340. handler(value) {
  341. this.$emit("change", JSON.stringify(value), "Distribution");
  342. }
  343. },
  344. },
  345. methods: {
  346. loadData() {
  347. this.cardLoading = true;
  348. request({
  349. params: {
  350. r: 'distribution/setting/config-setting',
  351. id: getQuery('id'),
  352. },
  353. method: 'get'
  354. }).then(e => {
  355. this.cardLoading = false;
  356. if (e.data.code == 0) {
  357. this.levels = e.data.data.levels;
  358. this.level_list = e.data.data.level_list
  359. this.is_install_regular_bonus = e.data.data.is_install_regular_bonus
  360. } else {
  361. this.$message.error(e.data.msg);
  362. }
  363. }).catch(e => {
  364. console.log(e);
  365. });
  366. },
  367. handleSelectionChange() {},
  368. handleClick(tab, event) {
  369. console.log(tab, event);
  370. },
  371. handleEnableRegularBonus(data) {
  372. for(let name in this.form) {
  373. if(name == 'commission'){
  374. this.form[name].is_enable_regular_bonus = data
  375. }
  376. }
  377. },
  378. }
  379. });
  380. </script>