trainingClassEdit.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="app-content">
  3. <!-- 门店信息 -->
  4. <form
  5. @submit="formSubmit"
  6. @reset="formReset"
  7. >
  8. <!-- 登录信息 -->
  9. <div class="module-com input-line-wrap">
  10. <tui-list-cell
  11. class="line-cell"
  12. :hover="false"
  13. >
  14. <div class="tui-title required">名称</div>
  15. <input
  16. v-model="form.name"
  17. placeholder-class="phcolor"
  18. class="tui-input"
  19. name="name"
  20. placeholder="请输入名称"
  21. maxlength="50"
  22. type="text"
  23. />
  24. </tui-list-cell>
  25. <tui-list-cell
  26. class="line-cell"
  27. :hover="false"
  28. >
  29. <div class="tui-title required">价格</div>
  30. <input
  31. v-model="form.tuition"
  32. placeholder-class="phcolor"
  33. class="tui-input"
  34. name="tuition"
  35. placeholder="请输入价格"
  36. maxlength="50"
  37. type="digit"
  38. />
  39. </tui-list-cell>
  40. <tui-list-cell
  41. class="line-cell"
  42. :hover="false"
  43. >
  44. <div class="tui-title required">招生对象</div>
  45. <input
  46. v-model="form.target"
  47. placeholder-class="phcolor"
  48. class="tui-input"
  49. name="target"
  50. placeholder="请输入招生对象"
  51. maxlength="50"
  52. type="text"
  53. />
  54. </tui-list-cell>
  55. <tui-list-cell
  56. class="line-cell"
  57. :hover="false"
  58. >
  59. <div class="tui-title">封面图</div>
  60. <app-uploader :remark="'建议上传比例800X500'"
  61. @resultData="_resultData"
  62. :num="1"
  63. :prefixShow="true"
  64. :imgList="imgList"
  65. />
  66. <!-- <image
  67. src="form.cover"
  68. class="_thmist"
  69. v-if="imgShow"
  70. ></image> -->
  71. </tui-list-cell>
  72. <tui-list-cell
  73. class="line-cell"
  74. :hover="false"
  75. >
  76. <div class="tui-title">简介</div>
  77. <textarea
  78. name="summary"
  79. id=""
  80. cols="30"
  81. rows="10"
  82. placeholder="简介 . . ."
  83. v-model="form.summary"
  84. ></textarea>
  85. </tui-list-cell>
  86. </div>
  87. <!-- 提交 -->
  88. <div class="confirm-btn">
  89. <button
  90. class="admin-button-com big blue"
  91. formType="submit"
  92. >确认</button>
  93. </div>
  94. </form>
  95. <!-- 选择地区 -->
  96. <app-area-sel
  97. :show.sync="showRegion"
  98. :city="form.receiveCity"
  99. @change="changeAreaFn"
  100. />
  101. </div>
  102. </template>
  103. <script>
  104. import TuiListCell from "@/components/plugin/list-cell";
  105. import AppUploader from "@/components/app-uploader";
  106. const form = require("@/utils/formValidation.js");
  107. // api
  108. import { pxClassDetail, pxClassUpdate, pxClassAdd } from "@/api/product";
  109. export default {
  110. name: "staff-add",
  111. components: {
  112. TuiListCell,
  113. AppUploader
  114. },
  115. data () {
  116. return {
  117. form: {
  118. name: "",
  119. tuition: "",
  120. introduction: "",
  121. target: "",
  122. status: "",
  123. cover: '',
  124. summary: ''
  125. },
  126. statusList: [
  127. {
  128. value: "01",
  129. name: "上架"
  130. },
  131. {
  132. value: "02",
  133. name: "下架"
  134. }
  135. ],
  136. imgShow: false,
  137. imgList: []
  138. };
  139. },
  140. onLoad () {
  141. // this.init()
  142. console.log(this.option.id)
  143. },
  144. onShow () {
  145. if (this.option.id) {
  146. uni.setNavigationBarTitle({
  147. title: `修改培训班`
  148. });
  149. this.imgShow = true
  150. } else {
  151. uni.setNavigationBarTitle({
  152. title: `添加培训班`
  153. });
  154. }
  155. },
  156. methods: {
  157. init () {
  158. if (this.option.id) {
  159. this._getDet();
  160. }
  161. },
  162. _resultData (val) {
  163. this.form.cover = val.shortUrl
  164. this.imgShow = false
  165. },
  166. // api
  167. _getDet () {
  168. pxClassDetail({ id: this.option.id }).then(res => {
  169. console.log(res)
  170. this.form = res.data
  171. this.imgList.push(res.data.cover )
  172. console.log(this.imgList)
  173. }).catch(err => { console.log(err) })
  174. },
  175. radioChange: function (evt) {
  176. for (let i = 0; i < this.statusList.length; i++) {
  177. if (this.statusList[i].value === evt.target.value) {
  178. this.form.status = evt.target.value;
  179. break;
  180. }
  181. }
  182. },
  183. confirmFn () {
  184. if (!this.form.cover) {
  185. this.$msg('请上传头像')
  186. return
  187. }
  188. let hostFn = this.option.id ? pxClassUpdate : pxClassAdd;
  189. if (this.option.id) {
  190. this.form.id = this.option.id;
  191. }
  192. hostFn(this.form).then(res => {
  193. uni.removeStorageSync('pxClassInfoList');
  194. let promptText = this.option.id ? "修改成功!" : "添加成功!";
  195. this.$msg(promptText);
  196. setTimeout(() => {
  197. this.pageTo(1);
  198. }, 1000);
  199. });
  200. },
  201. // 表单验证
  202. formSubmit (e) {
  203. // 表单规则
  204. let rules = [
  205. {
  206. name: "name",
  207. rule: ["required"],
  208. msg: ["请输入名称"]
  209. },
  210. {
  211. name: "tuition",
  212. rule: ["required"],
  213. msg: ["请输入价格"]
  214. },
  215. {
  216. name: "target",
  217. rule: ["required"],
  218. msg: ["请输入招生对象"]
  219. },
  220. {
  221. name: "summary",
  222. rule: ["required"],
  223. msg: ["请输入简介"]
  224. }
  225. ];
  226. // 进行表单检查
  227. let formData = e.detail.value;
  228. let checkRes = form.validation(formData, rules);
  229. // 验证通过!
  230. if (!checkRes) {
  231. this.confirmFn();
  232. } else {
  233. this.$msg(checkRes);
  234. }
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped>
  240. .app-content {
  241. min-height: calc(100vh - 20upx);
  242. padding-top: 20upx;
  243. }
  244. .prompt-text {
  245. color: $fontColor3;
  246. padding-left: 30upx;
  247. margin-bottom: 30upx;
  248. }
  249. // ---
  250. .module-com {
  251. margin-bottom: 20upx;
  252. .member-wrap {
  253. .member-det {
  254. font-size: 24upx;
  255. margin-left: 20upx;
  256. }
  257. }
  258. .remark-wrap {
  259. align-items: flex-start;
  260. .remark {
  261. height: 240upx;
  262. }
  263. }
  264. }
  265. .radio-group {
  266. display: flex;
  267. label {
  268. margin-right: 80upx;
  269. }
  270. }
  271. // 按钮
  272. .confirm-btn {
  273. width: calc(100% - 60upx);
  274. margin: 60upx 30upx 20upx;
  275. .admin-button-com {
  276. width: 100%;
  277. }
  278. }
  279. textarea {
  280. border: 1px solid #eee;
  281. padding: 20upx;
  282. font-size: 28upx;
  283. }
  284. ._thmist {
  285. width: 200upx;
  286. height: 200upx;
  287. vertical-align: top;
  288. background-color: #eee;
  289. margin-top: -18upx;
  290. }
  291. </style>