123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <template>
- <view class="content">
- <view class="box-pack-between item border-b">
- <text>名称</text>
- <input @input="bindName" maxlength="8" type="text" :value="name" placeholder="请输入名称" />
- </view>
- <view class="">
- <view class="box-pack-between ft32 item">
- <text>{{$test.$test}}场景 </text>
- <view class="add-home flex-center ft24">
- <picker @change="bindPickerChange" :range-key="'name'" :range="allwayList">
- 添加
- </picker>
- </view>
- </view>
- <view class="item-bg" v-if="arr.length>0">
- <view class="box-pack-between mar64 flex-y-center" v-for="(item,index) of arr" :key='item.id'>
- <view class="flex-y-center flex-grow-1 pdr-20">
- <text style="margin-right: 10rpx;">{{item.name}}</text>
- <input class="flex-grow-1" type="text" @input="getScene" :data-index="index"
- placeholder="请填写链接或内容" :value="item.way_power" />
- </view>
- <image class="item-del" @click="delScene" :data-index='index' src="../../static/images/del.png"
- mode=""></image>
- </view>
- </view>
- </view>
- <view class="bottom-bars flex-center">
- <button @click="save" class="flex-center ft28">{{id?'编辑':'添加'}}{{$test.$test}}池</button>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- $test: this.$test.$test,
- allwayList: [],
- arr: [],
- name: "",
- id: ''
- }
- },
- onLoad(e) {
- uni.setNavigationBarTitle({
- title: `添加${this.$test.$test}池`
- })
- this.allways();
- if (e.id) {
- this.id = e.id;
- this.poolDetail(e.id);
- }
- },
- methods: {
- poolDetail(id) {
- this.request({
- url: "powerpool/pool_detail",
- data: {
- id: id,
- token: uni.getStorageSync("token"),
- },
- }).then(res => {
- console.log(res, "res")
- if (res.code === '200') {
- this.name = res.data.name;
- this.arr = res.data.funeng;
- }
- }).catch((res) => {});
- },
- bindName(e) {
- this.name = e.detail.value;
- },
- getScene(e) {
- var index = e.currentTarget.dataset.index;
- this.arr[index].way_power = e.detail.value;
- },
- delScene(e) {
- var index = Number(e.currentTarget.dataset.index);
- this.arr.splice(index, 1);
- },
- bindPickerChange: function(e) {
- console.log(e, this.allwayList, "bindPickerChange", )
- if (this.arr.length > 0) {
- for (let i of this.arr) {
- if (i.id == this.allwayList[e.target.value].id) {
- uni.showToast({
- title: "场景重复",
- icon: 'none'
- })
- return
- }
- }
- }
- this.arr.push({
- id: this.allwayList[e.target.value].id,
- name: this.allwayList[e.target.value].name,
- super_id: this.allwayList[e.target.value].super_id,
- });
- },
- allways() {
- this.request({
- url: "funeng/allways",
- data: {},
- }).then(res => {
- console.log(res, "res")
- if (res.code === '200') {
- this.allwayList = res.data;
- this.arr.push({
- id: res.data[0].id,
- name: res.data[0].name,
- super_id: res.data[0].super_id,
- });
- }
- }).catch((res) => {});
- },
- save(e) {
- let arr = this.arr,
- way_id = [],
- way_power = [];
- for (let i of arr) {
- way_id.push(i.id);
- way_power.push(i.way_power)
- }
- if (way_power.length <= 0) {
- uni.showToast({
- title: "场景为空",
- icon: 'none'
- })
- return
- }
- if (!this.name) {
- uni.showToast({
- title: "名称不能为空",
- icon: 'none'
- })
- return
- }
- let data = {
- way_id: way_id.join(","),
- way_power: way_power.join(","),
- token: uni.getStorageSync("token"),
- name: this.name,
- }
- if (this.id) {
- data.id = this.id;
- }
- this.request({
- url: "powerpool/savepool",
- data,
- }).then(res => {
- console.log(res, "res")
- if (res.code === '200') {
- uni.showToast({
- title: this.id?"编辑成功":"添加成功",
- icon: 'none'
- }),
- setTimeout(() => {
- uni.navigateBack({
- delta: 1
- })
- }, 2e3)
- }
- }).catch((res) => {});
- },
- },
- }
- </script>
- <style>
- .item {
- padding: 32rpx 40rpx;
- }
- .item input {
- text-align: right;
- }
- .upimg {
- width: 126rpx;
- height: 126rpx;
- }
- .add-home {
- color: #FFFFFF;
- width: 126rpx;
- height: 54rpx;
- background: linear-gradient(315deg, #3387ff 2%, #569bff 99%);
- border-radius: 8rpx;
- box-shadow: 0px 0px 8rpx 0px rgba(51, 135, 255, 0.2);
- }
- .item-bg {
- width: 670rpx;
- /* height: 298rpx; */
- background: #f6f8fe;
- border-radius: 12rpx;
- margin: 0 auto;
- font-size: 28rpx;
- font-family: PingFang SC, PingFang SC-Regular;
- font-weight: 400;
- color: #333333;
- padding: 36rpx 32rpx;
- }
- .item-del {
- width: 40rpx;
- height: 40rpx;
- }
- .mar64 {
- margin-bottom: 64rpx;
- }
- .item-bg .mar64:last-child {
- margin-bottom: 0rpx;
- }
- .hg200rpx {
- height: 100rpx;
- }
- .mgr57 {
- margin-bottom: 57rpx;
- }
- .item-bg-32 {
- margin-right: 32rpx;
- }
- </style>
|