trainingClassEdit.vue 7.3 KB

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