fullpiece_discount_form.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. <template>
  2. <div class="detail-container">
  3. <el-page-header @back="goBack" :content="listItem && listItem.id ? '编辑':'新增'"></el-page-header>
  4. <el-divider></el-divider>
  5. <div class="form-contaner">
  6. <el-form ref="mainForm" :model="mainForm" :rules="mainFormRules" label-width="100px">
  7. <el-form-item label="活动名称:" prop="name">
  8. <el-input v-model="mainForm.name" placeholder="请填写活动名称" style="width: 400px;"></el-input>
  9. </el-form-item>
  10. <el-form-item label="活动时间:" prop="date">
  11. <el-date-picker
  12. v-model="mainForm.date"
  13. type="daterange"
  14. value-format="yyyy-MM-dd"
  15. style="width: 400px;"
  16. range-separator="至"
  17. start-placeholder="开始日期"
  18. end-placeholder="结束日期">
  19. </el-date-picker>
  20. </el-form-item>
  21. <el-form-item label="适用范围:" prop="people">
  22. <el-radio-group v-model="mainForm.people">
  23. <el-radio :label="1">所有人</el-radio>
  24. <el-radio :label="2">普通会员</el-radio>
  25. <el-radio :label="3">业务员</el-radio>
  26. <el-radio :label="4">团长</el-radio>
  27. <el-radio :label="5">内部人员</el-radio>
  28. </el-radio-group>
  29. </el-form-item>
  30. </el-form>
  31. </div>
  32. <el-divider></el-divider>
  33. <div class="label"><span>*</span>设置活动门槛:</div>
  34. <div class="btn-group">
  35. <el-button type="primary" size="small" @click="addThreshold">添加阶梯</el-button>
  36. </div>
  37. <div class="tips">注:件数只能是整数,折扣优惠填写必须是0&lt;x&lt;10的数字,保留两位小数点。</div>
  38. <div class="threshold-list">
  39. <div class="item" v-for="(item, index) in thresholdList" :key="index">
  40. <div class="left">
  41. <div>满<el-input type="number" size="small" v-model="item.satisfyNum" placeholder="请输入"></el-input>件</div>
  42. <div>打<el-input type="number" size="small" v-model="item.discountRate" placeholder="请输入"></el-input>折</div>
  43. <div>佣金比例<el-input type="number" size="small" v-model="item.shareRate" placeholder="请输入"></el-input>%</div>
  44. </div>
  45. <div class="right">
  46. <el-button type="danger" icon="el-icon-delete" plain size="small" v-if="thresholdList.length > 1" @click="delThreshold(index)">删除</el-button>
  47. </div>
  48. </div>
  49. </div>
  50. <el-divider></el-divider>
  51. <div class="label"><span>*</span>选择参与产品:</div>
  52. <div class="mymain-container">
  53. <div class="btn-group">
  54. <el-button size="small" type="primary" @click="addClassify">选择分类</el-button>
  55. <el-button size="small" type="primary" @click="addGoods">选择商品</el-button>
  56. </div>
  57. <div class="table">
  58. <el-table :data="goodsList" border fit stripe>
  59. <el-table-column align="center" label="商品名称" prop="goodsName" min-width="200"></el-table-column>
  60. <el-table-column align="center" label="销售价格" prop="goodsPrice" min-width="110">
  61. <template slot-scope="scope">
  62. ¥{{ scope.row.goodsPrice }}
  63. </template>
  64. </el-table-column>
  65. <el-table-column align="center" label="库存" prop="stockNum"></el-table-column>
  66. <el-table-column align="center" label="销量" prop="soldNum"></el-table-column>
  67. <el-table-column align="center" label="状态" class-name="status-col">
  68. <template slot-scope="scope">
  69. <el-tag :type="scope.row.status ? 'success':'danger'">{{ scope.row.status ? '上架':'下架' }}</el-tag>
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" label="操作" width="100">
  73. <template slot-scope="scope">
  74. <el-button type="text" @click="deleteGoods(scope.row.goodsId)" style="color: #F56C6C;">删除</el-button>
  75. </template>
  76. </el-table-column>
  77. </el-table>
  78. </div>
  79. </div>
  80. <div class="page-footer">
  81. <div class="footer">
  82. <el-button type="primary" @click="submitMainForm" :loading="formLoading">{{ formLoading ? '保存中 ...' : '保 存' }}</el-button>
  83. <el-popconfirm
  84. title="确定关闭吗?"
  85. @onConfirm="goBack"
  86. style="margin-left: 10px;"
  87. >
  88. <el-button slot="reference">关 闭</el-button>
  89. </el-popconfirm>
  90. </div>
  91. </div>
  92. <!-- 选择商品 -->
  93. <el-dialog title="选择商品" :visible.sync="addGoodsVisible" :show-close="false" width="50%" :close-on-click-modal="false">
  94. <div class="dialog-container clearfix">
  95. <div class="left fl">
  96. <div class="item" @click="changeClassify('')">全部分类</div>
  97. <div class="group" v-for="(item, index) in classifyList" :key="index">
  98. <div class="item" @click="toggleOpen(index)">
  99. <i :class="item.isOpen ? 'el-icon-caret-bottom':'el-icon-caret-right'"></i> {{item.name}}
  100. </div>
  101. <div class="child" v-if="item.isOpen">
  102. <div class="item" v-for="(childItem, childIndex) in item.children" :key="childIndex" @click="changeClassify(childItem.categoryId)">{{childItem.name}}</div>
  103. </div>
  104. </div>
  105. </div>
  106. <div class="right fl">
  107. <div class="search">
  108. <el-input placeholder="请输入商品名称进行搜索" v-model="keyword" class="input-with-select" clearable size="small" style="width: 250px">
  109. <el-button slot="append" icon="el-icon-search" size="small" @click="getGoodsListByScreen"></el-button>
  110. </el-input>
  111. </div>
  112. <div class="table" style="margin: 10px 0 20px;">
  113. <el-table
  114. v-loading="table_listLoading"
  115. :data="table_dataList"
  116. element-loading-text="Loading"
  117. tooltip-effect="dark"
  118. style="width: 100%"
  119. max-height="270"
  120. @selection-change="handleChooseGoods">
  121. <el-table-column align="center" type="selection" :selectable='checkboxSelect' width="45"></el-table-column>
  122. <el-table-column align="center" prop="goodsName" label="商品名称" min-width="200" show-overflow-tooltip></el-table-column>
  123. <el-table-column align="center" prop="goodsPrice" label="价格" width="80"></el-table-column>
  124. <el-table-column align="center" prop="stockNum" label="库存" width="80"></el-table-column>
  125. </el-table>
  126. </div>
  127. <div class="pagination clearfix">
  128. <div class="fr">
  129. <el-pagination
  130. @current-change="handleTableCurrentChange"
  131. :current-page="table_currentPage"
  132. :page-size="table_pageSize"
  133. background
  134. layout="prev, pager, next"
  135. :total="table_listTotal">
  136. </el-pagination>
  137. </div>
  138. </div>
  139. </div>
  140. </div>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button type="primary" @click="submitAddGoods">保 存</el-button>
  143. <el-button @click="cancelAddGoods">取 消</el-button>
  144. </div>
  145. </el-dialog>
  146. <!-- 选择分类 -->
  147. <el-dialog title="选择分类" :visible.sync="addClassifyVisible" :show-close="false" width="40%" :close-on-click-modal="false">
  148. <div class="classify-list">
  149. <el-tree
  150. :data="classifyList"
  151. show-checkbox
  152. default-expand-all
  153. node-key="categoryId"
  154. ref="tree"
  155. highlight-current
  156. :props="defaultProps">
  157. </el-tree>
  158. </div>
  159. <div slot="footer" class="dialog-footer">
  160. <el-button type="primary" @click="submitAddClassify">保 存</el-button>
  161. <el-button @click="cancelAddClassify">取 消</el-button>
  162. </div>
  163. </el-dialog>
  164. </div>
  165. </template>
  166. <script>
  167. import { getClassifyList, getGoodsList, getMoreGoodsList } from '@/api/goods'
  168. import { submitData, getDetail } from '@/api/fullpiece_discount'
  169. import { deleteEmptyObj, findElem } from '@/utils/util'
  170. let defaultObj = {
  171. satisfyNum: '',
  172. discountRate: '',
  173. shareRate: ''
  174. }
  175. export default {
  176. props: ['listItem'],
  177. data() {
  178. return {
  179. editId: '',
  180. mainForm: {
  181. name: '',
  182. date: '',
  183. people: 1,
  184. },
  185. mainFormRules: {
  186. name: [
  187. { required: true, message: '请填写活动名称', trigger: 'blur' }
  188. ],
  189. date: [
  190. { required: true, message: '请选择活动时间', trigger: 'change' }
  191. ],
  192. people: [
  193. { required: true, message: '请选择适用范围', trigger: 'change' }
  194. ],
  195. },
  196. formLoading: false,
  197. thresholdList: [JSON.parse(JSON.stringify(defaultObj))],
  198. goodsList: [], // 列表数据
  199. addGoodsVisible: false,
  200. classifyList: [],
  201. classifyCurrent: '',
  202. keyword: '',
  203. table_dataList: null, // 列表数据
  204. table_listLoading: true, // 列表加载loading
  205. table_currentPage: 1, // 当前页码
  206. table_pageSize: 10, // 每页数量
  207. table_listTotal: 0, // 列表总数
  208. table_chooseGoods: [], // table中 当前选择商品
  209. addClassifyVisible: false,
  210. defaultProps: {
  211. children: 'children',
  212. label: 'name'
  213. }
  214. }
  215. },
  216. created() {
  217. this.editId = this.listItem.id;
  218. if(this.editId) {
  219. this.getDetail();
  220. }
  221. },
  222. methods: {
  223. // 返回主页
  224. goBack(needRefresh) {
  225. this.$emit('backList', needRefresh);
  226. },
  227. getDetail() {
  228. getDetail({id: this.editId}).then(res => {
  229. if(!res.data) return this.$errorMsg(`数据返回异常:${res.data}`);
  230. this.mainForm = {
  231. name: res.data.name,
  232. date: [res.data.startTime.slice(0, 10), res.data.endTime.slice(0, 10)],
  233. people: res.data.useType,
  234. }
  235. this.goodsList = res.data.goodsList;
  236. res.data.itemList.forEach(item => {
  237. item.discountRate = item.discountRate * 10;
  238. item.shareRate = item.shareRate * 100;
  239. })
  240. this.thresholdList = res.data.itemList;
  241. })
  242. },
  243. // 添加阶梯
  244. addThreshold() {
  245. this.thresholdList.push(JSON.parse(JSON.stringify(defaultObj)));
  246. },
  247. // 删除阶梯
  248. delThreshold(index) {
  249. this.thresholdList.splice(index, 1);
  250. },
  251. // 获取分类列表
  252. getClassifyList() {
  253. getClassifyList({categoryLevel: 1, status: true}).then(res => {
  254. res.data.forEach(item => {
  255. item.isOpen = false;
  256. });
  257. this.classifyList = res.data;
  258. this.classifyCurrent = '';
  259. this.getGoodsList();
  260. })
  261. },
  262. // 展开/收起 分类
  263. toggleOpen(index) {
  264. this.classifyList[index].isOpen = !this.classifyList[index].isOpen;
  265. },
  266. // 切换分类
  267. changeClassify(cid) {
  268. if(this.table_chooseGoods.length > 0) {
  269. return this.$errorMsg('当前已选择商品,不可切换分类');
  270. }
  271. this.classifyCurrent = cid;
  272. this.table_currentPage = 1;
  273. this.getGoodsList();
  274. },
  275. // 搜索
  276. getGoodsListByScreen() {
  277. if(this.table_chooseGoods.length > 0) {
  278. return this.$errorMsg('当前已选择商品,不可搜索');
  279. }
  280. this.table_currentPage = 1;
  281. this.getGoodsList();
  282. },
  283. // 获取商品列表
  284. getGoodsList() {
  285. getGoodsList({
  286. pageNum: this.table_currentPage,
  287. pageSize: this.table_pageSize,
  288. keyword: this.keyword,
  289. categoryId: this.classifyCurrent,
  290. }).then(res => {
  291. let oldGoodsList = this.goodsList;
  292. let newGoodsList = res.data.records;
  293. for(let i = 0; i < oldGoodsList.length; i++) {
  294. let oldItem = oldGoodsList[i]
  295. for(let j = 0; j < newGoodsList.length; j++) {
  296. let newItem = newGoodsList[j]
  297. if(newItem.goodsId === oldItem.goodsId){
  298. newGoodsList[j].selected = true;
  299. break;
  300. }
  301. }
  302. }
  303. this.table_dataList = newGoodsList;
  304. this.table_listTotal = res.data.total;
  305. this.table_listLoading = false;
  306. })
  307. },
  308. // 查询重复值并禁选
  309. checkboxSelect (row, rowIndex) {
  310. if (row.selected) {
  311. return false // 禁用
  312. }else{
  313. return true // 不禁用
  314. }
  315. },
  316. // 更改列表当前页
  317. handleTableCurrentChange(val) {
  318. if(this.table_chooseGoods.length > 0) {
  319. return this.$errorMsg('当前已选择商品,不可切换分页');
  320. }
  321. this.table_currentPage = val;
  322. this.getGoodsList();
  323. },
  324. // table点击选择商品
  325. handleChooseGoods(val) {
  326. this.table_chooseGoods = val;
  327. },
  328. // 打开 选择商品
  329. addGoods() {
  330. this.addGoodsVisible = true;
  331. this.getClassifyList();
  332. },
  333. // 取消 选择商品
  334. cancelAddGoods(){
  335. this.addGoodsVisible = false;
  336. },
  337. // 提交 选择商品
  338. submitAddGoods() {
  339. let oldGoodsList = this.goodsList;
  340. let newGoodsList = this.table_chooseGoods;
  341. this.goodsList = oldGoodsList.concat(newGoodsList);
  342. this.addGoodsVisible = false;
  343. },
  344. // 删除商品
  345. deleteGoods(id) {
  346. let index = findElem(this.goodsList, 'goodsId', id);
  347. this.goodsList.splice(index, 1);
  348. },
  349. // 打开 选择分类
  350. addClassify() {
  351. this.addClassifyVisible = true;
  352. this.getClassifyList();
  353. },
  354. // 取消 选择分类
  355. cancelAddClassify(){
  356. this.addClassifyVisible = false;
  357. },
  358. // 提交 选择分类
  359. submitAddClassify() {
  360. if(this.$refs.tree.getCheckedNodes().length <= 0) {
  361. return this.$errorMsg('请选择分类');
  362. }
  363. let checkeds = this.$refs.tree.getCheckedNodes();
  364. let ids = [];
  365. checkeds.forEach(item => {
  366. if(item.level === 2) {
  367. ids.push(item.categoryId);
  368. }
  369. })
  370. getMoreGoodsList({ categoryIds: ids.join(',')}).then(res => {
  371. let oldGoodsList = this.goodsList;
  372. let newGoodsList = res.data;
  373. let allGoodsList = oldGoodsList.concat(newGoodsList);
  374. let showGoodsList = [];
  375. let obj = {};
  376. for(var i =0; i<allGoodsList.length; i++){
  377. if(!obj[allGoodsList[i].goodsId]){
  378. showGoodsList.push(allGoodsList[i]);
  379. obj[allGoodsList[i].goodsId] = true;
  380. }
  381. }
  382. this.goodsList = showGoodsList;
  383. this.addClassifyVisible = false;
  384. })
  385. },
  386. submitMainForm() {
  387. this.$refs.mainForm.validate((valid) => {
  388. if (valid) {
  389. let thresholdList = JSON.parse(JSON.stringify(this.thresholdList));
  390. for(let i=0; i<thresholdList.length; i++) {
  391. if(thresholdList[i].satisfyNum === '') {
  392. return this.$errorMsg(`【活动门槛-阶梯${i+1}】件数 不能为空`);
  393. }
  394. if(thresholdList[i].satisfyNum <= 0) {
  395. return this.$errorMsg(`【活动门槛-阶梯${i+1}】件数 需大于0`);
  396. }
  397. if(thresholdList[i].satisfyNum % 1 !== 0) {
  398. return this.$errorMsg(`【活动门槛-阶梯${i+1}】件数 需为整数`);
  399. }
  400. if(thresholdList[i].discountRate === '') {
  401. return this.$errorMsg(`【活动门槛-阶梯${i+1}】折扣 不能为空`);
  402. }
  403. if(thresholdList[i].discountRate <= 0 || thresholdList[i].discountRate >= 10) {
  404. return this.$errorMsg(`【活动门槛-阶梯${i+1}】折扣 需大于0且小于10`);
  405. }
  406. if(thresholdList[i].shareRate === '') {
  407. return this.$errorMsg(`【活动门槛-阶梯${i+1}】佣金比例 不能为空`);
  408. }
  409. if(thresholdList[i].shareRate <= 0 || thresholdList[i].shareRate >= 100) {
  410. return this.$errorMsg(`【活动门槛-阶梯${i+1}】佣金比例 需大于0且小于100`);
  411. }
  412. if(thresholdList[i].shareRate % 1 !== 0) {
  413. return this.$errorMsg(`【活动门槛-阶梯${i+1}】佣金比例 需为整数`);
  414. }
  415. }
  416. if(this.goodsList.length <= 0) {
  417. return this.$errorMsg('请选择商品');
  418. }
  419. let goodsIds = [];
  420. this.goodsList.forEach(item => {
  421. goodsIds.push(item.goodsId);
  422. })
  423. thresholdList.forEach(item => {
  424. item.discountRate = item.discountRate / 10;
  425. item.shareRate = item.shareRate / 100;
  426. })
  427. this.formLoading = true;
  428. let params = {
  429. name: this.mainForm.name,
  430. startTime: this.mainForm.date[0] + ' 00:00:00',
  431. endTime: this.mainForm.date[1] + ' 23:59:59',
  432. useType: this.mainForm.people,
  433. items: thresholdList,
  434. goodsIds
  435. }
  436. if(this.editId) {
  437. params.id = this.editId;
  438. }
  439. submitData(params).then(res => {
  440. this.formLoading = false;
  441. this.$successMsg('保存成功');
  442. setTimeout(()=>{
  443. this.goBack(true);
  444. }, 1000)
  445. }).catch(err => {
  446. this.formLoading = false;
  447. })
  448. }else {
  449. this.$errorMsg('请先完善信息');
  450. return false;
  451. }
  452. })
  453. },
  454. }
  455. }
  456. </script>
  457. <style scoped lang="scss">
  458. .detail-container {
  459. width:100%;
  460. height: 100%;
  461. }
  462. .label {
  463. font-size: 14px;
  464. color: #606266;
  465. line-height: 40px;
  466. font-weight: 600;
  467. span {
  468. color: #F56C6C;
  469. margin-right: 4px;
  470. }
  471. }
  472. .tips {
  473. font-size: 12px;
  474. color: #F56C6C;
  475. font-weight: 500;
  476. margin-top: 10px;
  477. }
  478. .threshold-list {
  479. margin-left: 10px;
  480. .item {
  481. display: flex;
  482. align-items: center;
  483. margin-top: 15px;
  484. .left {
  485. display: flex;
  486. align-items: center;
  487. div {
  488. margin-right: 80px;
  489. font-size: 14px;
  490. color: #333333;
  491. flex-shrink: 0;
  492. }
  493. .el-input {
  494. width: 100px;
  495. margin: 0 8px;
  496. }
  497. }
  498. }
  499. }
  500. .mymain-container {
  501. margin-top: 0;
  502. }
  503. .dialog-container {
  504. .left {
  505. width: 140px;
  506. height: 350px;
  507. overflow-y: scroll;
  508. .group {
  509. margin-top: 10px;
  510. }
  511. .child {
  512. margin-top: 5px;
  513. .item {
  514. padding-left: 18px;
  515. }
  516. }
  517. .item {
  518. cursor: pointer;
  519. line-height: 24px;
  520. }
  521. }
  522. .right {
  523. width: calc(100% - 140px);
  524. height: 350px;
  525. box-sizing: border-box;
  526. padding-left: 20px;
  527. }
  528. }
  529. .classify-list {
  530. height: 50vh;
  531. overflow-y: scroll;
  532. }
  533. ::v-deep input::-webkit-outer-spin-button,
  534. ::v-deep input::-webkit-inner-spin-button {
  535. -webkit-appearance: none;
  536. }
  537. ::v-deep input[type='number'] {
  538. -moz-appearance: textfield;
  539. }
  540. </style>