<template>
  <view class="page">
    <u-navbar
      title="任务审核"
      back-icon-color="#FFFFFF"
      title-color="#FFFFFF"
      leftText="返回"
      :autoBack="true"
    />
    <view class="view-forms">
      <uni-forms
        ref="valiForm"
        :rules="rules"
        :modelValue="valiFormData"
        label-position="top"
      >
        <view>
          <view class="item-header">
            <view class="title">事件标题</view>
            <view class="icon">*</view>
          </view>
          <view class="checkbox-rudio">
            <uni-data-checkbox
              mode="button"
              v-model="valiFormData.sex"
              :localdata="sexs"
            />
          </view>
        </view>
        <view>
          <view class="item-header">
            <view class="title">处理前照片</view>
            <view class="icon">*</view>
          </view>
          <view>
            <view class="img-box">
              <img
                @click="previewImage(index)"
                v-for="(image, index) in imageList"
                :key="index"
                :src="image"
              />
            </view>
          </view>
        </view>
        <view>
          <view class="item-header">
            <view class="title">处理后照片</view>
            <view class="icon">*</view>
          </view>

          <view>
            <view class="img-boxs">
              <u-checkbox-group @change="checkboxGroupChange">
                <u-checkbox
                  @change="checkboxChange"
                  v-model="item.checked"
                  v-for="(item, index) in list"
                  :key="index"
                  :name="item.name"
                  >{{ item.name }}</u-checkbox
                >
              </u-checkbox-group>

              <!-- <checkbox-group @change="checkboxChange">
                <view
                  class="img-item"
                  v-for="(item, index) in hobby"
                  :key="index"
                >
                  <img :src="item.text" />
                  <checkbox :value="item.type" :checked="checked" />
                </view>
              </checkbox-group> -->
            </view>
          </view>
        </view>
        <view>
          <view class="item-header">
            <view class="title">标记后照片</view>
            <view class="icon">*</view>
          </view>
          <view>
            <view class="img-box">
              <img
                @click="previewImage(index)"
                v-for="(image, index) in imageList"
                :key="index"
                :src="image"
              />
            </view>
          </view>
        </view>
        <view>
          <view class="item-header">
            <view class="title">文字说明</view>
            <view class="icon">*</view>
          </view>
          <view>
            <uni-easyinput
              type="textarea"
              v-model="valiFormData.introduction"
              placeholder="请输入内容"
            />
          </view>
        </view>
      </uni-forms>
    </view>

    <view class="footer">
      <button class="btn-add" @click="submit('valiForm')">提交</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      checked: false,
      imageList: [
        "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
        "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
        "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
      ],
      hobby: [
        {
          text: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
          value: "0",
          type: "同类",
        },
        {
          text: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
          value: "1",
          type: "同类",
        },
        {
          text: "https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/shuijiao-small.jpg",
          value: "2",
          type: "同类",
        },
      ],
      // 单选数据源
      sexs: [
        {
          text: "通过",
          value: 0,
        },
        {
          text: "不通过",
          value: 1,
        },
      ],
      // 校验表单数据
      valiFormData: {
        name: "",
        age: "",
        sex: "",
        introduction: "",
        checkbox1: [],
      },
      // 校验规则
      rules: {
        introduction: {
          rules: [
            {
              required: true,
            },
          ],
        },
      },
    };
  },
  computed: {},
  onLoad() {},
  onReady() {},
  methods: {
    checkboxChange(event) {
      if (Array.isArray(event.detail.value) && event.detail.value.length) {
        // 选中的操作

        this.checked = false;
      } else {
        this.checked = false;
      }
    },
    previewImage(index) {
      uni.previewImage({
        urls: this.imageList,
        current: index,
        indicator: this.currentIndicator,
        loop: this.isLoop,
      });
    },
    changeSelect(e) {},
    submit(ref) {
      this.$refs[ref]
        .validate()
        .then((res) => {
          console.log("success", res);
          uni.showToast({
            title: `校验通过`,
          });
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  .u-nav-slot {
    text {
      font-size: 32rpx;
      font-family: PingFang SC;
      font-weight: bold;
      color: #367bef;
    }
  }

  .view-forms {
    margin-top: calc(var(--status-bar-height) + 44px);
    padding: 30rpx 20rpx 240rpx 20rpx;

    .img-box {
      width: 100%;
      height: auto;
      margin: 16rpx auto;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-between;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
      padding: 30rpx;
    }
    .img-box > img {
      width: 200rpx;
      height: 200rpx;
      object-fit: cover;
      margin: 16rpx 0;
    }

    .img-box:after {
      content: "";
      display: block;
      width: 200rpx;
    }
    .img-boxs {
      width: 100%;
      height: auto;
      margin: 16rpx auto;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      justify-content: space-between;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
      padding: 30rpx;
      .img-item {
        img {
          width: 200rpx;
          height: 200rpx;
          object-fit: cover;
          margin: 16rpx 0;
        }
      }
    }
    .item-header {
      display: flex;
      .title {
        font-size: 30rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        // font-weight: bold;
        color: #2e2f31;
        background-image: url("@/static/images/umale/icon_ind.png");
        background-size: 100% 50%;
        background-position: bottom;
        background-repeat: no-repeat;
      }

      .icon {
        font-size: 30rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        font-weight: bold;
        color: #fe3434;
      }
    }

    /deep/ .uni-forms-item {
      margin-bottom: 15rpx;
    }
    /deep/.uni-forms-item__label {
      background-image: url("@/static/images/umale/icon_ind.png");
      background-size: 100% 100%;
      background-position: bottom;
      background-repeat: no-repeat;
      height: auto;
      margin-top: 26rpx;
      & > text {
        line-height: 0;
      }
      & > text {
        font-size: 30rpx;
        font-family: PingFang SC-Bold, PingFang SC;
        // font-weight: bold;
        color: #2e2f31;
        white-space: nowrap;
      }

      & > .is-required {
        color: #dd524d;
        font-weight: bold;
      }
    }

    /deep/ .uni-easyinput {
      margin-top: 19rpx;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
      border-radius: 16rpx;
    }

    /deep/ .uni-stat-box {
      margin-top: 19rpx;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
      border-radius: 16rpx;
    }

    .uni-file-picker {
      margin-top: 16rpx;
      background-color: #ffffff;
      padding: 29rpx;
      box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
      border-radius: 16rpx;
    }

    .checkbox-rudio /deep/ .uni-data-checklist .checklist-group {
      display: flex;

      & :nth-child(odd) {
        margin-right: 15rpx;
      }

      & :nth-child(even) {
        margin-left: 15rpx;
        margin-right: 0;
      }

      .checklist-box {
        flex: 1;
        background: #ffffff;
        box-shadow: 0rpx 0rpx 20rpx 1rpx rgba(57, 118, 241, 0.06);
        border-radius: 16rpx;
        border: 2rpx solid #dce3ec;

        .checklist-content {
          padding: 32rpx;

          justify-content: center;
        }

        .radio__inner {
          position: absolute;
          top: 12rpx;
          left: 0;
        }
      }
    }

    // 选中
    .checkbox-rudio
      /deep/
      .uni-data-checklist
      .checklist-group
      .checklist-box.is--button.is-checked {
      border-color: #32b78b;
      background-color: rgba(50, 183, 139, 0.05);
      .checklist-text {
        color: #32b78b;
      }

      .radio__inner {
        border-color: #32b78b;
        background-color: #32b78b;
        padding-left: 10rpx;
        padding-bottom: 10rpx;

        .radio__inner-icon {
          background-color: transparent;
        }

        .radio__inner-icon::before {
          content: "\2713"; /* 使用 Unicode 字符编码表示勾号 */
          color: #ffffff; /* 勾号的颜色 */
          font-size: 24rpx; /* 勾号的大小 */
        }
      }
    }
  }
  .footer {
    position: fixed;
    bottom: 0;
    z-index: 1;
    width: 100%;
    background: #ffffff;
    border: 1px solid #dce3ec;
    padding: 18rpx 28rpx 60rpx 28rpx;
    .btn-add {
      font-size: 36rpx;
      font-family: PingFang SC-Medium, PingFang SC;
      height: 88rpx;
      background: linear-gradient(90deg, #3976f1 0%, #3ca0f6 100%);
      border-radius: 16rpx;
      color: #ffffff;
    }
  }
}
</style>
