group.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view class="group">
  3. <view class="top"></view>
  4. <view class="head">
  5. <view class="head_left">
  6. <span class="cuIcon-back" @click="back"></span>
  7. </view>
  8. <view class="case">
  9. 商品详情
  10. </view>
  11. </view>
  12. <view class="content">
  13. <view class="center">
  14. <view class="title">
  15. 组合套餐
  16. </view>
  17. <view class="list" v-for="(item,index) in groupList" :key="index">
  18. <view class="name">{{item.groupName}}</view>
  19. <view class="single" v-for="(row,ind) in item.singleProduct" :key="ind">
  20. <view class="single_name">
  21. {{row.productName}}
  22. </view>
  23. <view class="single_price">
  24. {{row.quantity}}{{row.unit}}/{{row.price}}元
  25. <!-- <span class="cuIcon-deletefill"></span> -->
  26. <span @click="remove(index,ind)">删除</span>
  27. </view>
  28. </view>
  29. <view class="handle">
  30. <view class="delete" @click="deleteGroup(index)">
  31. 删除
  32. </view>
  33. <view class="addSingle" @click="addSingle(item,index)">
  34. 添加单品
  35. </view>
  36. </view>
  37. </view>
  38. <view class="add_group" @click="isAddGroup = true">
  39. <image src="/static/product/add.png" mode=""></image>
  40. 添加商品组
  41. </view>
  42. </view>
  43. </view>
  44. <view class="foot">
  45. <view class="btn" @click="save">
  46. 保存
  47. </view>
  48. </view>
  49. <!-- 添加商品组 -->
  50. <view class="popup" v-if="isAddGroup">
  51. <view class="model">
  52. <view class="title">
  53. 输入商品组名称
  54. <image src="/static/index/cut.png" mode="" @click="isAddGroup = false"></image>
  55. </view>
  56. <view class="inp">
  57. <u-input v-model="name" placeholder="限30字" />
  58. </view>
  59. <view class="btn">
  60. <view class="cancel" @click="cancel">取消</view>
  61. <view class="sub" @click="addGroup">确定</view>
  62. </view>
  63. </view>
  64. </view>
  65. <!-- 添加单品 -->
  66. <view class="popup" v-if="isAddSingle">
  67. <view class="model">
  68. <view class="title">
  69. 添加单品
  70. <image src="/static/index/cut.png" mode="" @click="isAddSingle = false"></image>
  71. </view>
  72. <view class="inp">
  73. <view class="single">
  74. 名称<u-input v-model="singleProduct.productName" placeholder="请输入单品名称" />
  75. </view>
  76. <view class="single">
  77. 数量<u-input type="number" v-model="singleProduct.quantity" placeholder="请输入数量" />
  78. </view>
  79. <view class="single">
  80. 单位<u-input v-model="singleProduct.unit" placeholder="请输入单位" />
  81. </view>
  82. <view class="single">
  83. 价格<u-input type="number" v-model="singleProduct.price" placeholder="请输入价格" />
  84. </view>
  85. </view>
  86. <view class="btn">
  87. <view class="cancel" @click="cancelSingle">取消</view>
  88. <view class="continue" @click="continu">确定并继续添加</view>
  89. <view class="subSingle" @click="subSingle">确定</view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. export default {
  97. data() {
  98. return {
  99. name: '',
  100. groupList: [],
  101. isAddGroup: false,
  102. isAddSingle: false,
  103. singleProduct: {
  104. productName: '',
  105. quantity: '',
  106. unit: '',
  107. price: ''
  108. },
  109. singleIndex: null,//商品组下标
  110. }
  111. },
  112. methods: {
  113. //添加商品组
  114. addGroup() {
  115. if (this.name !== '') {
  116. this.isAddGroup = false
  117. this.groupList.push({
  118. groupName: this.name,
  119. singleProduct: []
  120. })
  121. this.name = ''
  122. this.isAddSingle = true
  123. this.singleIndex = this.groupList.length - 1
  124. }
  125. },
  126. //取消添加商品组
  127. cancel() {
  128. this.isAddGroup = false
  129. this.name = ''
  130. },
  131. //添加单品弹窗出现
  132. addSingle(item, index) {
  133. this.isAddSingle = true
  134. this.singleIndex = index
  135. },
  136. //继续添加单品
  137. continu() {
  138. this.subSingle()
  139. },
  140. //取消添加单品
  141. cancelSingle() {
  142. this.isAddSingle = false
  143. this.isAddGroup = false
  144. this.singleProduct = {
  145. productName: '',
  146. quantity: '',
  147. unit: '',
  148. price: ''
  149. }
  150. },
  151. //确定添加单品
  152. subSingle() {
  153. this.groupList[this.singleIndex].singleProduct.push(this.singleProduct)
  154. this.isAddGroup = false
  155. this.isAddSingle = false
  156. this.singleProduct = {
  157. productName: '',
  158. quantity: '',
  159. unit: '',
  160. price: ''
  161. }
  162. },
  163. //删除单品
  164. remove(index, ind) {
  165. this.groupList[index].singleProduct.splice(ind, 1)
  166. },
  167. //删除商品组
  168. deleteGroup(index){
  169. this.groupList.splice(index,1)
  170. },
  171. //返回
  172. back() {
  173. uni.navigateBack({
  174. delta: 1
  175. });
  176. },
  177. //保存
  178. save(){
  179. // console.log(this.groupList)
  180. // let objStr = JSON.stringify(this.groupList);
  181. // uni.navigateTo({
  182. // url: `/pages/product/creatProduct?data=${encodeURIComponent(objStr)}`
  183. // })
  184. uni.setStorage({
  185. key:'group',
  186. data:this.groupList
  187. })
  188. this.back()
  189. }
  190. },
  191. onShow() {
  192. let that = this
  193. uni.getStorage({
  194. key: 'group',
  195. success: function(res) {
  196. that.groupList = res.data
  197. }
  198. })
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .group {
  204. width: 100vw;
  205. height: 100vh;
  206. display: flex;
  207. flex-direction: column;
  208. justify-content: space-between;
  209. background: #F7F8FC;
  210. /*#ifdef APP-PLUS*/
  211. .top {
  212. width: 100%;
  213. height: var(--status-bar-height);
  214. background-color: #fff;
  215. }
  216. /*#endif*/
  217. .head {
  218. width: 100%;
  219. padding: 20rpx;
  220. background-color: #fff;
  221. display: flex;
  222. justify-content: space-between;
  223. align-items: center;
  224. position: relative;
  225. .head_left {
  226. font-size: 40rpx;
  227. }
  228. .case {
  229. position: absolute;
  230. left: 50%;
  231. top: 50%;
  232. transform: translate(-50%, -50%);
  233. font-size: 36rpx;
  234. font-weight: 600;
  235. }
  236. }
  237. .content {
  238. width: 100%;
  239. flex: 1;
  240. padding: 20rpx;
  241. overflow-y: auto;
  242. .center {
  243. background-color: #fff;
  244. padding: 16rpx 20rpx;
  245. .title {
  246. font-size: 28rpx;
  247. font-weight: 600;
  248. margin-bottom: 20rpx;
  249. }
  250. }
  251. .add_group {
  252. width: 100%;
  253. height: 135rpx;
  254. margin: 20rpx auto 0px;
  255. background: #F7F8FC;
  256. display: flex;
  257. flex-direction: column;
  258. justify-content: center;
  259. align-items: center;
  260. font-size: 22rpx;
  261. color: #449AFF;
  262. image {
  263. width: 52rpx;
  264. height: 52rpx;
  265. }
  266. }
  267. .list {
  268. width: 100%;
  269. // height: 70rpx;
  270. background: #F7F8FC;
  271. border-radius: 8rpx;
  272. margin-top: 20rpx;
  273. border-radius: 20rpx;
  274. padding: 20rpx;
  275. .name {
  276. width: 100%;
  277. height: 40rpx;
  278. // padding: 20rpx;
  279. font-weight: 600;
  280. margin-bottom: 16rpx;
  281. }
  282. .single {
  283. width: 100%;
  284. // display: flex;
  285. // align-items: center;
  286. // justify-content: space-between;
  287. margin-bottom: 16rpx;
  288. .single_name {
  289. width: 100%;
  290. font-size: 26rpx;
  291. }
  292. .single_price {
  293. font-size: 24rpx;
  294. color: #888888;
  295. display: flex;
  296. justify-content: space-between;
  297. align-items: center;
  298. span {
  299. display: block;
  300. width: 112rpx;
  301. height: 47rpx;
  302. background: #FFFFFF;
  303. border-radius: 4rpx;
  304. border: 1px solid #EEEEEE;
  305. text-align: center;
  306. line-height: 47rpx;
  307. font-size: 24rpx;
  308. }
  309. }
  310. }
  311. .handle{
  312. width: 100%;
  313. display: flex;
  314. justify-content: space-between;
  315. .delete{
  316. width: 45%;
  317. height: 61rpx;
  318. background: rgba(243,79,79,0.1);
  319. border-radius: 12rpx;
  320. border: 1px solid #F34F4F;
  321. font-size: 28rpx;
  322. color: #F34F4F;
  323. display: flex;
  324. align-items: center;
  325. justify-content: center;
  326. }
  327. .addSingle {
  328. width: 45%;
  329. height: 61rpx;
  330. background: rgba(68, 154, 255, 0.1);
  331. border-radius: 12rpx;
  332. border: 1px solid #449AFF;
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. }
  337. }
  338. }
  339. }
  340. .foot {
  341. width: 100%;
  342. height: 112rpx;
  343. background-color: #fff;
  344. display: flex;
  345. align-items: center;
  346. justify-content: center;
  347. .operate {
  348. width: 100%;
  349. display: flex;
  350. justify-content: space-between;
  351. align-items: center;
  352. padding: 0px 20rpx;
  353. .delete {
  354. width: 205rpx;
  355. height: 76rpx;
  356. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  357. border-radius: 49rpx;
  358. font-size: 28rpx;
  359. color: #FFFFFF;
  360. display: flex;
  361. justify-content: center;
  362. align-items: center;
  363. margin-right: 24rpx;
  364. margin-left: 140rpx;
  365. }
  366. .all {
  367. width: 25%;
  368. // height: 60rpx;
  369. // border: 1px solid #999;
  370. display: flex;
  371. justify-content: center;
  372. align-items: center;
  373. image {
  374. width: 40rpx;
  375. height: 40rpx;
  376. margin-right: 10rpx;
  377. }
  378. }
  379. }
  380. .btn {
  381. width: 672rpx;
  382. height: 76rpx;
  383. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  384. border-radius: 75rpx;
  385. font-size: 28rpx;
  386. color: #FFFFFF;
  387. display: flex;
  388. align-items: center;
  389. justify-content: center;
  390. }
  391. }
  392. .popup {
  393. width: 100vw;
  394. height: 100vh;
  395. position: fixed;
  396. top: 0;
  397. left: 0;
  398. background: rgba(0, 0, 0, 0.4);
  399. display: flex;
  400. align-items: flex-end;
  401. z-index: 99;
  402. .model {
  403. width: 100%;
  404. background-color: #fff;
  405. border-radius: 20rpx 20rpx 0rpx 0rpx;
  406. padding: 0rpx 24rpx;
  407. padding-bottom: 20rpx;
  408. .title {
  409. width: 100%;
  410. height: 86rpx;
  411. display: flex;
  412. align-items: center;
  413. justify-content: center;
  414. position: relative;
  415. border-bottom: 1px solid #eeeeee;
  416. margin-bottom: 24rpx;
  417. image {
  418. width: 40rpx;
  419. height: 40rpx;
  420. position: absolute;
  421. right: 0px;
  422. }
  423. }
  424. .inp {
  425. width: 100%;
  426. min-height: 68rpx;
  427. background: #F7F8FC;
  428. border-radius: 4rpx;
  429. //
  430. .single {
  431. width: 100%;
  432. padding: 0rpx 20rpx;
  433. display: flex;
  434. align-items: center;
  435. // justify-content: space-between;
  436. background-color: #eee;
  437. margin-bottom: 20rpx;
  438. }
  439. }
  440. .btn {
  441. width: 100%;
  442. height: 100rpx;
  443. display: flex;
  444. justify-content: space-around;
  445. align-items: center;
  446. border-top: 1px solid #eeeeee;
  447. margin-top: 24rpx;
  448. .cancel {
  449. width: 205rpx;
  450. height: 76rpx;
  451. border-radius: 54rpx;
  452. border: 1px solid #CCCCCC;
  453. font-size: 28rpx;
  454. color: #999999;
  455. display: flex;
  456. align-items: center;
  457. justify-content: center;
  458. }
  459. .sub {
  460. width: 443rpx;
  461. height: 76rpx;
  462. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  463. border-radius: 53rpx;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. font-size: 28rpx;
  468. color: #FFFFFF;
  469. }
  470. .continue {
  471. width: 232rpx;
  472. height: 76rpx;
  473. background: linear-gradient(90deg, #77B6FF 0%, #449AFF 100%);
  474. border-radius: 53rpx;
  475. display: flex;
  476. align-items: center;
  477. justify-content: center;
  478. font-size: 28rpx;
  479. color: #FFFFFF;
  480. }
  481. .subSingle {
  482. width: 232rpx;
  483. height: 76rpx;
  484. background: linear-gradient(90deg, #FFA05B 0%, #FF7918 100%);
  485. border-radius: 49rpx;
  486. display: flex;
  487. align-items: center;
  488. justify-content: center;
  489. font-size: 28rpx;
  490. color: #FFFFFF;
  491. }
  492. }
  493. }
  494. }
  495. }
  496. ::v-deep.u-input {
  497. text-align: right !important;
  498. }
  499. </style>