changeTitle.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <uni-nav-bar fixed :border="false" left-icon="left" :title="title" :statusBar="true" @clickLeft="back" @clickRight="handleDel">
  4. <!-- #ifndef MP-WEIXIN -->
  5. <template v-slot:right v-if="type == 'edit'">
  6. <view class="nav-bar-del">删除</view>
  7. </template>
  8. <!-- #endif -->
  9. </uni-nav-bar>
  10. <view class="container">
  11. <uni-forms ref="form" :rules="rules" :model="form" label-width="0" err-show-type="toast">
  12. <view class="card-list">
  13. <uni-forms-item name="name" class="card-list-item border-line nameinput">
  14. <uni-easyinput v-model="form.name" :trim="true" :inputBorder="false" :primaryColor="'#c0c4cc'"
  15. placeholder="请输入姓名" :placeholderStyle="placeholderStyle" :styles="inpuStyle" maxlength="10" />
  16. </uni-forms-item>
  17. <uni-forms-item name="relationship" class="card-list-item">
  18. <picker @change="bindPickerChange" :value="index" :range="array">
  19. <view class="pickerbox">
  20. <view class="pickerbox-left">关系</view>
  21. <view class="pickerbox-right">
  22. <text v-show="!array[index]">请选择关系</text>
  23. <text class="pickerbox-val" v-show="array[index]">{{array[index]}}</text>
  24. <image class="arrow_right_icon" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png"></image>
  25. </view>
  26. </view>
  27. </picker>
  28. </uni-forms-item>
  29. </view>
  30. </uni-forms>
  31. <button class="confirm-btn" :loading="btnLoading" :disabled="disabled" :style="{opacity: disabled ? 0.5 : 1}"
  32. @click="submit">确定</button>
  33. <!-- #ifndef APP-PLUS || H5 -->
  34. <view class="footer-del" v-if="type == 'edit'" @click="handleDel">删除</view>
  35. <!-- #endif -->
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import { editMyfamily } from "@/api/pages_watch/user.js"
  41. export default {
  42. data() {
  43. return {
  44. btnLoading: false,
  45. type: "add",
  46. userList: [],
  47. title: '',
  48. relation: {
  49. "baba": "爸爸",
  50. "mama": "妈妈",
  51. },
  52. // 关系
  53. array: ['父亲', '母亲', '配偶', '儿子', '女儿', '其他'],
  54. index: undefined,
  55. // 修改家人的index
  56. userIdx: 0,
  57. form: {
  58. name: "",
  59. relationship: ""
  60. },
  61. rules: {
  62. name: {
  63. rules: [{
  64. required: true,
  65. errorMessage: '姓名不能为空'
  66. }]
  67. },
  68. },
  69. placeholderStyle: "{font-family: PingFang SC, PingFang SC;font-weight: 500;font-size: 32rpx;color: #CCCCCC;}",
  70. inpuStyle: {
  71. fontFamily: "PingFang SC, PingFang SC",
  72. fontWeight: 500,
  73. fontSize: "32rpx",
  74. color: "#333"
  75. }
  76. }
  77. },
  78. computed: {
  79. disabled() {
  80. return !(this.form.name && this.array[this.index])
  81. }
  82. },
  83. onLoad(option) {
  84. this.title = option.type == "edit" ? "修改称呼" : "新增家人"
  85. if (this.$isLogin()) {
  86. let userInfo = JSON.parse(uni.getStorageSync('userWatchInfo'))
  87. this.userList = JSON.parse(userInfo.otherDevice) || []
  88. this.type = option.type || 'add'
  89. if(this.type == 'edit'&& option.index) {
  90. this.userIdx = option.index || 0
  91. this.form.name = this.userList[option.index].name
  92. this.form.relationship = this.userList[option.index].relationship
  93. this.index = this.array.indexOf(this.form.relationship) == -1 ? undefined : this.array.indexOf(this.form.relationship)
  94. }
  95. }
  96. },
  97. methods: {
  98. back() {
  99. uni.navigateBack({
  100. delta: 1
  101. })
  102. },
  103. // 删除
  104. handleDel() {
  105. if(this.type == 'edit' ) {
  106. this.userList.splice(this.userIdx,1)
  107. this.handleEdit(JSON.stringify(this.userList))
  108. }
  109. },
  110. bindPickerChange: function(e) {
  111. this.index = e.detail.value
  112. },
  113. submit() {
  114. this.form.relationship = this.array[this.index]
  115. this.$refs["form"].validate().then(res => {
  116. this.btnLoading = true
  117. if(this.type == "add") {
  118. this.userList.push({
  119. name: this.form.name,
  120. relationship: this.form.relationship,
  121. deviceId: ""
  122. })
  123. } else if(this.type == "edit"){
  124. this.userList[this.userIdx].name = this.form.name
  125. this.userList[this.userIdx].relationship = this.form.relationship
  126. }
  127. this.handleEdit(JSON.stringify(this.userList))
  128. }).catch(err => {
  129. console.log('err', err);
  130. })
  131. },
  132. handleEdit(otherDevice) {
  133. editMyfamily({otherDevice: otherDevice}).then(res=>{
  134. this.btnLoading = false
  135. if(res.code == 200) {
  136. uni.navigateBack()
  137. } else {
  138. uni.showToast({
  139. title: res.msg,
  140. icon: "none"
  141. })
  142. }
  143. }).catch(err => {
  144. this.btnLoading = false
  145. console.log('err', err);
  146. })
  147. }
  148. }
  149. }
  150. </script>
  151. <style lang="scss" scoped>
  152. @mixin u-flex($flexD, $alignI, $justifyC) {
  153. display: flex;
  154. flex-direction: $flexD;
  155. align-items: $alignI;
  156. justify-content: $justifyC;
  157. }
  158. ::v-deep .uni-easyinput__content-input {
  159. font-family: PingFang SC, PingFang SC;
  160. font-weight: 500;
  161. font-size: 32rpx;
  162. color: #333333;
  163. }
  164. .footer-del {
  165. width: 702rpx;
  166. height: 98rpx;
  167. margin-top: 40rpx;
  168. background: #fff;
  169. border-radius: 16rpx 16rpx 16rpx 16rpx;
  170. font-family: PingFang SC, PingFang SC;
  171. font-weight: 500;
  172. font-size: 32rpx;
  173. color: #333333;
  174. line-height: 98rpx;
  175. text-align: center;
  176. }
  177. .nav-bar-del {
  178. font-family: PingFang SC, PingFang SC;
  179. font-weight: 400;
  180. font-size: 32rpx;
  181. color: #222222;
  182. width: 68rpx;
  183. }
  184. .pickerbox {
  185. @include u-flex(row, center, space-between);
  186. font-family: PingFang SC, PingFang SC;
  187. font-weight: 500;
  188. font-size: 32rpx;
  189. color: #333333;
  190. &-left {
  191. flex: 1;
  192. }
  193. &-right {
  194. flex-shrink: 0;
  195. font-family: PingFang SC, PingFang SC;
  196. font-weight: 400;
  197. font-size: 28rpx;
  198. color: #999999;
  199. @include u-flex(row, center, flex-end);
  200. }
  201. &-val {
  202. color: #333333;
  203. }
  204. .arrow_right_icon {
  205. width: 48rpx;
  206. height: 48rpx;
  207. }
  208. }
  209. .container {
  210. padding: 24rpx;
  211. .card-list {
  212. padding: 0 24rpx;
  213. background: #FFFFFF;
  214. border-radius: 16rpx 16rpx 16rpx 16rpx;
  215. }
  216. .card-list-item {
  217. height: 120rpx;
  218. margin-bottom: 0;
  219. @include u-flex(row, center, flex-start);
  220. }
  221. .nameinput {}
  222. .confirm-btn {
  223. width: 702rpx;
  224. height: 98rpx;
  225. margin-top: 40rpx;
  226. background: #FF7700;
  227. border-radius: 16rpx 16rpx 16rpx 16rpx;
  228. font-family: PingFang SC, PingFang SC;
  229. font-weight: 500;
  230. font-size: 32rpx;
  231. color: #FFFFFF;
  232. line-height: 98rpx;
  233. &::after {
  234. border: none;
  235. }
  236. }
  237. }
  238. </style>