goods.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. <template>
  2. <view class="padding">
  3. <view class="text-white padding bg radius">
  4. <div style="color:red;">新增商品默认库存为1000件,需要修改可点击操作批量修改库存</div>
  5. <u-form :model="shop" label-position="top">
  6. <u-form-item label="商品标题">
  7. <u-input v-model="shop.goodsName" placeholder="请填写商品标题" />
  8. </u-form-item>
  9. <u-form-item label="商品分类">
  10. <u-input v-model="shop.classifyName" placeholder="请选择" :disabled="true" @click="getflshow()" />
  11. </u-form-item>
  12. <u-form-item label="商品标签">
  13. <!-- <u-input v-model="" placeholder="请填写" /> -->
  14. <view class="flex align-center flex-wrap margin-bottom-sm">
  15. <view v-for="(item,index) in goodsLabel" :key="index" class="btn flex align-center margin-top">
  16. <view>{{item}}</view>
  17. <view class="margin-left-sm" @tap.stop="bindupdata(index)">x</view>
  18. </view>
  19. <view class="btns margin-top" @click="addtype1()">+添加</view>
  20. </view>
  21. </u-form-item>
  22. <u-form-item label="商品原价(选填)">
  23. <u-input v-model="shop.originalMoney" @input="ZheKouInput" placeholder="请填写" />
  24. </u-form-item>
  25. <u-form-item label="打包费(选填)">
  26. <u-input v-model="shop.packMoney" placeholder="请填写" />
  27. </u-form-item>
  28. <u-form-item label="商品售价">
  29. <u-input v-model="shop.goodsMoney" @input="ZheKouInput" placeholder="请填写" />
  30. </u-form-item>
  31. <view class="padding bg radius margin-tb" style="padding: 10px 0;">
  32. <view>
  33. <view class="text-lg" style="color: #333;">商品描述(选填)</view>
  34. <view class="margin-tb-sm">
  35. <u-input v-model="shop.goodsDescribe" type="textarea" height="200" placeholde="请描述一下您的特长"
  36. maxlengt="200" :clearable="false" style="background:#F5F5F5;" />
  37. </view>
  38. </view>
  39. <view>
  40. <view class="text-lg margin-top-sm text-black">商品封面图</view>
  41. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  42. <view v-if="shop.goodsCover.length">
  43. <view class="margin-top flex margin-right-sm flex-wrap">
  44. <view class="flex"
  45. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;">
  46. <image :src="shop.goodsCover" style="width: 100%;height: 100%;"></image>
  47. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  48. @click="removeImgs()">
  49. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="margin-top" @click="addImage(1)" v-if="shop.goodsCover.length<=0">
  55. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  56. class="flex justify-center align-center">
  57. <view>
  58. <view class="text-center">
  59. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  60. </image>
  61. </view>
  62. <view class="text-center text-black">添加图片</view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <view>
  69. <view class="text-lg margin-top-sm text-black">商品轮播图(可多张)</view>
  70. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  71. <view v-if="goodsPicture.length">
  72. <view class="margin-top flex margin-right-sm flex-wrap">
  73. <view class="flex"
  74. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;"
  75. v-for="(image,index) in goodsPicture" :key="index">
  76. <image :src="image" style="width: 100%;height: 100%;"></image>
  77. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  78. @click="removeImg(index,'lb')">
  79. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. <view class="margin-top" @click="addImages(1)" v-if="goodsPicture.length<=5">
  85. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  86. class="flex justify-center align-center">
  87. <view>
  88. <view class="text-center">
  89. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  90. </image>
  91. </view>
  92. <view class="text-center text-black">添加图片</view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view>
  99. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)(选填)</view>
  100. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  101. <view v-if="goodsParticularsPicture.length">
  102. <view class="margin-top flex margin-right-sm flex-wrap">
  103. <view class="flex"
  104. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;"
  105. v-for="(image,index) in goodsParticularsPicture" :key="index">
  106. <image :src="image" style="width: 100%;height: 100%;"></image>
  107. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  108. @click="removeImg(index,'sq')">
  109. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  110. </view>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length<=5">
  115. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  116. class="flex justify-center align-center">
  117. <view>
  118. <view class="text-center">
  119. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  120. </image>
  121. </view>
  122. <view class="text-center text-black">添加图片</view>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. </view>
  128. <!-- <view>
  129. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)</view>
  130. <editor id="editor"
  131. style="height:350rpx;color: #000000;font-size: 28rpx;width: 100%;border: 2rpx solid #F0F0F0;padding: 16rpx;"
  132. placeholder="请输入商品详情" @ready="onEditorReady" @input="getText"></editor>
  133. </view>
  134. <view>
  135. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length<=1">
  136. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  137. class="flex justify-center align-center">
  138. <view>
  139. <view class="text-center">
  140. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  141. </image>
  142. </view>
  143. <view class="text-center text-black">添加图片</view>
  144. </view>
  145. </view>
  146. </view>
  147. </view> -->
  148. </view>
  149. <u-form-item label="规格类型">
  150. <u-input v-model="attrsType" placeholder="请选择" :disabled="true" @click="ggShow()" />
  151. </u-form-item>
  152. <u-form-item label="商品规格" v-if="attrsid==2">
  153. <view style="width: 100%;">
  154. <view style="display: flex;width: 100%;">
  155. <u-input style="width: 80%;" v-model="attrs" placeholder="请选择" :disabled="true"
  156. @click="openguige()" />
  157. <view style="width: 20%;text-align: right;color: #FF4701;" v-if="attrs"
  158. @click="goGuiGeItem()">
  159. 修改价格</view>
  160. </view>
  161. <view style="color: #FF4701;font-size: 24upx;">*修改商品、商品售价后,商品规格将重置,请谨慎操作!</view>
  162. </view>
  163. </u-form-item>
  164. </u-form>
  165. </view>
  166. <u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="square" :hair-line="false">提交
  167. </u-button>
  168. <!-- 规格弹框 -->
  169. <u-popup v-model="Guigeshow" mode="bottom" border-radius="14" :closeable="closeable">
  170. <view>
  171. <scroll-view scroll-y="true">
  172. <view class="padding" style="margin-bottom: 70px;">
  173. <view>规格类型</view>
  174. <view class="flex align-center margin-top-sm flex-wrap">
  175. <view class="" v-for="(item,indexs) in list" :key="indexs">
  176. <view class="btn margin-top-sm flex align-center flex-wrap"
  177. :class="listIndex == indexs?'boxH':''" @click="bindguige(indexs,1,item.ruleName)">
  178. {{item.ruleName}}
  179. </view>
  180. <!-- <view class="btns margin-top-sm" @click="addtype(1)">+添加</view> -->
  181. </view>
  182. </view>
  183. <view v-for="(name,index) in attrList.ruleValue" :key="index">
  184. <view class="margin-top-sm">{{name.value}}</view>
  185. <view class="flex align-center flex-wrap margin-top-sm">
  186. <!-- :class="typeIndex1 == index&&typeIndex == ind?'active':''" -->
  187. <view class="btn margin-top-sm" v-for="(ite,ind) in name.detail1" :key='ind'
  188. @click="bindguige(ind,2,name.detail,index)" v-if="name.detail1">
  189. {{ite}}
  190. </view>
  191. <!-- <view class="btns margin-top-sm">+添加</view> -->
  192. </view>
  193. </view>
  194. </view>
  195. </scroll-view>
  196. <view class="addguige" @click="bindget()">确定</view>
  197. </view>
  198. </u-popup>
  199. <u-select v-model="flshow" :list="ClassifyList" valueName='classifyId' labelName="classifyName"
  200. @confirm="confirm">
  201. </u-select>
  202. <!-- 规格类型 -->
  203. <u-select v-model="ggshow" :list="attrList1" valueName='id' labelName="name" @confirm="ggconfirm">
  204. </u-select>
  205. <!-- 添加规格弹框 -->
  206. <u-popup v-model="show2" mode="center" border-radius="14" width="500rpx" height="300rpx" :closeable="closeable">
  207. <view>
  208. <view class="padding">
  209. <view>添加标签</view>
  210. <view>
  211. <u-input v-model="typeName" placeholder="请填写" />
  212. </view>
  213. </view>
  214. <view class="addguiges" @click="bindclose1()">确定</view>
  215. </view>
  216. </u-popup>
  217. </view>
  218. </template>
  219. <script>
  220. import configdata from '@/common/config.js';
  221. export default {
  222. data() {
  223. return {
  224. shop: {
  225. goodsName: '',
  226. classifyId: '',
  227. classifyName: '',
  228. goodsLabel: [],
  229. attr: [],
  230. sku: [],
  231. originalMoney: '',
  232. packMoney: 0,
  233. goodsMoney: '',
  234. goodsDescribe: '',
  235. //详情图
  236. goodsCover: '',
  237. goodsPicture: [],
  238. goodsParticularsPicture: [],
  239. shopId: uni.getStorageSync('shopId')
  240. },
  241. shops: {
  242. goodsName: '',
  243. classifyId: '',
  244. classifyName: '',
  245. goodsLabel: [],
  246. attr: [],
  247. sku: [],
  248. originalMoney: '',
  249. packMoney: 0,
  250. goodsMoney: '',
  251. goodsDescribe: '',
  252. //详情图
  253. goodsCover: '',
  254. goodsPicture: [],
  255. goodsParticularsPicture: [],
  256. shopId: uni.getStorageSync('shopId')
  257. },
  258. attrs: '',
  259. goodsLabel: [],
  260. goodsPicture: [],
  261. goodsParticularsPicture: [],
  262. customStyle: {
  263. backgroundColor: '#FFCC00',
  264. color: '#000000',
  265. border: 0
  266. },
  267. status: 1,
  268. customStyle1: {
  269. color: '#000000',
  270. position: "fixed",
  271. bottom: "15rpx",
  272. left: "0rpx",
  273. right: "0rpx",
  274. margin: "0rpx 50rpx",
  275. backgroundColor: '#FFCC00',
  276. },
  277. Guigeshow: false,
  278. //详情图
  279. goodsCover: [],
  280. shopId: '',
  281. page: 1,
  282. limit: 100,
  283. list: [],
  284. listIndex: 0,
  285. typeIndex: 0,
  286. typeIndex1: 0,
  287. wdIndex: 0,
  288. show: false,
  289. typeName: '',
  290. shows: false,
  291. typeperature: '',
  292. flshow: false,
  293. ggshow: false,
  294. ClassifyList: [],
  295. attrList: {},
  296. attrLists: [],
  297. shopId: '',
  298. show2: false,
  299. update: 0,
  300. count: 6,
  301. editorCtx: '',
  302. htmlMessage: '',
  303. closeable: true,
  304. attrsType: '多规格',
  305. attrsid: 2,
  306. attrList1: [{
  307. 'name': '单规格',
  308. 'id': 1
  309. },
  310. {
  311. 'name': '多规格',
  312. 'id': 2
  313. }
  314. ],
  315. }
  316. },
  317. onLoad(option) {
  318. console.log('option', option)
  319. if (option.goodsId) {
  320. this.update = 1
  321. uni.setNavigationBarTitle({
  322. title: '修改商品'
  323. })
  324. this.goodsDet(option.goodsId)
  325. } else {
  326. this.update = 0
  327. }
  328. // console.log(option, '店铺id')
  329. // this.shopId = option.shopId
  330. this.shopId = this.$queue.getData("shopId")
  331. this.getguige()
  332. // this.onEditorReady();
  333. },
  334. onShow() {
  335. let list = this.$queue.getData('guigeSelectItemList');
  336. if (list) {
  337. this.shop.sku = list;
  338. this.$queue.remove('guigeSelectItemList');
  339. }
  340. this.getClassifyList()
  341. },
  342. methods: {
  343. ZheKouInput(e) {
  344. console.log(e)
  345. this.attrs = '';
  346. this.shop.attr = []
  347. if (this.attrsid == 1) {
  348. this.guigeclect()
  349. } else {
  350. this.getgoodslist()
  351. }
  352. },
  353. goGuiGeItem() {
  354. this.$queue.setData('guigeSelectItemList', this.shop.sku)
  355. uni.navigateTo({
  356. url: '/my/publish/guigeitem'
  357. });
  358. },
  359. //获取分类
  360. getflshow() {
  361. console.log(this.ClassifyList.length)
  362. if (this.ClassifyList.length == 0) {
  363. uni.navigateTo({
  364. url: '/my/store/fenlei'
  365. })
  366. } else {
  367. this.flshow = true
  368. }
  369. },
  370. // 规格类型
  371. ggShow() {
  372. this.ggshow = true
  373. },
  374. //获取商品规格列表
  375. getgoodslist() {
  376. let ruleValues = this.attrList.ruleValue
  377. for (var j = 0; j < ruleValues.length; j++) {
  378. let details = ruleValues[j].detail;
  379. ruleValues[j].detail = ruleValues[j].detail.toString();
  380. }
  381. let data = {
  382. attrName: this.attrList.ruleName,
  383. attrValue: ruleValues,
  384. ruleId: this.attrList.id,
  385. }
  386. this.$Request.postJsonA("/admin/goods/isFormatAttr?coverImg=" + this.shop.goodsCover + '&originalPrice=' +
  387. this.shop.originalMoney + '&price=' + this.shop.goodsMoney, data).then(res => {
  388. if (res.code == 0) {
  389. // this.shop.sku.push(res.data.value)
  390. this.shop.sku = res.data.value
  391. console.log(res.data.value, '111', this.shop.sku)
  392. }
  393. });
  394. },
  395. //获取规格
  396. bindget() {
  397. this.getgoodslist()
  398. this.attrs = this.attrList.ruleName
  399. var obj = {}
  400. obj.attrName = this.attrList.ruleName
  401. obj.attrValue = this.attrList.ruleValue
  402. obj.ruleId = this.attrList.id
  403. this.shop.attr.push(obj)
  404. this.Guigeshow = false
  405. },
  406. //商品分类
  407. confirm(e) {
  408. // console.log(e)
  409. this.shop.classifyName = e[0].label
  410. this.shop.classifyId = e[0].value
  411. },
  412. //规格分类
  413. ggconfirm(e) {
  414. // console.log(e)
  415. this.attrsType = e[0].label
  416. this.attrsid = e[0].value
  417. if (e[0].value == 1) {
  418. this.shop.attr = []
  419. this.guigeclect()
  420. }
  421. },
  422. // 单规格
  423. guigeclect() {
  424. this.$Request.getA("/admin/goods/onlyFormatAttr?coverImg=" + this.shop.goodsCover + '&originalPrice=' +
  425. this.shop.originalMoney + '&price=' + this.shop.goodsMoney).then(res => {
  426. if (res.code == 0) {
  427. // this.shop.sku.push(res.data.value)
  428. this.shop.sku = res.data.value
  429. console.log(res.data.value, '111', this.shop.sku)
  430. }
  431. });
  432. },
  433. addtype(index) {
  434. if (index == 1) {
  435. this.show = true
  436. } else if (index == 2) {
  437. this.shows = true
  438. }
  439. },
  440. bindclose() {
  441. if (index == 1) {
  442. this.show = false
  443. } else if (index == 2) {
  444. this.shows = false
  445. }
  446. },
  447. //弹框规格切换
  448. bindguige(index, e, name, index1) {
  449. // console.log(index, e, name)
  450. if (e == 1) {
  451. this.listIndex = index
  452. this.attrList = this.list[index]
  453. } else if (e == 2) {
  454. this.typeIndex = index
  455. this.typeIndex1 = index1
  456. } else if (e == 3) {
  457. this.wdIndex = index
  458. }
  459. },
  460. //规格弹框
  461. openguige() {
  462. if (!this.attrList.ruleValue) {
  463. uni.showToast({
  464. title: '暂无规格',
  465. icon: 'none',
  466. duration: 1000
  467. })
  468. return
  469. }
  470. // 打开规格选项弹框
  471. this.Guigeshow = true
  472. },
  473. //获取商品规格
  474. getguige() {
  475. let data = {
  476. // page: this.page,
  477. // limit: this.limit,
  478. shopId: this.shopId,
  479. }
  480. this.$Request.getA("/selfGoodsRule/list", data).then(res => {
  481. if (res.code == 0) {
  482. // this.shop.sku = res.data
  483. if (res.data.length > 0) {
  484. this.list = res.data
  485. this.list.forEach(res => {
  486. res.ruleValue.forEach(ret => {
  487. ret.detail = ret.detail.split(',')
  488. ret.detail1 = ret.detail
  489. })
  490. })
  491. console.log('this.attrList', this.list)
  492. this.attrList = this.list[0]
  493. if (this.shop.attr && this.shop.attr.length > 0) {
  494. for (var i in res.data) {
  495. if (this.shop.attr[0].ruleId == res.data[i].id) {
  496. this.attrs = res.data[i].ruleName
  497. }
  498. }
  499. }
  500. }
  501. }
  502. });
  503. },
  504. // 商品类型
  505. getClassifyList() {
  506. this.$Request.getA("/admin/goods/selectAllClassify?shopId=" + this.shopId).then(res => {
  507. if (res.code == 0) {
  508. this.ClassifyList = res.data
  509. this.counts = this.ClassifyList[0].classifyId
  510. if (this.shop.classifyId != '') {
  511. for (var i in res.data) {
  512. if (this.shop.classifyId == res.data[i].classifyId) {
  513. this.shop.classifyName = res.data[i].classifyName
  514. }
  515. }
  516. }
  517. }
  518. });
  519. },
  520. getStarttime(e) {
  521. console.log(e)
  522. console.log(this.shop)
  523. this.shop.openTime = e.hour + ':' + e.minute
  524. },
  525. getEndtime(e) {
  526. console.log(e)
  527. this.shop.closeTime = e.hour + ':' + e.minute
  528. },
  529. // 详情图删除
  530. removeImg(index, texts) {
  531. if (texts == 'lb') {
  532. this.goodsPicture.splice(index, 1)
  533. } else if (texts == 'sq') {
  534. this.goodsParticularsPicture.splice(index, 1)
  535. }
  536. },
  537. // 身份证 资格证删除
  538. removeImgs() {
  539. // if (index == 1) {
  540. this.shop.goodsCover = ''
  541. // }
  542. },
  543. bindOpen(e) {
  544. console.log(e)
  545. let that = this
  546. uni.chooseLocation({
  547. success: function(res) {
  548. console.log('位置名称:' + res.name);
  549. console.log('详细地址:' + res.address);
  550. console.log('纬度:' + res.latitude);
  551. console.log('经度:' + res.longitude);
  552. that.shop.detailedAddress = res.address
  553. that.shop.shopLat = res.latitude
  554. that.shop.shopLng = res.longitude
  555. }
  556. });
  557. },
  558. // 图片上传
  559. addImages(e) {
  560. if (e == 1) {
  561. var num = this.goodsPicture.length
  562. this.count = 6 - num
  563. }
  564. if (e == 2) {
  565. var num = this.goodsParticularsPicture.length
  566. this.count = 6 - num
  567. }
  568. let that = this
  569. uni.chooseImage({
  570. count: this.count,
  571. sourceType: ['album', 'camera'],
  572. success: res => {
  573. for (let i = 0; i < res.tempFilePaths.length; i++) {
  574. that.$queue.showLoading("上传中...");
  575. uni.uploadFile({ // 上传接口
  576. url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
  577. // url: 'https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload',
  578. filePath: res.tempFilePaths[i],
  579. name: 'file',
  580. success: (uploadFileRes) => {
  581. if (e == 1) {
  582. if (that.goodsPicture.length < 6) {
  583. that.goodsPicture.push(JSON.parse(uploadFileRes.data)
  584. .data)
  585. }
  586. } else if (e == 2) {
  587. if (that.goodsParticularsPicture.length < 6) {
  588. that.goodsParticularsPicture.push(JSON.parse(
  589. uploadFileRes.data).data)
  590. }
  591. console.log(that.goodsParticularsPicture)
  592. }
  593. uni.hideLoading();
  594. }
  595. });
  596. }
  597. }
  598. })
  599. },
  600. // 图片上传
  601. addImage(e) {
  602. let that = this
  603. uni.chooseImage({
  604. count: 1,
  605. sourceType: ['album', 'camera'],
  606. success: res => {
  607. for (let i = 0; i < res.tempFilePaths.length; i++) {
  608. that.$queue.showLoading("上传中...");
  609. uni.uploadFile({ // 上传接口
  610. // url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
  611. url: 'https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload',
  612. filePath: res.tempFilePaths[i],
  613. name: 'file',
  614. success: (uploadFileRes) => {
  615. if (e == 1) {
  616. that.shop.goodsCover = JSON.parse(uploadFileRes.data).data
  617. }
  618. uni.hideLoading();
  619. }
  620. });
  621. }
  622. }
  623. })
  624. },
  625. config: function(name) {
  626. var info = null;
  627. if (name) {
  628. var name2 = name.split("."); //字符分割
  629. if (name2.length > 1) {
  630. info = configdata[name2[0]][name2[1]] || null;
  631. } else {
  632. info = configdata[name] || null;
  633. }
  634. if (info == null) {
  635. let web_config = cache.get("web_config");
  636. if (web_config) {
  637. if (name2.length > 1) {
  638. info = web_config[name2[0]][name2[1]] || null;
  639. } else {
  640. info = web_config[name] || null;
  641. }
  642. }
  643. }
  644. }
  645. return info;
  646. },
  647. // 发布
  648. submit() {
  649. this.shop.goodsPicture = this.goodsPicture
  650. this.shop.goodsPicture = this.goodsPicture.toString();
  651. this.shop.goodsParticularsPicture = this.goodsParticularsPicture.toString();
  652. this.shop.goodsLabel = this.goodsLabel.toString();
  653. if (!this.shop.goodsName) {
  654. uni.showToast({
  655. title: '请填写商品标题',
  656. icon: 'none',
  657. duration: 1000
  658. })
  659. return
  660. }
  661. if (!this.shop.classifyName) {
  662. uni.showToast({
  663. title: '请选择商品分类',
  664. icon: 'none',
  665. duration: 1000
  666. })
  667. return
  668. }
  669. if (!this.shop.goodsLabel) {
  670. uni.showToast({
  671. title: '请填写商品标签',
  672. icon: 'none',
  673. duration: 1000
  674. })
  675. return
  676. }
  677. if (!this.shop.originalMoney) {
  678. this.shop.originalMoney=this.shop.goodsMoney
  679. // uni.showToast({
  680. // title: '请填写商品原价',
  681. // icon: 'none',
  682. // duration: 1000
  683. // })
  684. // return
  685. }
  686. // console.log(this.shop.packMoney,'------------')
  687. // if (this.shop.packMoney*1 != '') {
  688. // uni.showToast({
  689. // title: '请填写商品打包费',
  690. // icon: 'none',
  691. // duration: 1000
  692. // })
  693. // return
  694. // }
  695. if (!this.shop.goodsMoney) {
  696. uni.showToast({
  697. title: '请填写商品售价',
  698. icon: 'none',
  699. duration: 1000
  700. })
  701. return
  702. }
  703. if (!this.shop.goodsDescribe) {
  704. this.shop.goodsDescribe='无'
  705. // uni.showToast({
  706. // title: '请填写商品描述',
  707. // icon: 'none',
  708. // duration: 1000
  709. // })
  710. // return
  711. }
  712. if (!this.shop.goodsCover) {
  713. uni.showToast({
  714. title: '请上传商品封面图',
  715. icon: 'none',
  716. duration: 1000
  717. })
  718. return
  719. }
  720. if (!this.shop.goodsPicture) {
  721. uni.showToast({
  722. title: '请上传商品轮播图',
  723. icon: 'none',
  724. duration: 1000
  725. })
  726. return
  727. }
  728. if (!this.shop.goodsParticularsPicture) {
  729. this.goodsParticularsPicture=['https://moxuanyunshang.oss-cn-beijing.aliyuncs.com/xiangqing/12ecc56005731327e02f42f0d851848.png']
  730. // uni.showToast({
  731. // title: '请上传商品详情图',
  732. // icon: 'none',
  733. // duration: 1000
  734. // })
  735. // return
  736. }
  737. if (this.attrsid == 2) {
  738. if (this.shop.attr.length == 0) {
  739. uni.showToast({
  740. title: '请选择商品规格',
  741. icon: 'none',
  742. duration: 1000
  743. })
  744. return
  745. }
  746. }
  747. let shops = this.shop;
  748. for (var i = 0; i < shops.attr.length; i++) {
  749. let attrValues = shops.attr[i].attrValue;
  750. for (var j = 0; j < attrValues.length; j++) {
  751. let details = attrValues[j].detail;
  752. let detailss = '';
  753. for (var z = 0; z < details.length; z++) {
  754. detailss = detailss + details[z];
  755. }
  756. shops.attr[i].attrValue[j].detail = detailss
  757. }
  758. }
  759. if (this.update == 0) {
  760. var url = '/admin/goods/insertGoods'
  761. }
  762. if (this.update == 1) {
  763. var url = '/admin/goods/update'
  764. }
  765. this.$Request.postJsonA(url, shops).then(res => {
  766. if (res.code == 0) {
  767. uni.showToast({
  768. title: '操作成功',
  769. icon: 'none'
  770. })
  771. setTimeout(function() {
  772. uni.navigateBack()
  773. }, 1000)
  774. } else {
  775. uni.showToast({
  776. title: res.msg,
  777. icon: 'none'
  778. })
  779. }
  780. });
  781. },
  782. //删除规格
  783. bindupdata(index) {
  784. console.log('this.shop.goodsLabel', typeof this.goodsLabel)
  785. this.goodsLabel.splice(index, 1)
  786. },
  787. addtype1() {
  788. this.typeName = ''
  789. this.show2 = true
  790. },
  791. bindclose1() {
  792. if (!this.typeName) {
  793. uni.showToast({
  794. title: '请填写规格',
  795. icon: 'none',
  796. duration: 1000
  797. })
  798. return
  799. }
  800. this.goodsLabel.push(this.typeName)
  801. this.show2 = false
  802. },
  803. // 获取商铺详情
  804. goodsDet(goodsId) {
  805. this.$Request.getA("/admin/goods/selectGoodsById?goodsId=" + goodsId).then(res => {
  806. if (res.code == 0) {
  807. this.dataCentre = res.data;
  808. this.shop = res.data;
  809. this.getClassifyList()
  810. if (this.shop.goodsLabel) {
  811. this.goodsLabel = this.shop.goodsLabel.split(',')
  812. }
  813. if (this.shop.goodsPicture) {
  814. this.goodsPicture = this.shop.goodsPicture.split(',')
  815. }
  816. if (this.shop.goodsParticularsPicture) {
  817. this.goodsParticularsPicture = this.shop.goodsParticularsPicture.split(',')
  818. }
  819. if (res.data.attr.length == 0) {
  820. this.attrsid = 1
  821. this.attrsType = '单规格'
  822. } else {
  823. this.attrsid = 2
  824. this.attrsType = '多规格'
  825. }
  826. this.getguige()
  827. }
  828. });
  829. }
  830. }
  831. }
  832. </script>
  833. <style>
  834. page {
  835. background-color: #F5F5F5;
  836. }
  837. .bg {
  838. background-color: #FFFFFF;
  839. }
  840. .btn {
  841. border: 1upx solid #CCCCCC;
  842. border-radius: 10px;
  843. padding: 0rpx 30rpx;
  844. margin-right: 25rpx;
  845. height: 30px;
  846. line-height: 30px;
  847. }
  848. .boxH {
  849. background: #FCD202;
  850. border: none;
  851. }
  852. .btns {
  853. border: 1upx dashed #333333;
  854. border-radius: 28px;
  855. padding: 0rpx 35rpx;
  856. margin-right: 25rpx;
  857. height: 30px;
  858. line-height: 30px;
  859. }
  860. .active {
  861. background: #FCD202;
  862. border: none;
  863. }
  864. .actives {
  865. background: #FCD202;
  866. border: none;
  867. }
  868. .addguige {
  869. width: 90%;
  870. margin: 0 auto;
  871. background: #FCD202;
  872. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  873. border-radius: 16upx;
  874. text-align: center;
  875. height: 88upx;
  876. line-height: 88upx;
  877. position: fixed;
  878. bottom: 25upx;
  879. left: 0;
  880. right: 0;
  881. }
  882. .addguiges {
  883. width: 90%;
  884. margin: 0 auto;
  885. background: #FCD202;
  886. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  887. border-radius: 16upx;
  888. text-align: center;
  889. height: 88upx;
  890. line-height: 88upx;
  891. /* position: fixed;
  892. bottom: 25upx;
  893. left: 0;
  894. right: 0; */
  895. }
  896. .u-input__textarea {
  897. background-color: #f5f5f5 !important;
  898. padding: 10rpx !important;
  899. }
  900. </style>