create.vue 17 KB

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