com-goods-distribution.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /**
  3. * @link:http://www.gdqijianshi.com/
  4. * @copyright: Copyright (c) 2020 广东七件事集团
  5. * Created by PhpStorm
  6. * Author: ganxiaohao
  7. * Date: 2020-05-19
  8. * Time: 14:19
  9. */
  10. ?>
  11. <template id="com-goods-distribution" v-cloak>
  12. <div v-loading="loading" class="com-goods-distribution" v-if="goods_id!=0">
  13. <el-form-item label="是否开启独立分销设置" prop="is_alone">
  14. <el-switch :active-value="1" :inactive-value="0" v-model="form.is_alone">
  15. </el-switch>
  16. </el-form-item>
  17. <template v-if="form.is_alone==1">
  18. <el-form-item label="分销佣金设置" v-if="use_attr == 1">
  19. <el-radio v-model="form.attr_setting_type" :label="0">按商品设置</el-radio>
  20. <el-radio v-model="form.attr_setting_type" :label="1">按规格设置</el-radio>
  21. </el-form-item>
  22. <el-form-item label="分销佣金类型" prop="share_type">
  23. <el-radio v-model="form.share_type" :label="0">固定金额</el-radio>
  24. <el-radio v-model="form.share_type" :label="1">百分比</el-radio>
  25. </el-form-item>
  26. <el-form-item label="分销佣金">
  27. <template v-if="distributionLevel.length == 0">
  28. <el-button type="danger" @click="$navigate({r: 'plugin/distribution/mall/setting/index'})">
  29. 请先在分销应用的中开启功能
  30. </el-button>
  31. </template>
  32. <template v-else>
  33. <div class="box">
  34. <label style="margin-bottom:0;padding:18px 10px;">批量设置</label>
  35. <el-select v-model="selectLevel" slot="prepend" placeholder="请选择等级"
  36. v-if="form.attr_setting_type == 1">
  37. <el-option v-for="(item, index) in form.distribution_level_list"
  38. :value="index"
  39. :key="item.id"
  40. :label="item.name">{{item.name}}
  41. </el-option>
  42. </el-select>
  43. <el-select v-model="selectData" slot="prepend" placeholder="请选择层级">
  44. <el-option v-for="(item, index) in distributionLevel" :value="item.value"
  45. :key="item.id"
  46. :label="item.label">{{item.label}}
  47. </el-option>
  48. </el-select>
  49. <el-input @keyup.enter.native="enter" type="number" style="width: 150px;"
  50. v-model="batchShareLevel">
  51. <span slot="append">{{form.share_type == 1 ? '%' : '元'}}</span>
  52. </el-input>
  53. <el-button type="primary" size="small" @click="batchAttr">设置</el-button>
  54. </div>
  55. <!--普通分销佣金设置 -->
  56. <template v-if="form.attr_setting_type == 0 || use_attr == 0">
  57. <el-table ref="normal" :data="form.distribution_level_list" border stripe style="width: 100%;"
  58. @selection-change="handleSelectionChange">
  59. <el-table-column type="selection" width="55"></el-table-column>
  60. <el-table-column width="100" label="等级名称" prop="name"></el-table-column>
  61. <el-table-column :label="item.label" :prop="item.value" :property="item.value"
  62. v-for="(item, index) in distributionLevel" :key="index" width="300">
  63. <template slot-scope="scope">
  64. <el-input type="number" v-model="scope.row[scope.column.property]">
  65. <span slot="append">{{form.share_type == 1 ? '%' : '元'}}</span>
  66. </el-input>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. </template>
  71. <template v-else>
  72. <!-- 详细分销佣金设置 -->
  73. <template v-if="form.attr.length > 0">
  74. <el-table ref="detail" :data="form.attr" border class="detail"
  75. @selection-change="handleSelectionChange">
  76. <el-table-column type="selection" width="55"></el-table-column>
  77. <el-table-column width="100" v-for="(item, index) in attrGroups" :key="item.id"
  78. :label="item.attr_group_name"
  79. :prop="'attr_list['+index+'].attr_name'">
  80. </el-table-column>
  81. <el-table-column v-for="(item, index) in form.distribution_level_list" :key="item.id"
  82. :label="item.name">
  83. <el-table-column :label="value.label" type="index" :index="index"
  84. :prop="value.value"
  85. v-for="(value, key) in distributionLevel" :key="key" width="150">
  86. <template slot-scope="scope">
  87. <el-input type="number"
  88. v-model="scope.row.distribution_level_list[scope.column.index][scope.column.property]" @input="onInput()">
  89. <span slot="append">{{form.share_type == 1 ? '%' : '元'}}</span>
  90. </el-input>
  91. </template>
  92. </el-table-column>
  93. </el-table-column>
  94. </el-table>
  95. </template>
  96. <!-- 默认规格 分销佣金-->
  97. <template v-else>
  98. <el-tag style="margin-top: 10px;" type="danger">如需设置多规格分销价, 请先添加商品规格</el-tag>
  99. </template>
  100. </template>
  101. </template>
  102. </el-form-item>
  103. </template>
  104. <el-form-item>
  105. <el-button type="primary" style="margin-top: 10px" size="small" @click="saveGoodsDistribution">保存分销设置
  106. </el-button>
  107. </el-form-item>
  108. </div>
  109. </template>
  110. <script>
  111. Vue.component('com-goods-distribution', {
  112. template: '#com-goods-distribution',
  113. props: {
  114. goods: Number,
  115. goods_id: String,
  116. goods_type: String,
  117. },
  118. data() {
  119. return {
  120. form: {
  121. goods_id: 0,
  122. attr_setting_type: 0,
  123. share_type: 0,
  124. distribution_level_list: [],
  125. attr: [],
  126. is_alone: 0,
  127. goods_type: 'MALL_GOODS'
  128. },
  129. attrGroups: [],
  130. distributionLevel: [],
  131. loading: false,
  132. selectList: [],
  133. batchShareLevel: 0,
  134. selectData: '',
  135. selectLevel: '',
  136. use_attr: 0,
  137. }
  138. },
  139. mounted() {
  140. if (this.goods_id == 0) {
  141. this.$alert('请先保存商品后重试!', '分销设置提示', {
  142. confirmButtonText: '确定',
  143. });
  144. return;
  145. }
  146. this.form.goods_id = this.goods_id;
  147. this.form.goods_type = this.goods_type;
  148. this.loadData();
  149. },
  150. methods: {
  151. onInput(){
  152. this.$forceUpdate();
  153. },
  154. saveGoodsDistribution() {
  155. let self = this;
  156. request({
  157. params: {
  158. r: 'plugin/distribution/mall/distribution/goods-distribution-setting',
  159. },
  160. method: 'post',
  161. data: {
  162. form: this.form
  163. }
  164. }).then(e => {
  165. self.loading = false;
  166. if (e.data.code == 0) {
  167. self.$message.success(e.data.msg);
  168. } else {
  169. self.$message.error(e.data.msg);
  170. }
  171. }).catch(e => {
  172. console.log(e);
  173. });
  174. },
  175. // 获取分销设置
  176. loadData() {
  177. let self = this;
  178. self.loading = true;
  179. request({
  180. params: {
  181. r: 'plugin/distribution/mall/distribution/distribution-config',
  182. goods_id: self.goods_id,
  183. goods_type: self.goods_type
  184. },
  185. method: 'get',
  186. data: {}
  187. }).then(e => {
  188. self.loading = false;
  189. if (e.data.code == 0) {
  190. let detail = e.data.data.detail;
  191. if (detail.distribution_goods) {
  192. self.form.share_type = detail.distribution_goods.share_type;
  193. self.form.attr_setting_type = detail.distribution_goods.attr_setting_type;
  194. self.form.is_alone = detail.distribution_goods.is_alone;
  195. }
  196. if (detail.goods) {
  197. self.use_attr = detail.goods.use_attr;
  198. self.attrGroups = detail.goods.attr_groups;
  199. }
  200. self.distributionLevel = e.data.data.distributionLevelArray; //分销层级
  201. self.form.distribution_level_list = e.data.data.distributionLevelList; //分销商等级
  202. if (e.data.data.detail) {
  203. let attr_level_setting_list = e.data.data.detail.attr_distribution_level_setting_list;
  204. self.form.attr = e.data.data.detail.attr;
  205. if (self.use_attr == 1) {
  206. self.form.attr.forEach((attr, index) => {
  207. attr.distribution_level_list = this.setDistriburtionLevel(self.form.distribution_level_list, attr_level_setting_list[index].distribution_level_list);
  208. });
  209. }
  210. // 未使用规格的情况
  211. let distribution_level_setting_list = e.data.data.detail.distribution_level_setting_list;
  212. self.form.distribution_level_list = this.setDistriburtionLevel(self.form.distribution_level_list, distribution_level_setting_list);
  213. }
  214. } else {
  215. self.$message.error(e.data.msg);
  216. }
  217. }).catch(e => {
  218. console.log(e);
  219. });
  220. },
  221. setDistriburtionLevel(distributionLevelList, list) {
  222. let newDistributionLevelList = [];
  223. distributionLevelList.forEach((item) => {
  224. let newItem = {
  225. level: item.level,
  226. name: item.name,
  227. commission_first: 0,
  228. commission_second: 0,
  229. commission_third: 0,
  230. };
  231. for (let i in list) {
  232. if (list[i].level == item.level) {
  233. newItem = Object.assign(newItem, list[i]);
  234. }
  235. }
  236. newDistributionLevelList.push(newItem);
  237. });
  238. return JSON.parse(JSON.stringify(newDistributionLevelList));
  239. },
  240. handleSelectionChange(data) {
  241. this.selectList = data;
  242. },
  243. batchAttr() {
  244. let form = JSON.parse(JSON.stringify(this.form));
  245. if (form.attr_setting_type == 0) {
  246. if (!this.selectList || this.selectList.length === 0) {
  247. this.$message.warning('请勾选分销商等级');
  248. return;
  249. }
  250. if (this.selectData === '') {
  251. this.$message.warning('请选择分销层级');
  252. return;
  253. }
  254. form.distribution_level_list.forEach((item, index) => {
  255. let flag = false;
  256. this.selectList.map((item1) => {
  257. if (JSON.stringify(item1) === JSON.stringify(item)) {
  258. flag = true;
  259. }
  260. });
  261. if (flag) {
  262. item[this.selectData] = this.batchShareLevel
  263. }
  264. })
  265. } else {
  266. if (!this.selectList || this.selectList.length === 0) {
  267. this.$message.warning('请勾选商品规格');
  268. return;
  269. }
  270. if (this.selectLevel === '') {
  271. this.$message.warning('请选择分销商等级');
  272. return;
  273. }
  274. if (this.selectData === '') {
  275. this.$message.warning('请选择分销层级');
  276. return;
  277. }
  278. form.attr.forEach((item, index) => {
  279. let flag = false;
  280. this.selectList.map((item1) => {
  281. if (JSON.stringify(item1.attr_list) === JSON.stringify(item.attr_list)) {
  282. flag = true;
  283. }
  284. });
  285. if (flag) {
  286. item.distribution_level_list[this.selectLevel][this.selectData] = this.batchShareLevel
  287. }
  288. })
  289. }
  290. this.$set(this, 'form', form);
  291. }
  292. }
  293. });
  294. </script>
  295. <style>
  296. .com-goods-distribution .box {
  297. border-top: 1px solid #E8EAEE;
  298. border-left: 1px solid #E8EAEE;
  299. border-right: 1px solid #E8EAEE;
  300. padding: 16px;
  301. }
  302. .com-goods-distribution .box .batch {
  303. margin-left: -10px;
  304. margin-right: 20px;
  305. }
  306. .com-goods-distribution .el-select .el-input {
  307. width: 130px;
  308. }
  309. .com-goods-distribution .detail {
  310. width: 100%;
  311. }
  312. .com-goods-distribution .detail .el-input-group__append {
  313. padding: 0 10px;
  314. }
  315. .com-goods-distribution input::-webkit-outer-spin-button,
  316. .com-goods-distribution input::-webkit-inner-spin-button {
  317. -webkit-appearance: none;
  318. }
  319. .com-goods-distribution input[type="number"] {
  320. -moz-appearance: textfield;
  321. }
  322. .com-goods-distribution .el-table .cell {
  323. text-align: center;
  324. }
  325. .com-goods-distribution .el-table thead.is-group th {
  326. background: #ffffff;
  327. }
  328. </style>