release.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <view class="container-release">
  3. <navbar :config="config" backColor="#666666"></navbar>
  4. <view class="main">
  5. <u-form :model="form" ref="formRef" label-width="150">
  6. <u-form-item label="所属分类" prop="classifyLabel">
  7. <u-input v-model="form.classifyLabel" type="select" placeholder="请选择" placeholder-style="text-align: right"
  8. @click="classifyShow = true" />
  9. </u-form-item>
  10. <u-form-item label="所属类型" prop="typeLabel">
  11. <u-input v-model="form.typeLabel" type="select" placeholder="请选择" placeholder-style="text-align: right"
  12. @click="typeShow = true" />
  13. </u-form-item>
  14. <u-form-item label="名称" prop="name">
  15. <u-input v-model="form.name" placeholder="请输入" placeholder-style="text-align: right" />
  16. </u-form-item>
  17. <u-form-item label="售价(¥)" prop="price">
  18. <u-input v-model="form.price" placeholder="请输入" placeholder-style="text-align: right" />
  19. </u-form-item>
  20. <u-form-item label="原价(¥)" prop="original_price">
  21. <u-input v-model="form.original_price" placeholder="请输入" placeholder-style="text-align: right" />
  22. </u-form-item>
  23. <u-form-item label="图片" label-position="top" prop="img">
  24. <!-- <u-upload :action="action" @on-success="onSuccessImg"
  25. :file-list="form.img" max-count="1"></u-upload> -->
  26. <uploadImg imgCount="1" uploadImgCount="1" :imgArr="img" :type="upimgtype" url="" @result="resultImg">
  27. </uploadImg>
  28. </u-form-item>
  29. <u-form-item label="图文详情" label-position="top" class="content-box" prop="details">
  30. <u-input v-model="form.details" maxlength="600" type="textarea" placeholder="请输入" @input="detailsChange" />
  31. <view class="content"><text>{{enterNum}}</text>/600</view>
  32. </u-form-item>
  33. <u-form-item>
  34. <!-- <u-upload :action="action" @on-success="onSuccessImgs" :file-list="form.detailsImages" max-count="6">
  35. </u-upload> -->
  36. <uploadImg imgCount="6" uploadImgCount="6" :imgArr="detailsImages" :type="upimgtype" url=""
  37. @result="resultImgs"></uploadImg>
  38. </u-form-item>
  39. </u-form>
  40. </view>
  41. <u-select v-model="classifyShow" label-name="name" value-name="id" :list="classifyList"
  42. :default-value="[classifyIndex]" @confirm="classifyConfirm"></u-select>
  43. <u-select v-model="typeShow" label-name="name" value-name="id" :list="typeList" :default-value="[typeIndex]"
  44. @confirm="typeConfirm"></u-select>
  45. <view class="footer">
  46. <view class="online-btn btn" @click="submit(0)">保存</view>
  47. <view class="btn" @click="submit(1)">提交发布</view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import uploadImg from "../../../components/uploadImg/imgUpload.vue"
  53. export default {
  54. components: {
  55. uploadImg
  56. },
  57. data() {
  58. return {
  59. config: {
  60. back: true,
  61. title: '发布商品',
  62. color: '#1A1A1A',
  63. backgroundColor: [1, "#fff"],
  64. statusBarFontColor: '#1A1A1A',
  65. leftSlot: true
  66. },
  67. shopId: '',
  68. form: {},
  69. action: this.$mConfig.baseUrl + '/sys/oss/upload',
  70. detailsImages: [],
  71. upimgtype: 'other',
  72. img: [],
  73. classifyShow: false,
  74. classifyList: [],
  75. classifyIndex: 0,
  76. typeList: [{
  77. name: '商品',
  78. id: 0
  79. },
  80. {
  81. name: '服务',
  82. id: 1
  83. }
  84. ],
  85. typeIndex: 0,
  86. typeShow: false,
  87. enterNum: 0,
  88. rules: {
  89. classifyLabel: [{
  90. required: true,
  91. message: '所属分类不能为空',
  92. trigger: ['change', 'blur'],
  93. }],
  94. typeLabel: [{
  95. required: true,
  96. message: '所属类型不能为空',
  97. trigger: ['change', 'blur'],
  98. }],
  99. name: [{
  100. required: true,
  101. message: '名称不能为空',
  102. trigger: ['change', 'blur'],
  103. }],
  104. price: [{
  105. required: true,
  106. message: '售价不能为空',
  107. trigger: ['change', 'blur'],
  108. }, {
  109. // 自定义验证函数,见上说明
  110. validator: (rule, value, callback) => {
  111. // 上面有说,返回true表示校验通过,返回false表示不通过
  112. // this.$u.test.mobile()就是返回true或者false的
  113. if (this.$u.test.chinese(value)) {
  114. return callback(new Error('请输入数字类型'));
  115. } else if (!this.$u.test.amount(value)) {
  116. return callback(new Error('最多两位小数'));
  117. }
  118. callback()
  119. },
  120. // message: '最多两位小数',
  121. // 触发器可以同时用blur和change
  122. trigger: ['change', 'blur'],
  123. }],
  124. original_price: [{
  125. required: true,
  126. message: '原价不能为空',
  127. trigger: ['change', 'blur'],
  128. }, {
  129. // 自定义验证函数,见上说明
  130. validator: (rule, value, callback) => {
  131. // 上面有说,返回true表示校验通过,返回false表示不通过
  132. // this.$u.test.mobile()就是返回true或者false的
  133. if (this.$u.test.chinese(value)) {
  134. return callback(new Error('请输入数字类型'));
  135. } else if (!this.$u.test.amount(value)) {
  136. return callback(new Error('最多两位小数'));
  137. }
  138. callback()
  139. },
  140. // message: '最多两位小数',
  141. // 触发器可以同时用blur和change
  142. trigger: ['change', 'blur'],
  143. }],
  144. img: [{
  145. required: true,
  146. message: '图片不能为空',
  147. trigger: ['change', 'blur'],
  148. }],
  149. details: [{
  150. required: true,
  151. message: '详情不能为空',
  152. trigger: ['change', 'blur'],
  153. }],
  154. },
  155. }
  156. },
  157. onLoad(options) {
  158. if (options.goodsId) {
  159. this.goodsId = options.goodsId
  160. this.$nextTick(() => {
  161. this.getGoodsDetail(options.goodsId)
  162. })
  163. }
  164. this.getClassifylist()
  165. },
  166. onReady() {
  167. this.$refs.formRef.setRules(this.rules);
  168. },
  169. methods: {
  170. // 获取分类列表
  171. getClassifylist() {
  172. this.$http.get('/offlinetype/goods/my_list', {
  173. isGoods: 1,
  174. }).then(res => {
  175. if (res.code == 200) {
  176. if (res.list.length > 0) {
  177. this.classifyList = res.list
  178. }
  179. }
  180. })
  181. },
  182. getGoodsDetail(id) {
  183. this.$http.get(`/offline/goods/info/${id}`, {
  184. id: id
  185. }).then(res => {
  186. if (res.code == 200) {
  187. this.form = res.data
  188. this.form.price = res.data.price.toString()
  189. this.form.original_price = res.data.original_price.toString()
  190. this.img = res.data.img.split()
  191. this.detailsImages = res.data.details_images
  192. this.enterNum = res.data.details.length
  193. this.getType(res.data.type_id, 'type_id')
  194. this.getType(res.data.type, 'type')
  195. }
  196. })
  197. },
  198. getType(id, str) {
  199. let list = str == 'type' ? this.typeList : this.classifyList
  200. for (let item of list) {
  201. if (item.id == id) {
  202. if (str == 'type') {
  203. return this.form.typeLabel = item.name
  204. } else {
  205. return this.form.classifyLabel = item.name
  206. }
  207. }
  208. }
  209. },
  210. classifyConfirm(e) {
  211. if (e.length > 0) {
  212. this.form.type_id = e[0].value
  213. this.form.classifyLabel = e[0].label
  214. for (let i in this.classifyList) {
  215. if (this.classifyList[i].id == e[0].value) {
  216. this.classifyIndex = Number(i)
  217. return false
  218. }
  219. }
  220. }
  221. },
  222. typeConfirm(e) {
  223. if (e.length > 0) {
  224. this.form.type = e[0].value
  225. this.form.typeLabel = e[0].label
  226. for (let i in this.typeList) {
  227. if (this.typeList[i].id == e[0].value) {
  228. this.typeIndex = Number(i)
  229. return false
  230. }
  231. }
  232. }
  233. },
  234. detailsChange(e) {
  235. if (e) {
  236. this.enterNum = e.length
  237. }
  238. },
  239. resultImg(e) {
  240. this.imgs = e
  241. this.form.img = e[0]
  242. },
  243. resultImgs(e) {
  244. this.detailsImages = e
  245. this.form.details_images = e
  246. },
  247. submit(type) {
  248. this.$refs.formRef.validate(valid => {
  249. if (valid) {
  250. let url = '/offline/goods/save'
  251. let method = 'post'
  252. if (this.goodsId) {
  253. url = '/offline/goods/update'
  254. method = 'put'
  255. }
  256. this.$http[method](url, {
  257. ...this.form,
  258. is_release: type
  259. }).then(res => {
  260. if (res.code == 200) {
  261. this.$mUtil.toast(type == 0 ? '保存成功' : '发布成功')
  262. setTimeout(() => {
  263. uni.navigateBack()
  264. }, 1000)
  265. }
  266. })
  267. } else {
  268. console.log('验证失败');
  269. }
  270. });
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. .container-release {
  277. .main {
  278. padding: 20rpx 30rpx 200rpx;
  279. /deep/ .u-form {
  280. .u-input__right-icon__item {
  281. display: flex;
  282. align-items: center;
  283. }
  284. .uicon-arrow-down-fill::before {
  285. width: 32rpx;
  286. height: 32rpx;
  287. content: '';
  288. background: url('@/static/personal/select-icon.png') no-repeat;
  289. background-size: 100% 100%;
  290. }
  291. .content-box {
  292. .u-form-item--right__content__slot {
  293. flex-direction: column;
  294. .u-input {
  295. width: 100%;
  296. }
  297. .content {
  298. width: 100%;
  299. text-align: right;
  300. }
  301. }
  302. }
  303. .content {
  304. font-size: 24rpx;
  305. font-family: PingFang SC, PingFang SC-Regular;
  306. font-weight: 400;
  307. color: #808080;
  308. text {
  309. color: #EF3124;
  310. }
  311. }
  312. }
  313. }
  314. .footer {
  315. width: 100%;
  316. padding: 30rpx 60rpx;
  317. position: fixed;
  318. bottom: 0;
  319. display: flex;
  320. align-items: center;
  321. justify-content: space-between;
  322. background-color: #fff;
  323. z-index: 99;
  324. .btn {
  325. width: 298rpx;
  326. color: #fff;
  327. text-align: center;
  328. line-height: 85rpx;
  329. border: 1rpx solid #3775F6;
  330. border-radius: 44rpx;
  331. background-color: #FA6138;
  332. font-size: 28rpx;
  333. font-family: PingFang SC, PingFang SC-Regular;
  334. font-weight: 400;
  335. text-align: center;
  336. }
  337. .online-btn {
  338. color: #FA6138;
  339. border: 1rpx solid #3775F6;
  340. background-color: #e7eefc;
  341. }
  342. }
  343. }
  344. </style>