uploadP.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <view class="content">
  3. <swiper class="swiper-box" :skip-hidden-item-layout='true' :style="{ height: maxheight }" disable-touch
  4. :current="current">
  5. <swiper-item>
  6. <scroll-view scroll-y="true" style="height: 100%;">
  7. <view class="tip">
  8. 最多可以添加3张商品图片
  9. </view>
  10. <view class="banner-box">
  11. <view class="banner" v-for="(item,index) in imageList" :key="index">
  12. <view class="banner-main">
  13. <image :src="item" mode=""></image>
  14. </view>
  15. <image class="cha" @click.stop="delImg(index)" src="../../static/img/cha.png" mode="">
  16. </image>
  17. </view>
  18. <view class="banner" v-if="imageList.length < 3" @click="navCroper(400,400,'banner')">
  19. <image src="../../static/img/addP.png" mode=""></image>
  20. </view>
  21. </view>
  22. <view class="main">
  23. <view class="box-1">
  24. <view class="box-left">
  25. 商品名称
  26. <text class="imp">*</text>
  27. </view>
  28. <input type="text" placeholder="请填写商品名称" value="" class="list-input" v-model="name" />
  29. </view>
  30. <view class="box-1">
  31. <view class="box-left">
  32. 商品编码
  33. <text class="imp">*</text>
  34. </view>
  35. <input type="text" placeholder="请填写商品编码" value="" class="list-input" v-model="bianma" />
  36. </view>
  37. <!-- <classify v-if="classify.length != 0" :list="classify" :choose="chooseClass"
  38. @chooseClasswc="chooseClasswc"></classify> -->
  39. <!-- <view class="box-1">
  40. <view class="box-left">运费模板</view>
  41. <picker @change="bindYf" :range="yfarray" range-key="name" class="list-input">
  42. <text>{{ yf.name }}</text>
  43. </picker>
  44. </view> -->
  45. <view class="box-1">
  46. <view class="box-left">商品规格</view>
  47. <u-radio-group @change="radioGroupChange" v-model="isdanname">
  48. <u-radio v-for="(item, index) in list" :key="index" :name="item">
  49. {{item}}
  50. </u-radio>
  51. </u-radio-group>
  52. </view>
  53. <arrts :value="values" :item="item" @getarrts="getarrts" ref='attr' :baseURL="baseURL"
  54. v-if="isdan === 1"></arrts>
  55. <view class="box-1" v-if="isdan === 0">
  56. <view class="box-left">
  57. 商品规格图片
  58. <text class="imp">*</text>
  59. </view>
  60. <view class="box-image" @click="navCroper(400,400,'guige')">
  61. <image v-if="guige" :src="guige" mode=""></image>
  62. <image v-else src="../../static/img/addP.png" mode=""></image>
  63. </view>
  64. </view>
  65. <view class="box-1" v-if="isdan === 0">
  66. <view class="box-left">
  67. 商品售价
  68. <text class="imp">*</text>
  69. </view>
  70. <input type="text" placeholder="请填写商品售价" value="" class="list-input" v-model="price" />
  71. </view>
  72. <view class="box-1" v-if="isdan === 0">
  73. <view class="box-left">
  74. 商品成本价
  75. <text class="imp">*</text>
  76. </view>
  77. <input type="text" placeholder="请填写商品成本价" value="" class="list-input" v-model="o_price" />
  78. </view>
  79. <view class="box-1" v-if="isdan === 0">
  80. <view class="box-left">
  81. 商品原价
  82. <text class="imp">*</text>
  83. </view>
  84. <input type="text" placeholder="请填写商品原价" value="" class="list-input" v-model="y_price" />
  85. </view>
  86. <view class="box-1" v-if="isdan === 0">
  87. <view class="box-left">
  88. 佣金计算值
  89. <text class="imp">*</text>
  90. </view>
  91. <input type="text" placeholder="请填写佣金计算值" value="" class="list-input"
  92. v-model="breakprice" />
  93. </view>
  94. <view class="box-1" v-if="isdan === 0">
  95. <view class="box-left">
  96. 库存
  97. <text class="imp">*</text>
  98. </view>
  99. <input type="text" placeholder="请填写库存" value="" class="list-input" v-model="stock" />
  100. </view>
  101. <view class="box-1" v-if="isdan === 0">
  102. <view class="box-left">
  103. 编码
  104. <text class="imp">*</text>
  105. </view>
  106. <input type="text" placeholder="请填写编码" value="" class="list-input" v-model="bian" />
  107. </view>
  108. </view>
  109. <view class="btn" @click="save()">
  110. 提交审核
  111. </view>
  112. <!-- <view class="btn" @click="next()">
  113. 下一页
  114. </view> -->
  115. </scroll-view>
  116. </swiper-item>
  117. <!-- <swiper-item v-if="showNext">
  118. <scroll-view scroll-y="true" style="height: 100%; padding-bottom: 20rpx;">
  119. <view class="bjq">
  120. <jinEdit v-if="isshow ==1" ref="set" placeholder="请输入文章内容" @editOk="editOk"
  121. uploadFileUrl="/api/upload/image" :header="{'Authori-zation': AuthoriZation}"
  122. :showImgSize="true" :html="content" height="50vh"></jinEdit>
  123. </view>
  124. <view class="btn1" @click="before()">
  125. 上一页
  126. </view>
  127. <view class="btn" @click="save()">
  128. 提交审核
  129. </view>
  130. </scroll-view>
  131. </swiper-item> -->
  132. </swiper>
  133. </view>
  134. </template>
  135. <script>
  136. import jinEdit from '@/components/jin-edit/jin-edit.vue';
  137. import arrts from './child/arrts.vue'
  138. import classify from './child/classify.vue';
  139. import {
  140. mapState
  141. } from "vuex";
  142. import {
  143. temp_list,
  144. get_product_info,
  145. save,
  146. set_apply
  147. } from '@/api/upload.js'
  148. export default {
  149. components: {
  150. classify,
  151. jinEdit,
  152. arrts
  153. },
  154. onReady() {
  155. // 初始化获取页面宽度
  156. var obj = this;
  157. uni.getSystemInfo({
  158. success: resu => {
  159. const query = uni.createSelectorQuery();
  160. query.select('.swiper-box').boundingClientRect();
  161. query.exec(function(res) {
  162. obj.maxheight = resu.windowHeight - res[0].top + 'px';
  163. console.log(obj.maxheight, 132456);
  164. });
  165. },
  166. fail: res => {}
  167. });
  168. },
  169. data() {
  170. return {
  171. showNext: false, //默认不显示第二页
  172. maxheight: '',
  173. origin_id: 0,
  174. isshow: 0,
  175. product: {},
  176. item: [],
  177. id: 0,
  178. values: [],
  179. current: 0, //当前页数
  180. yfarray: [], //运费列表
  181. yf: {
  182. name: '请选择运费模板'
  183. }, //运费
  184. imageList: [], //轮播图列表
  185. name: '', //商品名称
  186. bianma: '', //商品编码
  187. list: ['单规格', '多规格'],
  188. isdan: '',
  189. isdanname: '',
  190. chooseClass: [],
  191. classify: [], //商品分类
  192. guige: '', //单规格图片
  193. price: '', //单规格售价
  194. o_price: '', //单规格成本价
  195. y_price: '', //单规格原价
  196. breakprice: '', //单规格佣金计算值
  197. stock: '', //单规格库存
  198. bian: '', //单规格编码
  199. content: '', //商品详情
  200. AuthoriZation: '', //请求头
  201. };
  202. },
  203. computed: {
  204. ...mapState(['baseURL']),
  205. },
  206. onLoad(opt) {
  207. if (opt.id) {
  208. this.id = opt.id
  209. }
  210. this.AuthoriZation = 'Bearer ' + uni.getStorageSync('token')
  211. this.getclass()
  212. },
  213. onShow() {},
  214. onReachBottom() {},
  215. methods: {
  216. editOk(res) {
  217. // 保存富文本转出的html
  218. this.content = res.html
  219. console.log(this.content);
  220. },
  221. getarrts(res, val) {
  222. this.values = res
  223. this.item = val
  224. },
  225. getclass() {
  226. const obj = this
  227. get_product_info({}, obj.id).then(({
  228. data
  229. }) => {
  230. obj.yfarray = data.tempList
  231. obj.yf = data.tempList.filter(e => {
  232. return e.id == 1
  233. })
  234. obj.yf = obj.yf[0]
  235. obj.chooseClass = data.cateList.filter(e => {
  236. return e.value == 55
  237. })
  238. console.log(obj.chooseClass, 'yfmb');
  239. obj.classify = data.cateList
  240. console.log(obj.classify, '123456');
  241. obj.product = data.productInfo
  242. let info = data.productInfo
  243. if (obj.id != 0) {
  244. obj.name = info.store_name;
  245. obj.bianma = info.set_code;
  246. obj.isdan = info.spec_type;
  247. obj.isdanname = info.spec_type == 0 ? '单规格' : '多规格'
  248. info.cate_id.forEach(e => {
  249. for (let i = 0; i < data.cateList.length; i++) {
  250. if (data.cateList[i].value == e) {
  251. this.chooseClass.push(data.cateList[i])
  252. }
  253. }
  254. })
  255. data.tempList.forEach(e => {
  256. if (e.id == info.temp_id) {
  257. this.yf = e
  258. }
  259. })
  260. if (info.spec_type == 0) {
  261. obj.guige = info.attr.pic;
  262. obj.price = info.attr.price;
  263. obj.o_price = info.attr.cost;
  264. obj.y_price = info.attr.ot_price;
  265. obj.breakprice = info.attr.brokerage_origin;
  266. obj.stock = info.attr.stock;
  267. obj.bian = info.attr.bar_code;
  268. }
  269. if (info.spec_type == 1) {
  270. obj.values = info.attrs;
  271. obj.item = [...info.items];
  272. console.log(obj.values, '12345');
  273. }
  274. obj.content = info.description;
  275. obj.imageList = info.slider_image;
  276. obj.origin_id = info.origin_id;
  277. }
  278. obj.isshow = 1;
  279. })
  280. },
  281. upLoad(path) {
  282. // #ifdef H5
  283. console.log(path, 'h5');
  284. // #endif
  285. uni.showLoading({
  286. title: '图片上传中',
  287. mask: true
  288. });
  289. return new Promise((resolve, error) => {
  290. uni.uploadFile({
  291. url: this.baseURL + '/api/upload/image', //仅为示例,非真实的接口地址
  292. filePath: path,
  293. name: 'file',
  294. header: {
  295. "Authori-zation": 'Bearer ' + uni.getStorageSync('token')
  296. },
  297. success: (uploadFileRes) => {
  298. console.log(uploadFileRes, '1245');
  299. if ("string" === typeof uploadFileRes.data) {
  300. resolve(JSON.parse(uploadFileRes.data).data)
  301. } else {
  302. resolve(uploadFileRes.data.data)
  303. }
  304. },
  305. complete() {
  306. uni.hideLoading()
  307. }
  308. });
  309. })
  310. },
  311. bindYf: function(e) {
  312. this.yf = this.yfarray[e.target.value];
  313. },
  314. save() {
  315. uni.showLoading({
  316. title: '商品上传中',
  317. mask: true
  318. });
  319. const obj = this
  320. this.$refs.attr.succ()
  321. let attr = {}
  322. let attrs = []
  323. if (this.isdan == 0) {
  324. attr = {
  325. bar_code: obj.bian,
  326. brokerage: 0,
  327. brokerage_origin: obj.breakprice,
  328. brokerage_two: 0,
  329. cost: obj.o_price,
  330. integral: 0,
  331. ot_price: obj.y_price,
  332. pic: obj.guige,
  333. price: obj.price,
  334. stock: obj.stock,
  335. volume: 0,
  336. weight: 0
  337. }
  338. attrs.push(attr)
  339. }
  340. if (this.isdan == 1) {
  341. attr = obj.values[0]
  342. attrs = obj.values
  343. }
  344. let cate_id = []
  345. obj.chooseClass.forEach(e => {
  346. console.log(e, 'eee');
  347. cate_id.push(e.value + '')
  348. })
  349. console.log(cate_id, '654321');
  350. setTimeout(() => {
  351. save({
  352. activity: ['秒杀', '砍价', '拼团', ],
  353. attr: attr,
  354. attrs: attrs,
  355. cate_id: cate_id,
  356. commission: 0,
  357. description: obj.content,
  358. ficti: 0,
  359. give_integral: 0,
  360. image: obj.imageList[0],
  361. is_benefit: 0,
  362. is_best: 0,
  363. is_good: 0,
  364. is_hot: 0,
  365. is_new: 0,
  366. is_show: 1,
  367. is_sub: 0,
  368. items: obj.item,
  369. keyword: '',
  370. postage: '',
  371. price: '',
  372. set_code: obj.bianma,
  373. slider_image: obj.imageList,
  374. sort: 0,
  375. spec_type: obj.isdan,
  376. store_info: '',
  377. store_name: obj.name,
  378. store_type: 1,
  379. temp_id: obj.yf.id,
  380. unit_name: '',
  381. video_link: '',
  382. origin_id: obj.origin_id ? obj.origin_id : obj.id
  383. }, 0).then(({
  384. data
  385. }) => {
  386. console.log(data, 'success');
  387. set_apply({}, data.id).then(e => {
  388. uni.hideLoading()
  389. obj.$api.msg('提交审核成功')
  390. uni.navigateTo({
  391. url: '/pages/upload/commodity'
  392. })
  393. }).catch(e => {
  394. uni.hideLoading()
  395. })
  396. }).catch(err => {
  397. uni.hideLoading()
  398. console.log(err, '123456');
  399. })
  400. }, 200)
  401. },
  402. navCroper(w, h, type) {
  403. let that = this;
  404. this.onImg().then((url) => {
  405. uni.navigateTo({
  406. url: `/pages/set/cropper?width=${w}&height=${h}`,
  407. events: {
  408. uploadSuccess(res) {
  409. uni.showLoading({
  410. title: '图片上传中',
  411. mask: true
  412. });
  413. that.upLoad(res).then((urldata) => {
  414. if (type == 'banner') {
  415. that.imageList.push(urldata.url)
  416. }
  417. if (type == 'guige') {
  418. that.guige = urldata.url
  419. }
  420. uni.hideLoading()
  421. }).catch(err => {
  422. uni.hideLoading()
  423. })
  424. }
  425. },
  426. success: function(res) {
  427. // 通过eventChannel向被打开页面传送数据
  428. res.eventChannel.emit('urlNext', {
  429. url
  430. })
  431. }
  432. })
  433. })
  434. },
  435. onImg(type) {
  436. const _this = this
  437. return new Promise((ok, erro) => {
  438. // 判断是否需要选择
  439. uni.showActionSheet({
  440. itemList: ['拍照', '选择一张照片'],
  441. success: function(res) {
  442. _this.chooseImage(res.tapIndex).then((url) => {
  443. ok(url)
  444. }).catch((res) => {
  445. erro(res)
  446. })
  447. },
  448. fail: function(res) {
  449. erro(res)
  450. console.log(res.errMsg);
  451. }
  452. });
  453. })
  454. },
  455. chooseImage: function(index) {
  456. const _this = this
  457. return new Promise((ok, error) => {
  458. // 从相册/相机选择
  459. // 如需直接开相机或直接选相册,请只使用一个选项
  460. const sourceType = index === 0 ? ['camera'] : ['album']
  461. uni.chooseImage({
  462. count: 1, //默认9
  463. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  464. sourceType: sourceType,
  465. success: function(res) {
  466. ok(res.tempFilePaths[0])
  467. },
  468. fail(e) {
  469. uni.showModal({
  470. title: '文件打开错误',
  471. content: '请设置授权文件存储权限',
  472. showCancel: false,
  473. });
  474. error(e)
  475. }
  476. });
  477. })
  478. },
  479. radioGroupChange(e) {
  480. if (e == '单规格') {
  481. this.isdan = 0
  482. } else {
  483. this.isdan = 1
  484. }
  485. console.log(this.isdan);
  486. },
  487. chooseClasswc(e) {
  488. this.chooseClass = e;
  489. },
  490. //删除图片
  491. delImg(i) {
  492. uni.showModal({
  493. content: '确定删除这张吗',
  494. success: res => {
  495. if (res.confirm) {
  496. this.imageList.splice(i, 1);
  497. } else if (res.cancel) {}
  498. }
  499. });
  500. },
  501. }
  502. };
  503. </script>
  504. <style lang="scss">
  505. page,
  506. .content {
  507. min-height: 100%;
  508. height: auto;
  509. background: #f8f8f8;
  510. }
  511. .tip {
  512. font-size: 24rpx;
  513. color: #fd3939;
  514. padding: 10rpx 20rpx;
  515. }
  516. .banner-box {
  517. background: #ffffff;
  518. padding: 20rpx;
  519. display: flex;
  520. align-items: center;
  521. flex-wrap: wrap;
  522. image {
  523. width: 100%;
  524. height: 100%;
  525. }
  526. .banner {
  527. position: relative;
  528. width: 160rpx;
  529. height: 160rpx;
  530. margin-right: 10rpx;
  531. .banner-main {
  532. position: absolute;
  533. top: 0;
  534. left: 0;
  535. right: 0;
  536. width: 160rpx;
  537. height: 160rpx;
  538. border-radius: 20rpx;
  539. image {
  540. border-radius: 20rpx;
  541. }
  542. }
  543. .cha {
  544. position: absolute;
  545. top: 0;
  546. right: 0;
  547. width: 40rpx;
  548. height: 40rpx;
  549. }
  550. }
  551. }
  552. .main {
  553. background: #ffffff;
  554. margin-top: 20rpx;
  555. padding: 0 20rpx 20rpx;
  556. }
  557. .box-1 {
  558. display: flex;
  559. justify-content: space-between;
  560. align-items: center;
  561. width: 100%;
  562. padding-top: 20rpx;
  563. .box-left {
  564. padding-left: 2rpx;
  565. width: 50%;
  566. text-align: left;
  567. color: #000000;
  568. .imp {
  569. color: #e63931;
  570. }
  571. }
  572. input {
  573. height: 66rpx;
  574. line-height: 66rpx;
  575. // height: 88rpx;
  576. }
  577. .list-input {
  578. color: #9598a3;
  579. height: 66rpx;
  580. padding-left: 24rpx;
  581. font-size: 28rpx;
  582. display: flex;
  583. justify-content: flex-end;
  584. align-items: center;
  585. width: 50%;
  586. flex: 1;
  587. text-align: right;
  588. padding-right: 24rpx;
  589. .input-placeholder {
  590. height: 70rpx;
  591. color: #959595;
  592. }
  593. }
  594. .box-image {
  595. height: 66rpx;
  596. width: 66rpx;
  597. image {
  598. width: 100%;
  599. height: 100%;
  600. }
  601. }
  602. }
  603. .btn {
  604. display: flex;
  605. justify-content: center;
  606. align-items: center;
  607. width: 560rpx;
  608. height: 76rpx;
  609. background: #000000;
  610. border-radius: 38rpx;
  611. font-size: 34rpx;
  612. font-weight: 500;
  613. color: #ffffff;
  614. margin: 40rpx auto 20rpx;
  615. }
  616. .btn1 {
  617. display: flex;
  618. justify-content: center;
  619. align-items: center;
  620. width: 560rpx;
  621. height: 76rpx;
  622. background: #ffffff;
  623. border: 1px solid #000000;
  624. border-radius: 38rpx;
  625. font-size: 34rpx;
  626. font-weight: 500;
  627. color: #000000;
  628. margin: 40rpx auto 20rpx;
  629. }
  630. .bjq {
  631. background: #ffffff;
  632. padding: 20rpx;
  633. }
  634. </style>