uploadP.vue 15 KB

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