add-way.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="content">
  3. <view class="box-pack-between item border-b">
  4. <text>名称</text>
  5. <input @input="bindName" maxlength="8" type="text" :value="name" placeholder="请输入名称" />
  6. </view>
  7. <view class="">
  8. <view class="box-pack-between ft32 item">
  9. <text>{{$test.$test}}场景 </text>
  10. <view class="add-home flex-center ft24">
  11. <picker @change="bindPickerChange" :range-key="'name'" :range="allwayList">
  12. 添加
  13. </picker>
  14. </view>
  15. </view>
  16. <view class="item-bg" v-if="arr.length>0">
  17. <view class="box-pack-between mar64 flex-y-center" v-for="(item,index) of arr" :key='item.id'>
  18. <view class="flex-y-center flex-grow-1 pdr-20">
  19. <text style="margin-right: 10rpx;">{{item.name}}</text>
  20. <input class="flex-grow-1" type="text" @input="getScene" :data-index="index"
  21. placeholder="请填写链接或内容" :value="item.way_power" />
  22. </view>
  23. <image class="item-del" @click="delScene" :data-index='index' src="../../static/images/del.png"
  24. mode=""></image>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="bottom-bars flex-center">
  29. <button @click="save" class="flex-center ft28">{{id?'编辑':'添加'}}{{$test.$test}}池</button>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. $test: this.$test.$test,
  38. allwayList: [],
  39. arr: [],
  40. name: "",
  41. id: ''
  42. }
  43. },
  44. onLoad(e) {
  45. uni.setNavigationBarTitle({
  46. title: `添加${this.$test.$test}池`
  47. })
  48. this.allways();
  49. if (e.id) {
  50. this.id = e.id;
  51. this.poolDetail(e.id);
  52. }
  53. },
  54. methods: {
  55. poolDetail(id) {
  56. this.request({
  57. url: "powerpool/pool_detail",
  58. data: {
  59. id: id,
  60. token: uni.getStorageSync("token"),
  61. },
  62. }).then(res => {
  63. console.log(res, "res")
  64. if (res.code === '200') {
  65. this.name = res.data.name;
  66. this.arr = res.data.funeng;
  67. }
  68. }).catch((res) => {});
  69. },
  70. bindName(e) {
  71. this.name = e.detail.value;
  72. },
  73. getScene(e) {
  74. var index = e.currentTarget.dataset.index;
  75. this.arr[index].way_power = e.detail.value;
  76. },
  77. delScene(e) {
  78. var index = Number(e.currentTarget.dataset.index);
  79. this.arr.splice(index, 1);
  80. },
  81. bindPickerChange: function(e) {
  82. console.log(e, this.allwayList, "bindPickerChange", )
  83. if (this.arr.length > 0) {
  84. for (let i of this.arr) {
  85. if (i.id == this.allwayList[e.target.value].id) {
  86. uni.showToast({
  87. title: "场景重复",
  88. icon: 'none'
  89. })
  90. return
  91. }
  92. }
  93. }
  94. this.arr.push({
  95. id: this.allwayList[e.target.value].id,
  96. name: this.allwayList[e.target.value].name,
  97. super_id: this.allwayList[e.target.value].super_id,
  98. });
  99. },
  100. allways() {
  101. this.request({
  102. url: "funeng/allways",
  103. data: {},
  104. }).then(res => {
  105. console.log(res, "res")
  106. if (res.code === '200') {
  107. this.allwayList = res.data;
  108. this.arr.push({
  109. id: res.data[0].id,
  110. name: res.data[0].name,
  111. super_id: res.data[0].super_id,
  112. });
  113. }
  114. }).catch((res) => {});
  115. },
  116. save(e) {
  117. let arr = this.arr,
  118. way_id = [],
  119. way_power = [];
  120. for (let i of arr) {
  121. way_id.push(i.id);
  122. way_power.push(i.way_power)
  123. }
  124. if (way_power.length <= 0) {
  125. uni.showToast({
  126. title: "场景为空",
  127. icon: 'none'
  128. })
  129. return
  130. }
  131. if (!this.name) {
  132. uni.showToast({
  133. title: "名称不能为空",
  134. icon: 'none'
  135. })
  136. return
  137. }
  138. let data = {
  139. way_id: way_id.join(","),
  140. way_power: way_power.join(","),
  141. token: uni.getStorageSync("token"),
  142. name: this.name,
  143. }
  144. if (this.id) {
  145. data.id = this.id;
  146. }
  147. this.request({
  148. url: "powerpool/savepool",
  149. data,
  150. }).then(res => {
  151. console.log(res, "res")
  152. if (res.code === '200') {
  153. uni.showToast({
  154. title: this.id?"编辑成功":"添加成功",
  155. icon: 'none'
  156. }),
  157. setTimeout(() => {
  158. uni.navigateBack({
  159. delta: 1
  160. })
  161. }, 2e3)
  162. }
  163. }).catch((res) => {});
  164. },
  165. },
  166. }
  167. </script>
  168. <style>
  169. .item {
  170. padding: 32rpx 40rpx;
  171. }
  172. .item input {
  173. text-align: right;
  174. }
  175. .upimg {
  176. width: 126rpx;
  177. height: 126rpx;
  178. }
  179. .add-home {
  180. color: #FFFFFF;
  181. width: 126rpx;
  182. height: 54rpx;
  183. background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
  184. border-radius: 8rpx;
  185. box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
  186. }
  187. .item-bg {
  188. width: 670rpx;
  189. /* height: 298rpx; */
  190. background: #f6f8fe;
  191. border-radius: 12rpx;
  192. margin: 0 auto;
  193. font-size: 28rpx;
  194. font-family: PingFang SC, PingFang SC-Regular;
  195. font-weight: 400;
  196. color: #333333;
  197. padding: 36rpx 32rpx;
  198. }
  199. .item-del {
  200. width: 40rpx;
  201. height: 40rpx;
  202. }
  203. .mar64 {
  204. margin-bottom: 64rpx;
  205. }
  206. .item-bg .mar64:last-child {
  207. margin-bottom: 0rpx;
  208. }
  209. .hg200rpx {
  210. height: 100rpx;
  211. }
  212. .mgr57 {
  213. margin-bottom: 57rpx;
  214. }
  215. .item-bg-32 {
  216. margin-right: 32rpx;
  217. }
  218. </style>