| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <div class="app-content">
- <!-- 门店信息 -->
- <form
- @submit="formSubmit"
- @reset="formReset"
- >
- <!-- 登录信息 -->
- <div class="module-com input-line-wrap">
- <tui-list-cell
- class="line-cell"
- :hover="false"
- >
- <div class="tui-title required">名称</div>
- <input
- v-model="form.name"
- placeholder-class="phcolor"
- class="tui-input"
- name="name"
- placeholder="请输入名称"
- maxlength="50"
- type="text"
- />
- </tui-list-cell>
- <tui-list-cell
- class="line-cell"
- :hover="false"
- >
- <div class="tui-title required">价格</div>
- <input
- v-model="form.tuition"
- placeholder-class="phcolor"
- class="tui-input"
- name="tuition"
- placeholder="请输入价格"
- maxlength="50"
- type="digit"
- />
- </tui-list-cell>
- <tui-list-cell
- class="line-cell"
- :hover="false"
- >
- <div class="tui-title required">招生对象</div>
- <input
- v-model="form.target"
- placeholder-class="phcolor"
- class="tui-input"
- name="target"
- placeholder="请输入招生对象"
- maxlength="50"
- type="text"
- />
- </tui-list-cell>
- <tui-list-cell
- class="line-cell"
- :hover="false"
- >
- <div class="tui-title">封面图</div>
- <app-uploader :remark="'建议上传比例800X500'"
- @resultData="_resultData"
- :num="1"
- :prefixShow="true"
- :imgList="imgList"
- />
- <!-- <image
- src="form.cover"
- class="_thmist"
- v-if="imgShow"
- ></image> -->
- </tui-list-cell>
- <tui-list-cell
- class="line-cell"
- :hover="false"
- >
- <div class="tui-title">简介</div>
- <textarea
- name="summary"
- id=""
- cols="30"
- rows="10"
- placeholder="简介 . . ."
- v-model="form.summary"
- ></textarea>
- </tui-list-cell>
- </div>
- <!-- 提交 -->
- <div class="confirm-btn">
- <button
- class="admin-button-com big blue"
- formType="submit"
- >确认</button>
- </div>
- </form>
- <!-- 选择地区 -->
- <app-area-sel
- :show.sync="showRegion"
- :city="form.receiveCity"
- @change="changeAreaFn"
- />
- </div>
- </template>
- <script>
- import TuiListCell from "@/components/plugin/list-cell";
- import AppUploader from "@/components/app-uploader";
- const form = require("@/utils/formValidation.js");
- // api
- import { pxClassDetail, pxClassUpdate, pxClassAdd } from "@/api/product";
- export default {
- name: "staff-add",
- components: {
- TuiListCell,
- AppUploader
- },
- data () {
- return {
- form: {
- name: "",
- tuition: "",
- introduction: "",
- target: "",
- status: "",
- cover: '',
- summary: ''
- },
- statusList: [
- {
- value: "01",
- name: "上架"
- },
- {
- value: "02",
- name: "下架"
- }
- ],
- imgShow: false,
- imgList: []
- };
- },
- onLoad () {
- // this.init()
- console.log(this.option.id)
- },
- onShow () {
- if (this.option.id) {
- uni.setNavigationBarTitle({
- title: `修改培训班`
- });
- this.imgShow = true
- } else {
- uni.setNavigationBarTitle({
- title: `添加培训班`
- });
- }
- },
- methods: {
- init () {
- if (this.option.id) {
- this._getDet();
- }
- },
- _resultData (val) {
- this.form.cover = val.shortUrl
- this.imgShow = false
- },
- // api
- _getDet () {
- pxClassDetail({ id: this.option.id }).then(res => {
- console.log(res)
- this.form = res.data
- this.imgList.push(res.data.cover )
- console.log(this.imgList)
- }).catch(err => { console.log(err) })
- },
- radioChange: function (evt) {
- for (let i = 0; i < this.statusList.length; i++) {
- if (this.statusList[i].value === evt.target.value) {
- this.form.status = evt.target.value;
- break;
- }
- }
- },
- confirmFn () {
- if (!this.form.cover) {
- this.$msg('请上传头像')
- return
- }
- let hostFn = this.option.id ? pxClassUpdate : pxClassAdd;
- if (this.option.id) {
- this.form.id = this.option.id;
- }
- hostFn(this.form).then(res => {
- uni.removeStorageSync('pxClassInfoList');
- let promptText = this.option.id ? "修改成功!" : "添加成功!";
- this.$msg(promptText);
- setTimeout(() => {
- this.pageTo(1);
- }, 1000);
- });
- },
- // 表单验证
- formSubmit (e) {
- // 表单规则
- let rules = [
- {
- name: "name",
- rule: ["required"],
- msg: ["请输入名称"]
- },
- {
- name: "tuition",
- rule: ["required"],
- msg: ["请输入价格"]
- },
- {
- name: "target",
- rule: ["required"],
- msg: ["请输入招生对象"]
- },
- {
- name: "summary",
- rule: ["required"],
- msg: ["请输入简介"]
- }
- ];
- // 进行表单检查
- let formData = e.detail.value;
- let checkRes = form.validation(formData, rules);
- // 验证通过!
- if (!checkRes) {
- this.confirmFn();
- } else {
- this.$msg(checkRes);
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .app-content {
- min-height: calc(100vh - 20upx);
- padding-top: 20upx;
- }
- .prompt-text {
- color: $fontColor3;
- padding-left: 30upx;
- margin-bottom: 30upx;
- }
- // ---
- .module-com {
- margin-bottom: 20upx;
- .member-wrap {
- .member-det {
- font-size: 24upx;
- margin-left: 20upx;
- }
- }
- .remark-wrap {
- align-items: flex-start;
- .remark {
- height: 240upx;
- }
- }
- }
- .radio-group {
- display: flex;
- label {
- margin-right: 80upx;
- }
- }
- // 按钮
- .confirm-btn {
- width: calc(100% - 60upx);
- margin: 60upx 30upx 20upx;
- .admin-button-com {
- width: 100%;
- }
- }
- textarea {
- border: 1px solid #eee;
- padding: 20upx;
- font-size: 28upx;
- }
- ._thmist {
- width: 200upx;
- height: 200upx;
- vertical-align: top;
- background-color: #eee;
- margin-top: -18upx;
- }
- </style>
|