creatProduct.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. <template>
  2. <view class="creat">
  3. <view class="head">
  4. <span class="cuIcon-back" @click="back"></span>
  5. <view class="case">
  6. 创建商品
  7. </view>
  8. </view>
  9. <view class="content">
  10. <view class="form" v-if="schedule ==1">
  11. <view class="titl">
  12. 基础信息
  13. </view>
  14. <view class="item">
  15. <view class="label">
  16. 商品分类<span>*</span>
  17. </view>
  18. <view class="picker" @click="isSelectType = true">
  19. <span v-if="showText == ''">选择商品分类</span>
  20. <span v-else style="color: #333333;">{{showText}}</span>
  21. <u-icon name="arrow-right"></u-icon>
  22. </view>
  23. </view>
  24. <view class="item">
  25. <view class="label">
  26. 商品名称<span>*</span>
  27. </view>
  28. <view class="picker">
  29. <u-input v-model="form.productName" placeholder="输入商品名称" />
  30. </view>
  31. </view>
  32. <view class="item upload">
  33. <view class="label">
  34. 商品封面图<span>*</span>
  35. </view>
  36. <view class="tips">
  37. 支持jpg、png格式,尺寸为00px*00px
  38. </view>
  39. <u-upload ref="uUpload" :action="action" :file-list="fileList" max-count="1" width="140rpx"
  40. height="140rpx"></u-upload>
  41. </view>
  42. <view class="item upload">
  43. <view class="label">
  44. 商品详情图<span>*</span>
  45. </view>
  46. <view class="tips">
  47. 支持jpg、png格式,尺寸为00px*00px,最多20张
  48. </view>
  49. <u-upload :action="action" :file-list="fileList" max-count="20" width="140rpx" height="140rpx"></u-upload>
  50. </view>
  51. <view class="item">
  52. <view class="label">
  53. 原价<span>*</span>
  54. </view>
  55. <view class="picker">
  56. <u-input v-model="form.price" placeholder="输入商品原价" />
  57. </view>
  58. <view class="unit">
  59. </view>
  60. </view>
  61. <view class="item">
  62. <view class="label">
  63. 实际售价<span>*</span>
  64. </view>
  65. <view class="picker">
  66. <u-input type="num" v-model="form.soldPrice" placeholder="输入客户实际支付价" />
  67. </view>
  68. <view class="unit">
  69. </view>
  70. </view>
  71. <view class="item">
  72. <view class="label">
  73. 组合套餐
  74. </view>
  75. <view class="picker set" @click="goGroup">
  76. 去设置
  77. <u-icon name="arrow-right" style="margin-left: 17rpx;"></u-icon>
  78. </view>
  79. </view>
  80. </view>
  81. <!-- <u-form :model="form" ref="uForm" v-if="schedule ==1"
  82. style="background-color: #fff;padding: 16rpx;border-radius: 16rpx;">
  83. <view class="titl">
  84. 基础信息
  85. </view>
  86. <u-form-item style="display: flex;">
  87. <label>
  88. 商品分类 <span style="color: red;">*</span>
  89. </label>
  90. <picker v-model="form.sex" :range="genderOptions" range-key="label" @change="onGenderChange">
  91. <view class="">{{ form.sex || '请选择分类' }}</view>
  92. </picker>
  93. </u-form-item>
  94. <u-form-item label="商品名称" label-width="200"><u-input v-model="form.intro" /></u-form-item>
  95. <u-form-item label="商品封面图" label-width="200">
  96. <u-upload :action="action" :file-list="fileList"></u-upload>
  97. </u-form-item>
  98. <u-form-item label="商品详情图" label-width="200">
  99. <u-upload :action="action" :file-list="fileList"></u-upload>
  100. </u-form-item>
  101. <u-form-item label="原价" label-width="200"><u-input v-model="form.intro" /></u-form-item>
  102. <u-form-item label="实际售价" label-width="200"><u-input v-model="form.intro" /></u-form-item>
  103. <u-form-item label="组合套餐" label-width="200">
  104. <view class="" @click="goGroup">
  105. 设置组合套餐
  106. </view>
  107. </u-form-item>
  108. </u-form> -->
  109. <view class="form" v-if="schedule == 2">
  110. <view class="titl ">
  111. 售卖/使用信息
  112. </view>
  113. <view class="item">
  114. <view class="label">
  115. 售卖时间<span>*</span>
  116. </view>
  117. <view class="picker set inp" @click="isSelectDate = true">
  118. 去设置
  119. <u-icon name="arrow-right" style="margin-left: 17rpx;"></u-icon>
  120. </view>
  121. </view>
  122. <view class="item">
  123. <view class="label">
  124. 库存<span>*</span>
  125. </view>
  126. <view class="picker set">
  127. <u-input v-model="form.productName" placeholder="输入库存数量" />
  128. </view>
  129. </view>
  130. <view class="item">
  131. <view class="label">
  132. 可用时间<span>*</span>
  133. </view>
  134. <view class="picker set">
  135. 去设置
  136. <u-icon name="arrow-right" style="margin-left: 17rpx;"></u-icon>
  137. </view>
  138. </view>
  139. <view class="item">
  140. <view class="label">
  141. 需要预约<span>*</span>
  142. </view>
  143. <view class="picker set">
  144. <u-switch v-model="form.checked" style="margin-left:8rpx;" size="28"></u-switch>
  145. </view>
  146. </view>
  147. <view class="item">
  148. <view class="label">
  149. 退款规则
  150. </view>
  151. <view class="picker set">
  152. 请选择
  153. <u-icon name="arrow-right" style="margin-left: 17rpx;"></u-icon>
  154. </view>
  155. </view>
  156. <view class="item upload">
  157. <view class="label">
  158. 使用说明
  159. </view>
  160. <view class="textarea">
  161. <u-input v-model="form.num" type="textarea" placeholder="输入库存数量" maxlength="500" />
  162. </view>
  163. <view class="num">
  164. 0/500
  165. </view>
  166. </view>
  167. </view>
  168. </view>
  169. <view class="btn">
  170. <view class="next" @click="next" v-if="schedule==1">
  171. 下一步
  172. </view>
  173. <view class="handle" v-else>
  174. <view class="back" @click="schedule-=1">
  175. 上一步
  176. </view>
  177. <view class="submit">
  178. 提交审核
  179. </view>
  180. </view>
  181. </view>
  182. <selectDate @confirm="handleConfirm" @close="closeSelectDate" v-if="isSelectDate" />
  183. <refund v-if="isRefund" saveRule="saveFound" @closeRule="cutRule" />
  184. <view class="popup" v-if="isSelectType">
  185. <view class="model">
  186. <view class="title">
  187. 商品品类
  188. <image src="/static/index/cut.png" mode="" @click="closePopup"></image>
  189. </view>
  190. <view class="tree">
  191. <view class="left">
  192. <view class="item" :class="currentLeft == index?'active':''" v-for="(item,index) in treeLeft" :key="item.id"
  193. @click="selectLeft(item,index)">
  194. {{item.name}}
  195. </view>
  196. </view>
  197. <view class="left border">
  198. <view class="item" :class="currentCenter == index?'active':''" v-for="(item,index) in treeCenter"
  199. :key="item.id" @click="selectRight(item,index)">
  200. {{item.name}}
  201. </view>
  202. </view>
  203. <view class="left">
  204. <view class="item" :class="currentRight == index?'active':''" v-for="(item,index) in treeRight"
  205. :key="item.id" @click="selectLast(item,index)">
  206. {{item.name}}
  207. </view>
  208. </view>
  209. </view>
  210. <view class="sub">
  211. <view class="submit" @click="selectType">
  212. 确定
  213. </view>
  214. </view>
  215. </view>
  216. </view>
  217. </view>
  218. </template>
  219. <script>
  220. import selectDate from '@/components/product/select_date.vue'
  221. import refund from '@/components/refund.vue'
  222. export default {
  223. components: {
  224. selectDate,
  225. refund
  226. },
  227. data() {
  228. return {
  229. form: {
  230. productName: '',
  231. productImage: '',
  232. intro: '',
  233. sex: '',
  234. checked: false,
  235. num: 0
  236. },
  237. action: 'http://192.168.0.52:8080/jeecg-boot/sys/common/upload', //图片上传地址
  238. checkboxList: [{
  239. name: '苹果',
  240. checked: false,
  241. disabled: false
  242. },
  243. {
  244. name: '雪梨',
  245. checked: false,
  246. disabled: false
  247. },
  248. {
  249. name: '柠檬',
  250. checked: false,
  251. disabled: false
  252. }
  253. ],
  254. genderOptions: [{
  255. label: '男',
  256. value: 'male'
  257. },
  258. {
  259. label: '女',
  260. value: 'female'
  261. },
  262. {
  263. label: '其他',
  264. value: 'other'
  265. }
  266. ],
  267. schedule: 1, //进度
  268. fileList: [],
  269. selectedTime: null,
  270. isSelectDate: false,
  271. isRefund: false,
  272. selectedRules: null,
  273. isSelectType: false,
  274. treeLeft: [], //一级列表
  275. treeCenter: [], //二级列表
  276. treeRight: [], //三级列表
  277. currentLeft: null, //一级选中
  278. currentCenter: null, //二级选中
  279. currentRight: null, //三级选中
  280. productType: [], //选中的商品分类id
  281. selectTypeList: [], //选中的商品分类名称
  282. showText: ''
  283. }
  284. },
  285. methods: {
  286. onGenderChange(event) {
  287. const selectedIndex = event.detail.value;
  288. this.form.sex = this.genderOptions[selectedIndex].label;
  289. this.selectedGenderLabel = this.genderOptions[selectedIndex].label;
  290. },
  291. //下一步
  292. next() {
  293. this.schedule += 1
  294. let files = [];
  295. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  296. files = this.$refs.uUpload.lists.filter(val => {
  297. return val.progress == 100;
  298. })
  299. this.form.productImage = files[0].response.message
  300. console.log(this.form.productImage)
  301. },
  302. // 跳转至组合商品页
  303. goGroup() {
  304. uni.navigateTo({
  305. url: '/pages/product/group'
  306. })
  307. },
  308. //返回
  309. back() {
  310. uni.navigateBack({
  311. delta: 1
  312. });
  313. },
  314. // 处理 confirm 事件,接收子组件传递的时间段数据
  315. handleConfirm(time) {
  316. this.selectedTime = time; // 保存时间段数据
  317. console.log(this.selectedTime)
  318. this.isSelectDate = false
  319. },
  320. //隐藏弹窗
  321. closeSelectDate() {
  322. this.isSelectDate = false
  323. },
  324. //跳转至可用时间
  325. setUsable() {
  326. uni.navigateTo({
  327. url: '/pages/product/usable'
  328. })
  329. },
  330. //跳转至预约规则
  331. setRule() {
  332. uni.navigateTo({
  333. url: '/pages/product/rule'
  334. })
  335. },
  336. saveFound(rules) {
  337. this.selectedRules = rules; // 保存退款规则
  338. this.selectedRules = false
  339. },
  340. cutRule() {
  341. this.isRefund = false
  342. },
  343. //获取商品分类一级列表
  344. getLeftTree() {
  345. this.$http.get("/sys/category/childList?pid=" + '1889836358116098050', {}).then(res => {
  346. if (res.data.code == 0) {
  347. this.treeLeft = res.data.result
  348. if (this.treeLeft[0]) {
  349. this.getCenterTree(this.treeLeft[0].id)
  350. }
  351. }
  352. })
  353. },
  354. //获取商品分类二级列表
  355. getCenterTree(id) {
  356. this.$http.get("/sys/category/childList?pid=" + id, {}).then(res => {
  357. if (res.data.code == 0) {
  358. this.treeCenter = res.data.result
  359. if (this.treeCenter[0]) {
  360. this.getRightTree(this.treeCenter[0].id)
  361. }
  362. }
  363. })
  364. },
  365. //获取商品分类三级列表
  366. getRightTree(id) {
  367. this.$http.get("/sys/category/childList?pid=" + id, {}).then(res => {
  368. if (res.data.code == 0) {
  369. this.treeRight = res.data.result
  370. }
  371. })
  372. },
  373. //选中一级
  374. selectLeft(item, index) {
  375. this.showText = ''
  376. this.productType = []
  377. this.selectTypeList = []
  378. this.currentLeft = index
  379. this.currentCenter = null
  380. this.currentRight = null
  381. this.productType.push(item.id)
  382. this.selectTypeList.push(item.name)
  383. this.getCenterTree(item.id)
  384. },
  385. //选中二级
  386. selectRight(item, index) {
  387. this.currentCenter = index
  388. this.currentRight = null
  389. this.productType.push(item.id)
  390. this.selectTypeList.push(item.name)
  391. this.getRightTree(item.id)
  392. },
  393. //选中三级
  394. selectLast(item, index) {
  395. this.productType.push(item.id)
  396. this.selectTypeList.push(item.name)
  397. this.currentRight = index
  398. },
  399. //确定分类
  400. selectType() {
  401. this.isSelectType = false
  402. this.showText = this.selectTypeList.join('·')
  403. },
  404. //关闭选择分类弹窗
  405. closePopup() {
  406. this.isSelectType = false
  407. }
  408. },
  409. mounted() {
  410. this.getLeftTree()
  411. }
  412. }
  413. </script>
  414. <style lang="scss" scoped>
  415. .creat {
  416. width: 100vw;
  417. height: 100vh;
  418. background: #F7F8FC;
  419. display: flex;
  420. flex-direction: column;
  421. justify-content: space-between;
  422. .head {
  423. width: 100%;
  424. height: 112rpx;
  425. padding: 32rpx 24rpx;
  426. display: flex;
  427. align-items: center;
  428. background-color: #fff;
  429. position: relative;
  430. .cuIcon-back {
  431. font-size: 40rpx;
  432. margin-right: 40rpx;
  433. }
  434. .case {
  435. font-size: 36rpx;
  436. font-weight: 600;
  437. position: absolute;
  438. top: 50%;
  439. left: 50%;
  440. transform: translate(-50%, -50%);
  441. }
  442. .step {
  443. position: absolute;
  444. right: 20rpx;
  445. }
  446. }
  447. .content {
  448. width: 100%;
  449. flex: 1;
  450. padding: 24rpx;
  451. .titl {
  452. width: 100%;
  453. // height: 60rpx;
  454. font-weight: 500;
  455. margin-bottom: 16rpx;
  456. }
  457. .form {
  458. background-color: #fff;
  459. padding: 16rpx;
  460. border-radius: 16rpx;
  461. .item {
  462. width: 100%;
  463. height: 58rpx;
  464. border-bottom: 1px solid #EEEEEE;
  465. display: flex;
  466. // align-items: center;
  467. padding-bottom: 16rpx;
  468. margin-bottom: 16rpx;
  469. .label {
  470. margin-right: 20rpx;
  471. font-weight: 600;
  472. font-size: 28rpx;
  473. min-width: 126rpx;
  474. span {
  475. color: red;
  476. }
  477. }
  478. .picker {
  479. flex: 1;
  480. display: flex;
  481. align-items: center;
  482. justify-content: space-between;
  483. font-size: 28rpx;
  484. color: #999999;
  485. }
  486. .set {
  487. display: flex;
  488. justify-content: end;
  489. /deep/.u-input {
  490. text-align: right !important;
  491. }
  492. }
  493. }
  494. .upload {
  495. display: block;
  496. height: auto;
  497. .tips {
  498. font-size: 20rpx;
  499. color: #999999;
  500. margin-bottom: 16rpx;
  501. margin-top: 10rpx;
  502. }
  503. }
  504. .textarea {
  505. width: 100%;
  506. height: 196rpx;
  507. background: #F7F8FC;
  508. border-radius: 4rpx;
  509. padding: 12rpx 16rpx;
  510. font-size: 26rpx;
  511. margin-top: 12rpx;
  512. }
  513. .num {
  514. width: 100%;
  515. text-align: right;
  516. font-size: 24rpx;
  517. color: #999999;
  518. margin-top: 6rpx;
  519. }
  520. }
  521. }
  522. .btn {
  523. width: 100%;
  524. height: 112rpx;
  525. background-color: #fff;
  526. display: flex;
  527. justify-content: center;
  528. align-items: center;
  529. .next {
  530. width: 672rpx;
  531. height: 76rpx;
  532. border-radius: 54rpx;
  533. border: 1px solid #449AFF;
  534. margin: 0 auto;
  535. display: flex;
  536. justify-content: center;
  537. align-items: center;
  538. font-size: 28rpx;
  539. color: #449AFF;
  540. }
  541. .handle {
  542. width: 100%;
  543. display: flex;
  544. justify-content: space-around;
  545. .back {
  546. width: 205rpx;
  547. height: 76rpx;
  548. border-radius: 54rpx;
  549. border: 1px solid #449AFF;
  550. display: flex;
  551. align-items: center;
  552. justify-content: center;
  553. font-size: 28rpx;
  554. color: #449AFF;
  555. }
  556. .submit {
  557. width: 443rpx;
  558. height: 76rpx;
  559. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  560. border-radius: 53rpx;
  561. display: flex;
  562. align-items: center;
  563. justify-content: center;
  564. font-size: 28rpx;
  565. color: #FFFFFF;
  566. }
  567. }
  568. }
  569. .popup {
  570. width: 100vw;
  571. height: 100vh;
  572. position: fixed;
  573. top: 0;
  574. left: 0;
  575. background: rgba(0, 0, 0, 0.4);
  576. display: flex;
  577. align-items: end;
  578. z-index: 99;
  579. .model {
  580. width: 100%;
  581. background-color: #fff;
  582. border-radius: 20rpx 20rpx 0rpx 0rpx;
  583. padding: 0rpx 24rpx;
  584. padding-bottom: 20rpx;
  585. .title {
  586. width: 100%;
  587. height: 86rpx;
  588. display: flex;
  589. align-items: center;
  590. justify-content: center;
  591. border-bottom: 1px solid #EEEEEE;
  592. position: relative;
  593. image {
  594. width: 40rpx;
  595. height: 40rpx;
  596. position: absolute;
  597. right: 0px;
  598. }
  599. }
  600. .tree {
  601. display: flex;
  602. max-height: 546rpx;
  603. .left {
  604. overflow-y: auto;
  605. .item {
  606. width: 224rpx;
  607. height: 78rpx;
  608. padding: 20rpx;
  609. font-size: 26rpx;
  610. }
  611. .active {
  612. background: rgba(68, 154, 255, 0.1);
  613. color: #2983EC;
  614. }
  615. }
  616. .border {
  617. border-left: 1px solid #eeeeee;
  618. border-right: 1px solid #eeeeee;
  619. }
  620. }
  621. .sub {
  622. display: flex;
  623. justify-content: space-between;
  624. margin-top: 16rpx;
  625. border-top: 1px solid #eeeeee;
  626. padding-top: 16rpx;
  627. .submit {
  628. width: 672rpx;
  629. height: 76rpx;
  630. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  631. border-radius: 53rpx;
  632. display: flex;
  633. align-items: center;
  634. justify-content: center;
  635. font-size: 28rpx;
  636. color: #FFFFFF;
  637. }
  638. }
  639. }
  640. }
  641. }
  642. /deep/.u-upload__button {
  643. width: 250rpx !important;
  644. height: 250rpx !important;
  645. }
  646. </style>