index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="container">
  3. <navBar title="主角详情" :back="true" color="#333333" background="#FFFFFF" />
  4. <view class="parmasBox">
  5. <view class="titleBox">
  6. <image :src="picBase+'s_star.png'" mode="heightFix" class="starIcon" @click="upload"></image>
  7. 故事主角信息
  8. </view>
  9. <view class="inputBox">
  10. <view class="selAndTileBox">
  11. <view class="nickname">
  12. <input type="text" class="nackI" v-model="formData.nickName" placeholder="请输入昵称" />
  13. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  14. </image>
  15. </view>
  16. <!-- <view class="selBtn" @click="show5=true">
  17. 选择主角
  18. </view> -->
  19. </view>
  20. <view class="otherBox">
  21. <view class="item" @click="show=true">
  22. <input type="text" class="nackI" disabled v-model="formData.sex" placeholder="选择性别" />
  23. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  24. </image>
  25. </view>
  26. <view class="item" @click="show2=true">
  27. <input type="text" class="nackI" disabled v-model="formData.ageName" placeholder="选择年龄" />
  28. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  29. </image>
  30. </view>
  31. <view class="item" @click="show3=true">
  32. <input type="text" class="nackI" disabled v-model="formData.star" placeholder="选择星座" />
  33. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  34. </image>
  35. </view>
  36. <view class="item" @click="show4=true">
  37. <input type="text" class="nackI" disabled v-model="formData.className" placeholder="选择年级" />
  38. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  39. </image>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view class='btnBox' @click="save">
  45. <view class='btn'>
  46. {{type==0?'保存':'修改'}}
  47. </view>
  48. </view>
  49. <u-picker :show="show" :defaultIndex="defaultIndex1" class="my-picker" title="性别选择" aColor="#007AFF"
  50. :columns="columns" confirmColor="#007AFF" @confirm="confirm1" @cancel="show=false"></u-picker>
  51. <u-picker :show="show2" :defaultIndex="defaultIndex2" title="年龄选择" keyName="label" aColor="#007AFF"
  52. :columns="columns2" confirmColor="#007AFF" @confirm="confirm2" @cancel="show2=false"></u-picker>
  53. <u-picker :show="show3" :defaultIndex="defaultIndex3" title="星座选择" aColor="#007AFF" :columns="columns3"
  54. confirmColor="#007AFF" @confirm="confirm3" @cancel="show3=false"></u-picker>
  55. <u-picker :show="show4" :defaultIndex="defaultIndex4" title="班级选择" aColor="#007AFF" :columns="columns4"
  56. confirmColor="#007AFF" @confirm="confirm4" @cancel="show4=false"></u-picker>
  57. <!-- <u-picker keyName="name" :show="show5" title="选择主角" aColor="#007AFF" :columns="columns5" confirmColor="#007AFF"
  58. @confirm="confirm5" @cancel="show5=false"></u-picker> -->
  59. </view>
  60. </template>
  61. <script>
  62. // import navBar from '@/components/navBar/index.vue'
  63. import {
  64. getKefu,
  65. postAddRole,
  66. postUpRole
  67. } from '@/api/index/index.js'
  68. export default {
  69. // components: {
  70. // navBar
  71. // },
  72. data() {
  73. return {
  74. picBase: this.$picBase2,
  75. formData: {
  76. nickName: '',
  77. sex: '',
  78. ageName: '',
  79. age: -1,
  80. star: '',
  81. className: '',
  82. class: -1
  83. },
  84. show: false,
  85. columns: [
  86. ['男孩', '女孩']
  87. ],
  88. show2: false,
  89. columns2: [
  90. [
  91. '1岁',
  92. '2岁',
  93. '3岁',
  94. '4岁',
  95. '5岁',
  96. '6岁',
  97. '7岁',
  98. '8岁',
  99. '9岁',
  100. '10岁',
  101. '11岁',
  102. '12岁',
  103. '13岁',
  104. '14岁',
  105. '15岁',
  106. '16岁',
  107. ]
  108. ],
  109. show3: false,
  110. columns3: [
  111. ['白羊座', '金牛座', '双子座 ', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
  112. ],
  113. show4: false,
  114. columns4: [
  115. ['幼儿园', '一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
  116. ],
  117. roleInfo: null,
  118. type: 0,
  119. roleId: -1,
  120. defaultIndex1: [0],
  121. defaultIndex2: [0],
  122. defaultIndex3: [0],
  123. defaultIndex4: [0]
  124. }
  125. },
  126. onLoad() {
  127. // this.getabout()
  128. if (getApp().roleInfo) {
  129. this.type = 1
  130. this.roleInfo = getApp().roleInfo
  131. this.confirm5(getApp().roleInfo)
  132. console.log('传入的主角信息', this.roleInfo);
  133. getApp().roleInfo = null
  134. // 回显选择器对应默认索引
  135. this.reshowIndex()
  136. } else {
  137. this.reShow2()
  138. }
  139. },
  140. methods: {
  141. reshowIndex() {
  142. this.defaultIndex1[0] = this.roleInfo.sex == '男孩' ? 0 : 1
  143. this.defaultIndex2[0] = Number(this.roleInfo.age) - 1
  144. let xinzuoIndex = this.columns3[0].findIndex((item, index) => {
  145. return item == this.roleInfo.star
  146. })
  147. console.log('xinzuoIndex-----', xinzuoIndex);
  148. this.defaultIndex3[0] = xinzuoIndex
  149. this.defaultIndex4[0] = Number(this.roleInfo.level)
  150. },
  151. reShow2() {
  152. // 回显方式2
  153. // this.formData.nickName = res1.data.data[i].name
  154. this.formData.sex = this.columns[0][0]
  155. this.formData.age = 1
  156. this.formData.ageName = '1岁'
  157. this.formData.star = this.columns3[0][0]
  158. this.formData.className = this.columns4[0][0]
  159. this.formData.class = 0
  160. },
  161. async getabout() {
  162. let res1 = await getKefu()
  163. console.log('关于我们返回值--------2', res1);
  164. if (res1.code == 0) {
  165. this.content = res1.data.about.value
  166. } else {
  167. this.$toast(res1.message)
  168. }
  169. },
  170. confirm1(e) {
  171. console.log('e', e);
  172. this.formData.sex = e.value[0]
  173. this.show = false
  174. },
  175. confirm2(e) {
  176. console.log('e', e);
  177. this.formData.ageName = this.columns2[0][e.indexs[0]]
  178. this.formData.age = e.indexs[0] + 1
  179. this.show2 = false
  180. },
  181. confirm3(e) {
  182. console.log('e', e);
  183. this.formData.star = e.value[0]
  184. this.show3 = false
  185. },
  186. confirm4(e) {
  187. console.log('e', e);
  188. // this.formData.class = e.value[0]
  189. this.formData.class = e.indexs[0]
  190. this.formData.className = e.value[0]
  191. console.log('confirm4--level', this.formData.class);
  192. this.show4 = false
  193. },
  194. confirm5(e) {
  195. this.formData.class = e.level
  196. this.formData.className = this.columns4[0][Number(e.level)]
  197. this.formData.nickName = e.name
  198. this.formData.sex = e.sex
  199. this.formData.star = e.star
  200. this.formData.age = e.age
  201. this.formData.ageName = this.columns2[0][Number(e.age) - 1]
  202. },
  203. async save() {
  204. if (!this.formData.nickName) {
  205. return this.$toast('请输入昵称')
  206. }
  207. if (!this.formData.sex) {
  208. return this.$toast('请选择性别')
  209. }
  210. if (this.formData.age == -1) {
  211. return this.$toast('请选择年龄')
  212. }
  213. if (!this.formData.star) {
  214. return this.$toast('请选择星座')
  215. }
  216. if (this.formData.class == -1) {
  217. return this.$toast('请选择班级')
  218. }
  219. let p = {}
  220. if (this.type == 0) {
  221. p = {
  222. name: this.formData.nickName,
  223. sex: this.formData.sex,
  224. age: this.formData.age,
  225. star: this.formData.star,
  226. level: this.formData.class,
  227. }
  228. console.log('角色参数------------------', p);
  229. let res1 = await postAddRole(p)
  230. console.log('新增返回值--------2', res1);
  231. if (res1.code == 0) {
  232. this.$toast(this.type == 0 ? '保存成功' : '修改成功', 'success')
  233. setTimeout(() => {
  234. uni.navigateBack()
  235. }, 1500)
  236. } else {
  237. this.$toast(res1.message)
  238. }
  239. } else {
  240. p = {
  241. id: this.roleInfo.id,
  242. name: this.formData.nickName,
  243. sex: this.formData.sex,
  244. age: this.formData.age,
  245. star: this.formData.star,
  246. level: this.formData.class,
  247. }
  248. console.log('角色参数------------------', p);
  249. let res1 = await postUpRole(p)
  250. console.log('修改返回值--------2', res1);
  251. if (res1.code == 0) {
  252. this.$toast(this.type == 0 ? '保存成功' : '修改成功', 'success')
  253. setTimeout(() => {
  254. uni.navigateBack()
  255. }, 1500)
  256. } else {
  257. this.$toast(res1.message)
  258. }
  259. }
  260. },
  261. }
  262. }
  263. </script>
  264. <style lang="scss" scoped>
  265. @import "./index.scss";
  266. </style>