create.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <div class="create-skill-wrapper">
  3. <div class="create-skill-title">新建技能服务</div>
  4. <div class="progress-wrapper">
  5. <div class="progress-title">完成度: {{ percent }}%</div>
  6. <el-progress
  7. class="progress-bar"
  8. :show-text="false"
  9. color="#308eff"
  10. :percentage="percent"></el-progress>
  11. </div>
  12. <div class="form-wrapper">
  13. <!-- 第一步 -->
  14. <div v-show="currentStep === 1">
  15. <div class="skill-field">
  16. <div class="field-name"><span class="required">*</span> 技能标题</div>
  17. <el-input
  18. class="skill-title-input"
  19. :class="{ 'is-error': titleError }"
  20. v-model="title"
  21. maxlength="50"
  22. show-word-limit
  23. placeholder="请输入"></el-input>
  24. </div>
  25. </div>
  26. <!-- 第二步 -->
  27. <div v-show="currentStep === 2">
  28. <div class="price-field">
  29. <div class="price-wrapper">
  30. <div class="field-name"><span class="required">*</span> 技能价格</div>
  31. <el-input
  32. class="price-input"
  33. :class="{ 'is-error': priceError }"
  34. type="number"
  35. placeholder="请输入价格"
  36. v-model="price"></el-input>
  37. <span class="yuan">元</span>
  38. </div>
  39. <div class="cate-wrapper">
  40. <div class="field-name"><span class="required">*</span> 技能类别</div>
  41. <div class="cate-content">
  42. <el-cascader
  43. class="cate-cascader"
  44. :class="{ 'is-error': cateError }"
  45. v-model="selectedSkillCate"
  46. :options="skillCate"
  47. :props="{ expandTrigger: 'hover' }"
  48. placeholder="请选择类别"></el-cascader>
  49. </div>
  50. </div>
  51. </div>
  52. <div class="content-field">
  53. <div class="field-name"><span class="required">*</span> 技能描述</div>
  54. <div class="content-editor">
  55. <el-input
  56. class="content-input"
  57. type="textarea"
  58. :rows="8"
  59. :autosize="{ minRows: 8 }"
  60. placeholder="请输入技能描述"
  61. v-model="content"></el-input>
  62. </div>
  63. </div>
  64. </div>
  65. <!-- 第三步 -->
  66. <div v-show="currentStep === 3">
  67. <div class="image-field">
  68. <div class="field-name"><span class="required">*</span> 技能介绍图</div>
  69. <multi-uploader
  70. class="skill-image-uploader"
  71. :showTips="false"
  72. v-model="imageList"></multi-uploader>
  73. <div class="upload-tips">建议上传多张能证明技能价值的图片
  74. 第一张默认为封面
  75. 建议比例16:9(如:1920*1080、800*450)支持J(E)PG、PNG格式,小于5MB
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80. <div class="example-wrapper">
  81. <div class="example-content">
  82. <div class="example-title">
  83. <img class="example-icon" src="@/assets/img/skill/example-icon@2x.png" alt="example-icon">
  84. <span>示例</span>
  85. </div>
  86. <div class="example-text">{{ exampleText }}</div>
  87. </div>
  88. <img class="example-img" :src="exampleImage" alt="example-img">
  89. </div>
  90. <div class="actions-wrapper">
  91. <div class="actions-left">
  92. <el-button
  93. class="prev-btn"
  94. v-show="currentStep > 1"
  95. :disabled="currentStep === 1"
  96. @click="handlePrev">← 上一步</el-button>
  97. </div>
  98. <div class="actions-right">
  99. <el-button
  100. class="next-btn"
  101. :loading="publishIsLoading"
  102. :disabled="pcreateIsLoading"
  103. @click="handleNext">{{ currentStep === 3 ? '提交审核' : '下一步' }}</el-button>
  104. <el-button
  105. class="pcreate-btn"
  106. :loading="pcreateIsLoading"
  107. :disabled="publishIsLoading"
  108. v-show="currentStep === 3"
  109. @click="handlePcreate">存草稿</el-button>
  110. </div>
  111. </div>
  112. </div>
  113. </template>
  114. <script>
  115. import { mapState } from "vuex";
  116. import editor from "@/components/editor";
  117. import multiUploader from '@/components/multi-uploader';
  118. import ExampleImage1 from '@/assets/img/skill/example-img1@2x.png'
  119. import ExampleImage2 from '@/assets/img/skill/example-img2@2x.png'
  120. import ExampleImage3 from '@/assets/img/skill/example-img3@2x.png'
  121. export default {
  122. // async asyncData({ $axios, params }) {
  123. // let res = await $axios.$get(`/api/vip/getList`)
  124. // console.log('init', res)
  125. // },
  126. head: {
  127. title: "新建技能服务"
  128. },
  129. components: {
  130. editor,
  131. multiUploader
  132. },
  133. data() {
  134. return {
  135. ExampleImage1,
  136. ExampleImage2,
  137. ExampleImage3,
  138. currentStep: 1, // 当前的步骤:1、2、3
  139. sale_id: '', // 编辑时的 id
  140. title: '', // 技能标题
  141. price: '', // 技能价格
  142. selectedSkillCate: [], // 选中的技能分类
  143. skillCate: [], // 技能分类数据源
  144. content: '', // 技能描述
  145. defaultContent: '', // 默认的技能描述
  146. imageList: [], // 图片列表
  147. publishIsLoading: false, // 是否在提交审核
  148. pcreateIsLoading: false, // 是否在存草稿中
  149. priceError: false,
  150. titleError: false,
  151. cateError: false,
  152. contentError: false
  153. }
  154. },
  155. computed: {
  156. // 在示例中展示的文字
  157. exampleText () {
  158. let text = ''
  159. if (this.currentStep === 1) {
  160. text = `最好是一个细分类目下具体有场景的服务内容!
  161. 如:
  162. 1、我可以2小时内完成一个VUE公共组件编写
  163. 2、我可以完成小程序、公众号页面(100%)还原
  164. 3、我可以完成网站https证书安装部署,提高网站安全性和用户信任`
  165. } else if (this.currentStep === 2) {
  166. text = `服务内容需要把边界和风险描述清楚!
  167. 如:
  168. 服务包含的内容:
  169. 1、介绍你的服务包含哪些内容
  170. 2、明确好服务边界,需要由具体的量词描述
  171. 服务优势:
  172. 1、你有过哪些相关经验
  173. 2、你比其他人在哪些方面有优势
  174. 需客户提供的信息:
  175. 1、你的工作开展前需要客户提供哪些资料
  176. 其他:
  177. 1、将服务风险前置,如修改次数以及超出服务部分如何收费的规则等`
  178. } else if (this.currentStep === 3) {
  179. text = `您可以上传工作的最终交付物截图,增加技能的吸引力,让您的技能区别于其他人才,提高曝光率和成单率`
  180. }
  181. return text
  182. },
  183. // 在示例中展示的图片
  184. exampleImage () {
  185. let image = null
  186. if (this.currentStep === 1) {
  187. image = this.ExampleImage1
  188. } else if (this.currentStep === 2) {
  189. image = this.ExampleImage2
  190. } else if (this.currentStep === 3) {
  191. image = this.ExampleImage3
  192. }
  193. return image
  194. },
  195. // 新建/编辑技能的进度:0-100
  196. percent () {
  197. let val = 0
  198. if (this.currentStep === 2) {
  199. val = 33.3
  200. } else if (this.currentStep === 3) {
  201. val = 66.7
  202. }
  203. return val
  204. }
  205. },
  206. mounted () {
  207. this.needLogin()
  208. this._getSkillCate()
  209. this.sale_id = this.$route.query.sale_id || ''
  210. if (this.sale_id) {
  211. this._getSkillDetail()
  212. }
  213. },
  214. methods: {
  215. /** 获取技能分类 */
  216. _getSkillCate () {
  217. this.$axios.$post('/api/sale/cateListYes', { type: 2, point: 1 }).then(res => {
  218. if (res.status === 1) {
  219. let skillCate = res.data || []
  220. this.skillCate = skillCate.map(item => {
  221. let children = item.child_list.map(child => {
  222. return {
  223. value: child.category_id,
  224. label: child.name
  225. }
  226. })
  227. return {
  228. value: item.category_id,
  229. label: item.name,
  230. children: children
  231. }
  232. })
  233. }
  234. }).catch(err => {
  235. console.log('get skill cate error: ', err)
  236. })
  237. },
  238. /** 获取技能服务详情 */
  239. _getSkillDetail () {
  240. const self = this
  241. this.$axios.$post('/api/sale/saleInfo', { sale_id: this.sale_id }).then(res => {
  242. if (res.status === 1) {
  243. console.log('获取技能详情成功', res.data)
  244. self.title = res.data.title || ""
  245. self.price = res.data.price || ""
  246. self.content = res.data.content || self.defaultContent
  247. if (res.data.cate_id_one && res.data.cate_id_two) {
  248. self.selectedSkillCate = [res.data.cate_id_one, res.data.cate_id_two]
  249. }
  250. self._setSkillImages(res.data)
  251. }
  252. })
  253. },
  254. /** 创建、编辑技能 */
  255. _publishSkillData (actType) {
  256. const self = this
  257. const data = {
  258. title: this.title,
  259. price: this.price,
  260. content: this.content,
  261. img: this.imageList.map((it) => it.url).join(","),
  262. type: 1,
  263. cate_id_one: this.selectedSkillCate[0],
  264. cate_id_two: this.selectedSkillCate[1],
  265. act: actType,
  266. sale_id: this.sale_id || ''
  267. }
  268. if (actType === 'pcreate') {
  269. this.pcreateIsLoading = true
  270. } else {
  271. this.publishIsLoading = true
  272. }
  273. this.$axios.$post('/api/sale/create', data).then(res => {
  274. if (res.status === 1) {
  275. // self.$message.success(`${self.sale_id ? '编辑' : '创建'}技能成功!`)
  276. if (actType === 'pcreate') {
  277. self.$message.success('保存草稿成功')
  278. } else {
  279. self.$message.success('保存成功,平台将在1-3个工作日内完成审核')
  280. }
  281. setTimeout(() => {
  282. window.location.href = '/workbench/skill/index'
  283. }, 1200)
  284. } else {
  285. self.$message.error('保存失败')
  286. }
  287. }).then(() => {
  288. setTimeout(() => {
  289. self.pcreateIsLoading = false
  290. self.publishIsLoading = false
  291. }, 800)
  292. })
  293. },
  294. /** 编辑时初始化图片列表 */
  295. _setSkillImages (data) {
  296. let images = data.image.split(',')
  297. if (images && images.length > 0) {
  298. images.forEach((image, index) => {
  299. let imageName = this._getImageName(image);
  300. console.log("imageName", imageName);
  301. this.imageList.push({ name: imageName + index, url: image });
  302. })
  303. }
  304. },
  305. /** 通过 image url 获取名字 */
  306. _getImageName (url) {
  307. if (url) {
  308. try {
  309. const lastquotaIndex = url.lastIndexOf("/");
  310. const lastDotIndex = url.lastIndexOf('.');
  311. return url.substring(lastquotaIndex + 1, lastDotIndex);
  312. } catch (e) {
  313. console.log(e);
  314. }
  315. }
  316. return ""
  317. },
  318. /** 技能描述内容改变时 */
  319. handleChange (val) {
  320. this.content = val
  321. },
  322. /** 点击上一步 */
  323. handlePrev () {
  324. if (this.currentStep > 1) {
  325. this.currentStep--
  326. window.scroll(0, 103)
  327. }
  328. },
  329. /** 点击下一步 */
  330. handleNext () {
  331. this.titleError = false
  332. this.priceError = false
  333. this.cateError = false
  334. this.contentError = false
  335. // 在每一步做数据校验
  336. if (this.currentStep === 1) {
  337. if (this.title === '') {
  338. this.$message.error('请输入技能服务名称')
  339. this.titleError = true
  340. return
  341. }
  342. if (this.title.length < 5) {
  343. this.$message.error('技能服务名称不可少于5字符')
  344. this.titleError = true
  345. return
  346. }
  347. if (this.title.length > 50) {
  348. this.$message.error('技能服务名称不可超过50字符,请删减')
  349. this.titleError = true
  350. return
  351. }
  352. this.currentStep++
  353. window.scroll(0, 103)
  354. } else if (this.currentStep === 2) {
  355. if (this.price <= 0) {
  356. this.$message.error('请输入大于0的技能价格')
  357. this.priceError = true
  358. return
  359. }
  360. if (String(this.price).indexOf('.') > -1 &&
  361. String(this.price).length - String(this.price).indexOf('.') - 1 > 2) {
  362. this.priceError = true
  363. this.$message.error('技能价格最多保留两位小数')
  364. return
  365. }
  366. if (this.selectedSkillCate.length !== 2 ||
  367. (!this.selectedSkillCate[0] || !this.selectedSkillCate[1])) {
  368. this.cateError = true
  369. this.$message.error('请选择技能类别')
  370. return
  371. }
  372. if (!this.content) {
  373. this.contentError = true
  374. this.$message.error('请输入技能描述')
  375. return
  376. }
  377. this.currentStep++
  378. window.scroll(0, 103)
  379. } else if (this.currentStep === 3) {
  380. if (this.imageList.length === 0) {
  381. this.$message.error('请上传技能介绍图')
  382. return
  383. }
  384. this._publishSkillData(this.sale_id ? 'update' : 'create')
  385. }
  386. },
  387. /** 点击存草稿 */
  388. handlePcreate () {
  389. if (this.imageList.length === 0) {
  390. this.$message.error('请上传技能介绍图')
  391. return
  392. }
  393. this._publishSkillData('pcreate')
  394. }
  395. }
  396. }
  397. </script>
  398. <style scope lang="scss">
  399. @import "@/assets/css/skill/create.scss";
  400. </style>
  401. <style>
  402. input::-webkit-outer-spin-button,
  403. input::-webkit-inner-spin-button {
  404. -webkit-appearance: none !important;
  405. }
  406. input[type="number"]{
  407. -moz-appearance: textfield !important;
  408. }
  409. </style>
  410. <style lang="scss">
  411. // 编辑器样式
  412. .content-editor {
  413. .my-editor {
  414. .ql-snow {
  415. border: 1px solid #d7dfe8 !important;
  416. border-radius: 3px 3px 0 0 !important;
  417. }
  418. .quill-editor {
  419. border-width: 1px !important;
  420. border-top: 0 !important;
  421. border-color: #d7dfe8 !important;
  422. border-radius: 0 0 3px 3px !important;
  423. }
  424. }
  425. }
  426. // 图片上传器样式
  427. .skill-image-uploader {
  428. .el-upload-list__item {
  429. width: 300px !important;
  430. height: 168.75px !important;
  431. line-height: 168.75px !important;
  432. }
  433. .el-upload--picture-card {
  434. width: 300px !important;
  435. height: 168.75px !important;
  436. line-height: 168.75px !important;
  437. .el-upload-list__item-thumbnail {
  438. object-fit: scale-down !important;
  439. }
  440. }
  441. .el-upload-list--picture-card {
  442. .el-upload-list__item-thumbnail {
  443. object-fit: scale-down !important;
  444. }
  445. }
  446. }
  447. </style>