add.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <uni-forms ref="baseForm" :rules="rules" :modelValue="form" label-width="80px">
  5. <uni-forms-item label="流程" required name="matchPath">
  6. <uni-data-select v-model="form.matchPath" :localdata="matchPathList"
  7. @change="matchPathChange"></uni-data-select>
  8. </uni-forms-item>
  9. <uni-forms-item label="选手" required name="sign">
  10. <uni-data-select v-model="form.sign" :localdata="signList" @change="signChange"></uni-data-select>
  11. </uni-forms-item>
  12. <uni-forms-item label="分数" required name="score">
  13. <uni-easyinput v-model="form.score" placeholder="请输入分数" />
  14. </uni-forms-item>
  15. </uni-forms>
  16. <view class="button">
  17. <button type="primary" @click="submit('baseForm')">保存</button>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import moment from 'moment';
  24. export default {
  25. data() {
  26. return {
  27. id: "",
  28. match: "",
  29. user: {},
  30. form: {
  31. sign: "",
  32. score: "",
  33. },
  34. matchPathList: [],
  35. signList: [],
  36. // 校验规则
  37. rules: {
  38. sign: {
  39. rules: [{
  40. required: true,
  41. errorMessage: '选手不能为空'
  42. }]
  43. },
  44. score: {
  45. rules: [{
  46. required: true,
  47. errorMessage: '分数不能为空'
  48. }]
  49. },
  50. },
  51. }
  52. },
  53. onLoad: async function(e) {
  54. const that = this;
  55. that.$set(that, `id`, e && e.id || '');
  56. that.$set(that, `match`, e && e.match || '');
  57. await that.searchToken();
  58. await that.searchOther();
  59. await that.search();
  60. },
  61. methods: {
  62. // 用户信息
  63. searchToken() {
  64. const that = this;
  65. try {
  66. const res = uni.getStorageSync('token');
  67. if (res) {
  68. const user = that.$jwt(res);
  69. that.$set(that, `user`, user);
  70. }
  71. } catch (e) {}
  72. },
  73. async searchOther() {
  74. const that = this;
  75. let res;
  76. // 查询流程
  77. res = await that.$api(`/matchPath`, 'GET', {
  78. match: that.match,
  79. is_use: '0',
  80. })
  81. if (res.errcode == '0') {
  82. for (let val of res.data) {
  83. val.text = val.name
  84. val.value = val.id
  85. }
  86. that.$set(that, `matchPathList`, res.data)
  87. }
  88. // 查询选手
  89. res = await that.$api(`/sign`, 'GET', {
  90. match: that.match,
  91. status: '1',
  92. })
  93. if (res.errcode == '0') {
  94. for (let val of res.data) {
  95. val.text = val.name
  96. val.value = val.id
  97. }
  98. that.$set(that, `signList`, res.data)
  99. }
  100. },
  101. // 查询
  102. async search() {
  103. const that = this;
  104. if (that.id) {
  105. let res;
  106. res = await that.$api(`/score/${that.id}`, 'GET', {})
  107. if (res.errcode == '0') {
  108. that.$set(that, `form`, res.data)
  109. } else {
  110. uni.showToast({
  111. title: res.errmsg,
  112. });
  113. }
  114. }
  115. },
  116. // 选择流程
  117. matchPathChange(e) {
  118. const that = this;
  119. let data = that.matchPathList.find(i => i.id == e);;
  120. if (data) {
  121. that.$set(that.form, `matchPath`, data.id)
  122. }
  123. },
  124. // 选择选手
  125. signChange(e) {
  126. const that = this;
  127. let data = that.signList.find(i => i.id == e);;
  128. if (data) {
  129. that.$set(that.form, `sign`, data.id)
  130. }
  131. },
  132. // 保存
  133. submit(ref) {
  134. const that = this;
  135. that.$refs[ref].validate().then(async res => {
  136. let arr;
  137. const data = {
  138. match: that.match,
  139. time: moment().format('YYYY-MM-DD'),
  140. }
  141. if (that.id) {
  142. arr = await that.$api(`/score/${that.id}`, 'POST', {
  143. ...res,
  144. ...data
  145. })
  146. } else {
  147. arr = await that.$api(`/score`, 'POST', {
  148. ...res,
  149. ...data
  150. })
  151. }
  152. if (arr.errcode == '0') {
  153. uni.showModal({
  154. content: "维护成功!",
  155. showCancel: false
  156. });
  157. uni.navigateBack({
  158. delta: 1
  159. })
  160. } else {
  161. uni.showToast({
  162. title: arr.errmsg,
  163. });
  164. }
  165. }).catch(err => {
  166. console.log('err', err);
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. .main {
  174. padding: 0 3vw;
  175. .one {
  176. .button_remark {
  177. margin: 2vw 0;
  178. text-indent: 10px;
  179. color: var(--fF0Color);
  180. font-size: var(--font12Size);
  181. }
  182. .button {
  183. margin: 2vw 0 0 0;
  184. button {
  185. background-color: var(--f3CColor);
  186. font-size: var(--font14Size);
  187. border-radius: 2vw;
  188. }
  189. }
  190. }
  191. }
  192. </style>