create.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. <template>
  2. <div class="form-submit">
  3. <div class="i-layout-page-header">
  4. <PageHeader class="product_tabs" hidden-breadcrumb>
  5. <div slot="title">
  6. <router-link :to="{ path: `${roterPre}/marketing/czcard_list` }">
  7. <div class="font-sm after-line">
  8. <span class="iconfont iconfanhui"></span>
  9. <span class="pl10">返回</span>
  10. </div>
  11. </router-link>
  12. <span v-text="$route.params.id ? '编辑充值卡' : '添加充值卡'" class="mr20 ml16"></span>
  13. </div>
  14. </PageHeader>
  15. </div>
  16. <Card :bordered="false" dis-hover class="ivu-mt">
  17. <Form :model="formData" :label-width="150">
  18. <FormItem label="名称" required>
  19. <Input v-model="formData.title" v-width="320" placeholder="请输入充值卡名称"></Input>
  20. </FormItem>
  21. <FormItem label="金额" required>
  22. <Input v-model="formData.amount" v-width="320" type="number" placeholder="请输入充值卡金额"></Input>
  23. </FormItem>
  24. <!-- <FormItem label="等级" required>
  25. <Input v-model="formData.level" v-width="320" type="number" placeholder="请输入充值卡等级"></Input>
  26. </FormItem> -->
  27. <FormItem label="次卡数量" required>
  28. <Input v-model="formData.batch_num" v-width="320" type="number" placeholder="请输入次卡数量"></Input>
  29. </FormItem>
  30. </Form>
  31. </Card>
  32. <Card :bordered="false" dis-hover class="fixed-card"
  33. :style="{ left: `${!menuCollapse ? '200px' : isMobile ? '0' : '80px'}` }">
  34. <Form>
  35. <FormItem>
  36. <Button type="primary" class="submission" @click="save">立即创建</Button>
  37. </FormItem>
  38. </Form>
  39. </Card>
  40. <!-- 选择商品-->
  41. <Modal v-model="modals" title="商品列表" footerHide scrollable width="900" @on-cancel="cancel">
  42. <goods-list ref="goodslist" :ischeckbox="true" :isdiy="true" :goodsType="1" @getProductId="getProductId"
  43. v-if="modals"></goods-list>
  44. </Modal>
  45. <Modal v-model="storeModals" title="门店列表" footerHide scrollable width="900" @on-cancel="cancelStore">
  46. <store-list ref="storelist" @getStoreId="getStoreId" v-if="storeModals"></store-list>
  47. </Modal>
  48. <Modal v-model="modalPic" width="960px" scrollable footer-hide closable title='上传' :mask-closable="false"
  49. :z-index="1">
  50. <uploadPictures :isChoice="isChoice" @getPic="getPic" :gridBtn="gridBtn" :gridPic="gridPic" v-if="modalPic">
  51. </uploadPictures>
  52. </Modal>
  53. </div>
  54. </template>
  55. <script>
  56. import {
  57. mapState
  58. } from "vuex";
  59. import storeList from "@/components/storeList";
  60. import goodsList from '@/components/goodsList';
  61. import {
  62. couponCategoryApi,
  63. couponSaveApi,
  64. addSuper,
  65. couponDetailApi,
  66. superInfo,
  67. addCzcard
  68. } from "@/api/marketing";
  69. import {
  70. brandList
  71. } from "@/api/product";
  72. // import { formatDate } from '@/utils/validate';
  73. import Setting from "@/setting";
  74. import uploadPictures from '@/components/uploadPictures';
  75. export default {
  76. name: "storeCouponCreate",
  77. components: {
  78. goodsList,
  79. storeList,
  80. uploadPictures
  81. },
  82. data() {
  83. return {
  84. checkPidList: [], //父级有关id集合 (需求禁止删除子级,用于删除整个商品)
  85. isAllChecked: false, //表头是否被选中
  86. gridPic: {
  87. xl: 6,
  88. lg: 8,
  89. md: 12,
  90. sm: 12,
  91. xs: 12
  92. },
  93. gridBtn: {
  94. xl: 4,
  95. lg: 8,
  96. md: 8,
  97. sm: 8,
  98. xs: 8
  99. },
  100. isChoice: '单选',
  101. modalPic: false,
  102. roterPre: Setting.roterPre,
  103. disabled: false,
  104. storesList: [],
  105. formData: {
  106. title: '',
  107. amount: '',
  108. batch_num: '',
  109. // level: '',
  110. type: 0
  111. },
  112. categoryList: [],
  113. brandList: [],
  114. productList: [],
  115. isMinPrice: 0,
  116. isCouponTime: 1,
  117. isReceiveTime: 0,
  118. modals: false,
  119. datetime1: [],
  120. datetime2: [],
  121. storeModals: false,
  122. currentTab: '1',
  123. imageType: '',
  124. chooseModals: false,
  125. keyword: '',
  126. searchTableData: [],
  127. tableData: [],
  128. };
  129. },
  130. computed: {
  131. ...mapState("admin/layout", ["isMobile", "menuCollapse"]),
  132. },
  133. created() {
  134. this.getBrandList();
  135. this.getCategoryList();
  136. if (this.$route.params.id) {
  137. this.formData.id = this.$route.params.id
  138. this.getCouponDetail();
  139. }
  140. },
  141. methods: {
  142. onchangeIsShow(row) {
  143. // this.tableData.forEach(item=>{
  144. // item.attrValue.forEach(i => {
  145. // if(row.unique == i.unique) {
  146. // console.log('i.is_yue:',i.is_yue);
  147. // // i.is_yue = !i.is_yue;
  148. // }
  149. // })
  150. // })
  151. },
  152. getProductId(data) {
  153. this.modals = false;
  154. // console.log(data)
  155. // let uni =
  156. let list = this.tableData.concat(data);
  157. let uni = this.unique(list);
  158. uni.forEach((i) => {
  159. i.is_yue = i.is_yue ? true : false;
  160. i.number = i.number || 0;
  161. i.days = i.days || 0;
  162. })
  163. this.tableData = uni;
  164. console.log(uni,'uni')
  165. },
  166. checkboxItem(e) {
  167. let id = parseInt(e.rowid);
  168. if (e.row.product_id) {
  169. // let index = this.checkUidList.indexOf(id);
  170. // if(index !== -1){
  171. // this.checkUidList = this.checkUidList.filter((item)=> item !== id);
  172. // }else{
  173. // this.checkUidList.push(id);
  174. // }
  175. let pIndex = this.checkPidList.indexOf(e.row.product_id);
  176. if (pIndex !== -1 && !e.checked) {
  177. this.checkPidList = this.checkPidList.filter((item) => item !== e.row.product_id);
  178. }
  179. if (pIndex === -1 && e.checked) {
  180. this.checkPidList.push(e.row.product_id);
  181. }
  182. } else {
  183. let pIndex = this.checkPidList.indexOf(id);
  184. if (pIndex !== -1 && !e.checked) {
  185. this.checkPidList = this.checkPidList.filter((item) => item !== id);
  186. }
  187. if (pIndex === -1 && e.checked) {
  188. this.checkPidList.push(id);
  189. }
  190. }
  191. this.isAllChecked = this.$refs.xTree.isAllCheckboxChecked();
  192. },
  193. checkboxAll() {
  194. this.isAllChecked = this.$refs.xTree.isAllCheckboxChecked();
  195. if (!this.isAllChecked) {
  196. this.checkPidList = [];
  197. }
  198. console.log('fgfg', this.isAllChecked);
  199. },
  200. searchWord() {
  201. let list = []
  202. this.tableData.forEach(item => {
  203. let obj = item.store_name.indexOf(this.keyword);
  204. if (obj != -1) {
  205. list.push(item)
  206. }
  207. })
  208. if (this.keyword) {
  209. this.searchTableData = list;
  210. } else {
  211. this.searchTableData = []
  212. }
  213. },
  214. addGoods() {
  215. this.modals = true;
  216. },
  217. // 选择商品
  218. changeGoods() {
  219. this.modals = true;
  220. },
  221. // 选择图片
  222. modalPicTap(type) {
  223. this.imageType = type;
  224. this.modalPic = true;
  225. this.$refs.formItem.validateField("image")
  226. },
  227. // 选中图片
  228. getPic(pc) {
  229. this.formData[this.imageType] = pc.att_dir;
  230. this.modalPic = false;
  231. // this.$refs.formItem.validateField("image")
  232. },
  233. //删除门店
  234. delte(row) {
  235. this.storesList.forEach((item, index) => {
  236. if (row.id == item.id) {
  237. this.storesList.splice(index, 1)
  238. }
  239. })
  240. },
  241. //添加门店
  242. addStore() {
  243. this.storeModals = true;
  244. },
  245. //关闭门店弹窗
  246. cancelStore() {
  247. this.storeModals = false;
  248. },
  249. uniqueId(arr) {
  250. const res = new Map();
  251. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  252. },
  253. unique(arr) {
  254. const res = new Map();
  255. return arr.filter((arr) => !res.has(arr.id) && res.set(arr.id, 1))
  256. },
  257. getStoreId(data) {
  258. this.storeModals = false;
  259. let list = this.storesList.concat(data);
  260. let uni = this.uniqueId(list);
  261. this.storesList = uni;
  262. },
  263. // 品类
  264. getCategoryList() {
  265. couponCategoryApi(1).then(async (res) => {
  266. res.data.forEach((val) => {
  267. val.cate_name = `${val.html}${val.cate_name}`;
  268. });
  269. this.categoryList = res.data;
  270. });
  271. },
  272. //品牌
  273. getBrandList() {
  274. brandList().then(res => {
  275. this.brandList = res.data;
  276. })
  277. },
  278. // 充值卡
  279. getCouponDetail() {
  280. superInfo(this.$route.params.id)
  281. .then((res) => {
  282. let data = res.data[0];
  283. this.formData.name = data.name;
  284. this.formData.is_forever = data.is_forever;
  285. this.formData.grade = data.grade;
  286. this.formData.discount = data.discount;
  287. this.formData.valid_date = data.valid_date / 60 / 60 / 24;
  288. this.formData.icon = data.icon;
  289. this.formData.image = data.image;
  290. this.formData.is_show = data.is_show;
  291. this.formData.mark = data.mark;
  292. this.formData.is_funds = data.is_funds;
  293. let list = []
  294. data.product.forEach(item => {
  295. let obj = {
  296. id: item.product_id,
  297. store_name: item.product_name,
  298. price: item.price,
  299. is_yue: item.is_yue? true: false,
  300. days: item.days,
  301. number: item.number,
  302. spu: item.spu,
  303. }
  304. list.push(obj)
  305. })
  306. this.tableData = list
  307. })
  308. .catch((err) => {
  309. this.$Message.error(err.msg);
  310. });
  311. },
  312. makeDate(data) {
  313. let date = new Date(data);
  314. let YY = date.getFullYear() + "-";
  315. let MM =
  316. (date.getMonth() + 1 < 10 ?
  317. "0" + (date.getMonth() + 1) :
  318. date.getMonth() + 1) + "-";
  319. let DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
  320. let hh =
  321. (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
  322. let mm =
  323. (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
  324. ":";
  325. let ss =
  326. date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  327. return YY + MM + DD + " " + hh + mm + ss;
  328. },
  329. // 上一页:
  330. upTab() {
  331. if (this.currentTab == '2') {
  332. this.currentTab = (Number(this.currentTab) - 1).toString();
  333. }
  334. },
  335. // 创建
  336. save() {
  337. let that = this
  338. if (!that.formData.title) {
  339. return that.$Message.error("请输入充值卡名称");
  340. }
  341. // if (!that.formData.level) {
  342. // return that.$Message.error("请输入充值卡等级");
  343. // }
  344. if (!that.formData.batch_num) {
  345. return that.$Message.error("请输入充值卡次卡数量");
  346. }
  347. if (!that.formData.amount) {
  348. return that.$Message.error("请输入充值卡金额");
  349. }
  350. addCzcard(that.formData)
  351. .then((res) => {
  352. this.disabled = true;
  353. this.$Message.success(res.msg);
  354. setTimeout(() => {
  355. this.$router.push({
  356. path: this.roterPre + "/marketing/czcard_list",
  357. });
  358. }, 1000);
  359. })
  360. .catch((err) => {
  361. this.$Message.error(err.msg);
  362. });
  363. },
  364. cancel() {
  365. this.modals = false;
  366. },
  367. // 删除商品
  368. remove(productId) {
  369. for (let index = 0; index < this.productList.length; index++) {
  370. if (this.productList[index].product_id == productId) {
  371. this.productList.splice(index, 1);
  372. }
  373. }
  374. this.formData.product_id = "";
  375. this.productList.forEach((value) => {
  376. if (this.formData.product_id) {
  377. this.formData.product_id += `,${value.product_id}`;
  378. } else {
  379. this.formData.product_id += `${value.product_id}`;
  380. }
  381. });
  382. },
  383. //批量设置
  384. batchSet() {
  385. this.modalsSet = true;
  386. },
  387. //批量删除
  388. delAll() {
  389. if (this.isAllChecked && (this.tableData.length == this.searchTableData.length || !this.searchTableData
  390. .length)) {
  391. this.tableData = []
  392. } else {
  393. this.tableData = this.tableData.filter(item => !this.checkPidList.some(ele => ele === item.id));
  394. }
  395. this.checkPidList = [];
  396. this.isAllChecked = false;
  397. },
  398. //删除
  399. del(row) {
  400. if (this.searchTableData.length) {
  401. this.searchTableData.forEach((i, index) => {
  402. if (row.id == i.id) {
  403. this.searchTableData.splice(index, 1)
  404. }
  405. })
  406. this.tableData.forEach((i, index) => {
  407. if (row.id == i.id) {
  408. return this.tableData.splice(index, 1)
  409. }
  410. })
  411. } else {
  412. this.tableData.forEach((i, index) => {
  413. if (row.id == i.id) {
  414. return this.tableData.splice(index, 1)
  415. }
  416. })
  417. }
  418. if (this.isAllChecked && !this.tableData.length) {
  419. this.isAllChecked = false;
  420. this.checkPidList = []
  421. } else {
  422. let index = this.checkPidList.indexOf(row.id);
  423. this.checkPidList.splice(index, 1)
  424. }
  425. },
  426. },
  427. };
  428. </script>
  429. <style scoped lang="stylus">
  430. .tips {
  431. display: inline-bolck;
  432. font-size: 12px;
  433. font-weight: 400;
  434. color: #999999;
  435. margin-top: 10px;
  436. }
  437. .imgPic {
  438. .info {
  439. width: 60%;
  440. margin-left: 10px;
  441. }
  442. .pictrue {
  443. height: 36px;
  444. margin: 7px 3px 0 3px;
  445. img {
  446. height: 100%;
  447. display: block;
  448. }
  449. }
  450. }
  451. .productType {
  452. width: 120px;
  453. height: 60px;
  454. background: #FFFFFF;
  455. border-radius: 3px;
  456. border: 1px solid #E7E7E7;
  457. float: left;
  458. text-align: center;
  459. padding-top: 8px;
  460. position: relative;
  461. cursor: pointer;
  462. line-height: 23px;
  463. margin-right: 12px;
  464. &.on {
  465. border-color: #1890FF;
  466. }
  467. .name {
  468. font-size: 14px;
  469. font-weight: 600;
  470. color: rgba(0, 0, 0, 0.85);
  471. &.on {
  472. color: #1890FF;
  473. }
  474. }
  475. .title {
  476. font-size: 12px;
  477. font-weight: 400;
  478. color: #999999;
  479. }
  480. .jiao {
  481. position: absolute;
  482. bottom: 0;
  483. right: 0;
  484. width: 0;
  485. height: 0;
  486. border-bottom: 26px solid #1890FF;
  487. border-left: 26px solid transparent;
  488. }
  489. .iconfont {
  490. position: absolute;
  491. bottom: -3px;
  492. right: 1px;
  493. color: #FFFFFF;
  494. font-size: 12px;
  495. }
  496. }
  497. .info {
  498. color: #888;
  499. font-size: 12px;
  500. }
  501. .ivu-input-wrapper {
  502. width: 320px;
  503. }
  504. .ivu-input-number {
  505. width: 160px;
  506. }
  507. .ivu-date-picker {
  508. width: 320px;
  509. }
  510. .ivu-icon-ios-camera-outline {
  511. width: 58px;
  512. height: 58px;
  513. border: 1px dotted rgba(0, 0, 0, 0.1);
  514. border-radius: 4px;
  515. background-color: rgba(0, 0, 0, 0.02);
  516. line-height: 58px;
  517. cursor: pointer;
  518. vertical-align: middle;
  519. }
  520. .upload-list {
  521. width: 58px;
  522. height: 58px;
  523. border: 1px dotted rgba(0, 0, 0, 0.1);
  524. border-radius: 4px;
  525. margin-right: 15px;
  526. display: inline-block;
  527. position: relative;
  528. cursor: pointer;
  529. vertical-align: middle;
  530. }
  531. .upload-list img {
  532. display: block;
  533. width: 100%;
  534. height: 100%;
  535. }
  536. .ivu-icon-ios-close-circle {
  537. position: absolute;
  538. top: 0;
  539. right: 0;
  540. transform: translate(50%, -50%);
  541. }
  542. .form-submit {
  543. /deep/.ivu-card {
  544. border-radius: 0;
  545. }
  546. margin-bottom: 79px;
  547. .fixed-card {
  548. position: fixed;
  549. right: 0;
  550. bottom: 0;
  551. left: 200px;
  552. z-index: 99;
  553. box-shadow: 0 -1px 2px rgb(240, 240, 240);
  554. /deep/ .ivu-card-body {
  555. padding: 15px 16px 14px;
  556. }
  557. .ivu-form-item {
  558. margin-bottom: 0;
  559. }
  560. /deep/ .ivu-form-item-content {
  561. margin-right: 124px;
  562. text-align: center;
  563. }
  564. .ivu-btn {
  565. height: 36px;
  566. padding: 0 20px;
  567. }
  568. }
  569. }
  570. /deep/.vxe-tree-cell {
  571. padding-left: 0 !important;
  572. }
  573. .picBox {
  574. display: inline-block;
  575. cursor: pointer;
  576. .upLoad {
  577. width: 58px;
  578. height: 58px;
  579. line-height: 58px;
  580. border: 1px dotted rgba(0, 0, 0, 0.1);
  581. border-radius: 4px;
  582. background: rgba(0, 0, 0, 0.02);
  583. }
  584. .pictrue {
  585. width: 60px;
  586. height: 60px;
  587. border: 1px dotted rgba(0, 0, 0, 0.1);
  588. margin-right: 10px;
  589. img {
  590. width: 100%;
  591. height: 100%;
  592. }
  593. }
  594. .iconfont {
  595. color: #CCCCCC;
  596. font-size 26px;
  597. text-align center
  598. }
  599. }
  600. .vxeTable {
  601. border-top: 1px dotted #eee;
  602. margin-top 20px;
  603. }
  604. /deep/ .vxe-tree--btn-wrapper {
  605. left: 0;
  606. }
  607. </style>