addCommodity.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. <template>
  2. <view class="page" :style="{'height':(h)+'px','padding-top':mt+'px'}">
  3. <c-nav-bar title="添加商品" :showIcon="true"></c-nav-bar>
  4. <view class="body">
  5. <view class="typeInfo">
  6. <view class="cellBox">
  7. <text style="font-size: 32rpx; font-weight: 700;"><text class="req">*</text>商品名称</text>
  8. <input v-model="fromData.comboName" type="text" placeholder="请输入商品名称"
  9. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  10. </view>
  11. <view class="cellBox">
  12. <text style="font-size: 32rpx; font-weight: 700;"><text class="req">*</text>价格</text>
  13. <input v-model="fromData.price" type="text" placeholder="请输入价格"
  14. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  15. </view>
  16. <!-- <view class="cellBox">
  17. <text style="font-size: 32rpx; font-weight: 700;">库存</text>
  18. <input v-model="fromData.shortName" type="text" placeholder="请输入库存"
  19. style="width: 210rpx;height: 42rpx; font-size: 30rpx;flex:1" />
  20. </view> -->
  21. <view class="cellBox">
  22. <text style="font-size: 32rpx; font-weight: 700;"><text class="req">*</text>类型</text>
  23. <!-- <u-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
  24. <u-radio :customStyle="{marginBottom: '10px'}" v-for="(item, index) in radiolist1" :key="index"
  25. :label="item.name" :name="item.name" @change="radioChange">
  26. </u-radio>
  27. </u-radio-group> -->
  28. <u-radio-group @change="selectType" size="32" iconSize="24" v-model="fromData.comboType"
  29. placement="row" activeColor='#1372FF'>
  30. <u-radio labelSize='30' label="包桌" :name='1'></u-radio>
  31. <u-radio labelSize='30' label="按人均" :name='2' v-if="tabIndex==0"></u-radio>
  32. </u-radio-group>
  33. </view>
  34. <view class="uploadPic">
  35. <view style=" margin-left: 16rpx; margin-bottom: 22rpx;">
  36. <text style="font-size: 32rpx; font-weight: 700; "><text class="req">*</text>套餐内容</text>
  37. </view>
  38. <view class="textarea">
  39. <u--textarea v-model="fromData.comboExplain" height='310' placeholder="最多输入60个汉字"
  40. count></u--textarea>
  41. </view>
  42. </view>
  43. <view class="uploadPic">
  44. <view style=" margin-left: 16rpx;">
  45. <text style="font-size: 32rpx; font-weight: 700; "><text class="req">*</text> 主图/封面</text>
  46. </view>
  47. <view class="pic">
  48. <!-- 图片 -->
  49. <u-upload :fileList="cover" multiple :maxCount="1" :maxSize="1 * 1024 * 1024"
  50. @afterRead="afterReadcover" @oversize="overSize" width="180" height="180"
  51. @delete="deletePic">
  52. </u-upload>
  53. </view>
  54. </view>
  55. <view class="uploadPic">
  56. <view style=" margin-left: 16rpx;">
  57. <text style="font-size: 32rpx; font-weight: 700; "><text class="req">*</text>套餐照片</text>
  58. </view>
  59. <view class="pic">
  60. <!-- 图片 -->
  61. <u-upload :fileList="introduction" multiple :maxCount="5" :maxSize="5 * 1024 * 1024"
  62. @afterRead="afterRead" @oversize="overSize" width="180" height="180" @delete="deletePic">
  63. </u-upload>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 图片上传
  68. -->
  69. </view>
  70. <view class="btn-btn">
  71. <view class="hander-two">
  72. <view class="pop-btn-del" @click="Shelves(0)">
  73. 保存
  74. </view>
  75. <view class="pop-btn-add" @click="Shelves(1)">
  76. 立即上架
  77. </view>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <script>
  84. export default {
  85. data() {
  86. return {
  87. checked: false,
  88. weekedChecked: false,
  89. action: '', //图片服务器地址
  90. value2: '统计字数',
  91. introduction: [],
  92. introductioned: [],
  93. cover: [],
  94. covered: [],
  95. fromData: {
  96. comboName: "", //套餐名称
  97. comboType: '1', //套餐类型: 1包桌 2按人均
  98. cover: '', //主图/封面
  99. introduction: '', //图片 多个以,分割
  100. price: '', //价格
  101. status: '0', //是否上下架: 1是0否
  102. comboExplain: '', //说明
  103. homestayId: uni.getStorageSync('homestayId'),
  104. },
  105. radiolist1: [{
  106. name: '包桌',
  107. disabled: false
  108. },
  109. {
  110. name: '按人均',
  111. disabled: false
  112. },
  113. ],
  114. tabIndex: 0,
  115. }
  116. },
  117. onLoad() {},
  118. methods: {
  119. selectType(type) {
  120. console.log(type);
  121. this.typeIndex = type;
  122. this.fromData.comboType = type
  123. },
  124. // 保存 上架
  125. Shelves(status) {
  126. if (!this.fromData.comboName) return this.$showToast("请添商品名称");
  127. if (!this.fromData.price) return this.$showToast("请填写价格");
  128. if (!this.fromData.comboType) return this.$showToast("请选择套餐类型");
  129. if (!this.fromData.comboExplain) return this.$showToast("请填写套餐内容");
  130. if (!this.fromData.cover) return this.$showToast("请上传主图/封面");
  131. if (!this.fromData.introduction) return this.$showToast("请上传套餐照片");
  132. this.fromData.status = status
  133. this.$api.post('/merchant/hotel/repast', this.fromData).then(res => {
  134. console.log(res.data);
  135. if (res.data.code == 0) {
  136. if (status == 0) {
  137. this.$showToast('保存成功');
  138. setTimeout(() => {
  139. uni.navigateTo({
  140. url: '/pages/HotelMerchandise/index'
  141. })
  142. // uni.navigateBack(1)
  143. }, 1000);
  144. } else {
  145. this.$showToast('上架成功');
  146. setTimeout(() => {
  147. uni.navigateTo({
  148. url: '/pages/HotelMerchandise/index'
  149. })
  150. // uni.navigateBack(1)
  151. }, 1000);
  152. }
  153. } else this.$showToast(res.data.msg);
  154. })
  155. },
  156. // 删除图片
  157. deletePic(event) {
  158. this.introduction.splice(event.index, 1)
  159. },
  160. // 新增图片
  161. async afterReadcover(event) {
  162. const result = await this.uploadFilePromisecover(event.file[0].url);
  163. //图片路径
  164. },
  165. // 新增图片
  166. async afterRead(event) {
  167. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  168. let Lists = [].concat(event.file)
  169. for (let i = 0; i < Lists.length; i++) {
  170. const result = await this.uploadFilePromise(Lists[i].url)
  171. wx.getImageInfo({
  172. src: Lists[i].url,
  173. success: res => {
  174. }
  175. })
  176. }
  177. },
  178. //上传图片
  179. uploadFilePromisecover(url) {
  180. return new Promise((resolve, reject) => {
  181. let a = uni.uploadFile({
  182. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  183. filePath: url,
  184. name: 'file',
  185. header: {
  186. token: wx.getStorageSync('access_token')
  187. },
  188. success: (res) => {
  189. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  190. this.cover.push({
  191. url: data.data.url
  192. })
  193. this.covered.push(data.data.url)
  194. this.fromData.cover = this.covered.toString()
  195. console.log(this.covered);
  196. console.log(this.fromData.cover);
  197. resolve(data.data.url)
  198. }
  199. });
  200. })
  201. },
  202. //上传图片
  203. uploadFilePromise(url) {
  204. return new Promise((resolve, reject) => {
  205. let a = uni.uploadFile({
  206. url: 'https://i.ringzle.com/island-cloud-server/oss/file/upload',
  207. filePath: url,
  208. name: 'file',
  209. header: {
  210. token: wx.getStorageSync('access_token')
  211. },
  212. success: (res) => {
  213. let data = JSON.parse(res.data) //最终传给的是字符串,这里需要转换格式
  214. this.introduction.push({
  215. url: data.data.url
  216. })
  217. this.introductioned.push(data.data.url)
  218. this.fromData.introduction = this.introductioned.toString()
  219. console.log(this.introductioned);
  220. console.log(this.fromData.introduction);
  221. resolve(data.data.url)
  222. }
  223. });
  224. })
  225. },
  226. // 图片大小超出最大允许大小
  227. overSize(e) {
  228. uni.$u.toast('上传图片大小不能超过10MB!')
  229. },
  230. }
  231. }
  232. </script>
  233. <style lang="scss">
  234. .req {
  235. color: #f44;
  236. }
  237. .u-radio__icon-wrap--circle {
  238. margin-top: 10rpx !important;
  239. }
  240. .uicon-camera-fill {
  241. font-size: 50rpx !important;
  242. }
  243. .btn-btn {
  244. width: 100%;
  245. height: 136rpx;
  246. background-color: #fff;
  247. position: fixed;
  248. bottom: 0;
  249. // margin: 0 auto;
  250. z-index: 999999;
  251. // margin-top: 30rpx;
  252. // margin-left: 30rpx;
  253. .hander-two {
  254. display: flex;
  255. justify-content: space-between;
  256. align-items: center;
  257. margin: 30rpx 0;
  258. .pop-btn-del {
  259. margin: 0 15rpx;
  260. padding: 22rpx 136rpx;
  261. font-size: 32rpx;
  262. color: #111111;
  263. font-weight: Regular;
  264. background-color: #F0F2F5;
  265. border-radius: 50rpx;
  266. }
  267. .pop-btn-add {
  268. border-radius: 50rpx;
  269. margin: 0 15rpx;
  270. background-color: #1372FF;
  271. padding: 22rpx 100rpx;
  272. font-size: 32rpx;
  273. color: #FFFFFF;
  274. font-weight: Regular;
  275. }
  276. }
  277. }
  278. .btn {
  279. margin: 0 auto;
  280. width: 690rpx;
  281. height: 96rpx;
  282. background-color: #1372FF;
  283. color: #fff;
  284. display: flex;
  285. justify-content: center;
  286. align-items: center;
  287. font-size: 34rpx;
  288. border-radius: 48rpx;
  289. }
  290. .uicon-close {
  291. font-size: 30rpx !important;
  292. top: 8rpx !important;
  293. }
  294. .page {
  295. background: #F3F4F4;
  296. padding-bottom: 260rpx;
  297. box-sizing: border-box;
  298. overflow-y: auto;
  299. overflow-x: auto;
  300. }
  301. .body {
  302. padding-top: 20rpx;
  303. padding-left: 30rpx;
  304. padding-right: 30rpx;
  305. }
  306. .typeInfo {
  307. background-color: #fff;
  308. width: 100%;
  309. // height: 145px;
  310. border-radius: 5px;
  311. padding-top: 15px;
  312. padding-left: 7px;
  313. padding-right: 15px;
  314. box-sizing: border-box;
  315. }
  316. .titleInfo {
  317. // margin-top: 30rpx;
  318. margin-left: 20rpx;
  319. margin-bottom: 40rpx;
  320. }
  321. .cellBox {
  322. margin-left: 20rpx;
  323. display: flex;
  324. padding: 20rpx 0 30rpx;
  325. border-bottom: 1rpx solid #E1E1E1;
  326. text {
  327. margin-top: 10rpx;
  328. width: 170rpx;
  329. }
  330. }
  331. .bigRoom {
  332. margin-left: 20rpx;
  333. width: 100%;
  334. height: 102rpx;
  335. display: flex;
  336. // justify-content: center;
  337. align-items: center;
  338. }
  339. .shelves {
  340. width: 695rpx;
  341. height: 102rpx;
  342. background-color: #fff;
  343. margin-top: 20rpx;
  344. border-radius: 10rpx;
  345. display: flex;
  346. justify-content: space-between;
  347. align-items: center;
  348. // padding-left: 30rpx;
  349. // padding-right: 30rpx;
  350. }
  351. .uploadPic {
  352. padding-top: 28rpx;
  353. // width: 690rpx;
  354. // height: 293rpx;
  355. background-color: #fff;
  356. border-radius: 10rpx;
  357. margin-top: 20rpx;
  358. }
  359. .pic {
  360. // margin-left: 30rpx;
  361. // margin-top: 20rpx;
  362. // width: 190rpx;
  363. // height: 120rpx;
  364. margin: 20rpx 26rpx;
  365. padding-bottom: 20rpx;
  366. }
  367. // .custom-upload-button{
  368. // width: 190rpx;
  369. // height: 120rpx;
  370. // }
  371. .priceInfo {
  372. width: 690rpx;
  373. // height: 908rpx;
  374. background-color: #fff;
  375. border-radius: 10rpx;
  376. margin-top: 20rpx;
  377. padding-top: 30rpx;
  378. }
  379. .week {
  380. padding-left: 30rpx;
  381. padding-right: 30rpx;
  382. margin-bottom: 20rpx;
  383. }
  384. .weekend {
  385. display: flex;
  386. justify-content: space-between;
  387. border-bottom: 1rpx solid #E1E1E1;
  388. padding-bottom: 30rpx;
  389. }
  390. .everyDay {
  391. padding-left: 30rpx;
  392. padding-right: 30rpx;
  393. width: 100%;
  394. // background-color: pink;
  395. height: 102rpx;
  396. display: flex;
  397. align-items: center;
  398. }
  399. .days {
  400. display: flex;
  401. align-items: center;
  402. border-bottom: 1rpx solid #E1E1E1;
  403. padding-bottom: 30rpx;
  404. }
  405. .priceBoxWeek {
  406. display: flex;
  407. align-items: center;
  408. padding-left: 30rpx;
  409. padding-right: 30rpx;
  410. }
  411. .weekendBox {
  412. width: 630rpx;
  413. display: flex;
  414. align-items: center;
  415. // margin-right: 90rpx;
  416. // justify-content: space-between;
  417. border-bottom: 1rpx solid #E1E1E1;
  418. height: 102rpx;
  419. overflow: hidden;
  420. box-sizing: border-box;
  421. }
  422. .everyHouseList {
  423. // padding-right: 30rpx;
  424. width: 690rpx;
  425. // height: 908rpx;
  426. background-color: #fff;
  427. border-radius: 10rpx;
  428. margin-top: 20rpx;
  429. // padding-top: 30rpx;
  430. }
  431. .HouseListTitleInfo {
  432. margin-right: 30rpx;
  433. margin-left: 20rpx;
  434. margin-bottom: 40rpx;
  435. display: flex;
  436. justify-content: space-between;
  437. }
  438. .submit {
  439. margin-top: 20rpx;
  440. border-radius: 10rpx;
  441. width: 690rpx;
  442. height: 102rpx;
  443. background-color: #fff;
  444. display: flex;
  445. justify-content: center;
  446. align-items: center;
  447. }
  448. .addSubmit {
  449. width: 100%;
  450. position: fixed;
  451. /* 固定定位 */
  452. bottom: 20rpx;
  453. /* 底部对齐 */
  454. left: 0;
  455. /* 可选:左对齐 */
  456. // width: 690rpx;
  457. /* 可选:宽度为 100% */
  458. height: 96rpx;
  459. margin-left: 30rpx;
  460. // padding-top: 20rpx;
  461. margin-top: 30rpx;
  462. background-color: #1372FF;
  463. border-radius: 48rpx;
  464. }
  465. .uploadPicPic {
  466. position: relative;
  467. top: -96rpx;
  468. }
  469. .u-upload__deletable[data-v-69e2a36e] {
  470. width: 0 !important;
  471. }
  472. </style>