123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- <template>
- <view class="container main">
- <view class="one">
- <uni-forms ref="baseForm" :rules="rules" :modelValue="form" label-width="80px">
- <uni-forms-item label="流程" required name="matchPath">
- <uni-data-select v-model="form.matchPath" :localdata="matchPathList"
- @change="matchPathChange"></uni-data-select>
- </uni-forms-item>
- <uni-forms-item label="选手" required name="sign">
- <uni-data-select v-model="form.sign" :localdata="signList" @change="signChange"></uni-data-select>
- </uni-forms-item>
- <uni-forms-item label="分数" required name="score">
- <uni-easyinput v-model="form.score" placeholder="请输入分数" />
- </uni-forms-item>
- </uni-forms>
- <view class="button">
- <button type="primary" @click="submit('baseForm')">保存</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import moment from 'moment';
- export default {
- data() {
- return {
- id: "",
- match: "",
- user: {},
- form: {
- sign: "",
- score: "",
- },
- matchPath: '',
- matchPathList: [],
- signList: [],
- // 校验规则
- rules: {
- sign: {
- rules: [{
- required: true,
- errorMessage: '选手不能为空'
- }]
- },
- score: {
- rules: [{
- required: true,
- errorMessage: '分数不能为空'
- }]
- },
- },
- }
- },
- onLoad: async function(e) {
- const that = this;
- that.$set(that, `id`, e && e.id || '');
- that.$set(that, `match`, e && e.match || '');
- that.$set(that.form, `matchPath`, e && e.matchPath || '');
- that.$set(that, `matchPath`, e && e.matchPath || '');
- await that.searchToken();
- await that.searchOther();
- await that.search();
- },
- methods: {
- // 用户信息
- searchToken() {
- const that = this;
- try {
- const res = uni.getStorageSync('token');
- if (res) {
- const user = that.$jwt(res);
- that.$set(that, `user`, user);
- }
- } catch (e) {}
- },
- async searchOther() {
- const that = this;
- let res;
- // 查询流程
- res = await that.$api(`/matchPath`, 'GET', {
- match: that.match,
- is_use: '0',
- })
- if (res.errcode == '0') {
- for (let val of res.data) {
- val.text = val.name
- val.value = val.id
- }
- that.$set(that, `matchPathList`, res.data)
- }
- // 查询选手
- res = await that.$api(`/sign`, 'GET', {
- match: that.match,
- status: '1',
- })
- if (res.errcode == '0') {
- for (let val of res.data) {
- val.text = val.name
- val.value = val.id
- }
- that.$set(that, `signList`, res.data)
- }
- },
- // 查询
- async search() {
- const that = this;
- if (that.id) {
- let res;
- res = await that.$api(`/score/${that.id}`, 'GET', {})
- if (res.errcode == '0') {
- that.$set(that, `form`, res.data)
- } else {
- uni.showToast({
- title: res.errmsg,
- });
- }
- } else {
- that.$set(that, `form`, {
- matchPath: that.matchPath
- })
- }
- },
- // 选择流程
- matchPathChange(e) {
- const that = this;
- let data = that.matchPathList.find(i => i.id == e);;
- if (data) {
- that.$set(that.form, `matchPath`, data.id)
- }
- },
- // 选择选手
- signChange(e) {
- const that = this;
- let data = that.signList.find(i => i.id == e);;
- if (data) {
- that.$set(that.form, `sign`, data.id)
- }
- },
- // 保存
- submit(ref) {
- const that = this;
- that.$refs[ref].validate().then(async res => {
- let arr;
- const data = {
- match: that.match,
- time: moment().format('YYYY-MM-DD'),
- }
- if (that.id) {
- arr = await that.$api(`/score/${that.id}`, 'POST', {
- ...res,
- ...data
- })
- } else {
- arr = await that.$api(`/score`, 'POST', {
- ...res,
- ...data
- })
- }
- if (arr.errcode == '0') {
- uni.showModal({
- content: "维护成功!",
- showCancel: false
- });
- uni.navigateBack({
- delta: 1
- })
- } else {
- uni.showToast({
- title: arr.errmsg,
- });
- }
- }).catch(err => {
- console.log('err', err);
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .main {
- padding: 0 3vw;
- .one {
- .button_remark {
- margin: 2vw 0;
- text-indent: 10px;
- color: var(--fF0Color);
- font-size: var(--font12Size);
- }
- .button {
- margin: 2vw 0 0 0;
- button {
- background-color: var(--f3CColor);
- font-size: var(--font14Size);
- border-radius: 2vw;
- }
- }
- }
- }
- </style>
|