<template>
  <div class="EvaluateForm">
    <u-navbar back-icon-color="#000" title="我要评价" title-color="#000" title-width="300" title-size="32" :title-bold="true" :background="backgroundNavbar" :is-fixed="true" height="44"></u-navbar>
    <div class="header-info">
      <div class="name">{{ shopInfo.shopName }}</div>
      <div class="time">
        <u-icon name="clock" color="#000" size="32"></u-icon> 评价时间：{{ shopInfo.date }}
      </div>
      <div class="flex-info">
        <div class="flex-item item-user">
          <p>经营者</p>
          <div>{{ shopInfo.name }}</div>
        </div>
        <!-- <div class="flex-item item-phone">
          <p>联系电话</p>
          <div>{{ shopInfo.phone }}</div>
          <span></span>
        </div> -->
        <div class="flex-item item-type">
          <p>经营类型</p>
          <div>{{ $dict.getLabel('operatorType', shopInfo.operatorType) }}</div>
          <span></span>
        </div>
        <div class="flex-item item-phone" v-if="shopInfo.phone" @click="callPhone(shopInfo.phone)">
          <span></span>
          <img src="https://cdn.cunwuyun.cn/wechat/fd-store/phone-icon.png" alt="">
        </div>
      </div>
    </div>
    <div class="line-bg"></div>
    <div class="form-info">
      <div class="form-title">评价清单</div>
      <!-- <div class="mini-title" v-if="positiveTypeList.length">一、正面清单</div> -->
      <div class="item" v-for="(item, index) in positiveTypeList" :key="index">
        <div class="label">({{index+1}})、{{item.listType}}</div>
        <div class="value">
          <!-- <div class="radio" @click="positiveRadioClick(index, 1)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 1">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            是  
          </div>
          <div class="radio" @click="positiveRadioClick(index, 0)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 0">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            否
          </div> -->
          <div class="radio" @click="positiveRadioClick(index, 0)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 0">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            好 
          </div>
          <div class="radio" @click="positiveRadioClick(index, 1)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 1">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            一般
          </div>
          <div class="radio" @click="positiveRadioClick(index, 2)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 2">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            较差
          </div>
          <div class="radio" @click="positiveRadioClick(index, 3)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 3">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            差
          </div>
        </div>
      </div>
      <!-- <div class="mini-title" v-if="negativeTypeList.length">二、负面清单</div> -->
      <div class="item" v-for="(item, index) in negativeTypeList" :key="index">
        <div class="label">({{positiveTypeList.length+1}})、{{item.listType}}</div>
        <div class="value">
          <!-- <div class="radio" @click="negativeRadioClick(index, 1)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 1">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            是  
          </div>
          <div class="radio" @click="negativeRadioClick(index, 0)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 0">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            否
          </div> -->
          <div class="radio" @click="negativeRadioClick(index, 0)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 0">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            好  
          </div>
          <div class="radio" @click="negativeRadioClick(index, 1)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 1">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            一般
          </div>
          <div class="radio" @click="negativeRadioClick(index, 2)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 2">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            较差
          </div>
          <div class="radio" @click="negativeRadioClick(index, 3)">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-xz.png" alt="" v-if="item.status == 3">
            <img src="https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-wxz.png" alt="" v-else>
            差
          </div>
        </div>     
      </div>
      <div class="line-bg"></div>
      <div class="text-area">
        <u-input type="textarea" trim v-model="form.remark"  maxlength="300" height="400" placeholder="请填写评语..." 
          placeholder-style="color: #333;font-size: 15px;"/>
        <p>{{form.remark.length}}/300</p>
      </div>
      <div class="line-bg"></div>
      <div class="upload">
        <div class="label">上传图片</div>
        <div class="upload-info">
          <AiUploader v-model="form.file" :limit="9"></AiUploader>
        </div>
        <p>最多上传9张</p>
      </div>
    </div>
    <div class="line-bg"></div>
    <div class="footer" @click="add">
      <div class="btn">提交</div>
    </div>
  </div>
</template>

<script>
import {mapState} from 'vuex'
export default {
  name: 'EvaluateForm',
  appName: '我要评价',
  customNavigation: true,
  navigationBarBackgroundColor: '#ffffff',
  navigationBarTextStyle: 'black',
  data() {
    return {
      form: {
        remark: '',
        file: []
      },
      positiveTypeList: [],
      negativeTypeList: [],
      shopId: '',
      shopInfo: {},
      backgroundNavbar: {
        background: '#fff',
      }
    }
  },
  computed: {
    ...mapState(['user'])
  },
  onLoad(e) {
    this.getTypeList()
    this.shopId = e.shopId
    this.getShopDetail()
  },
  onShow() {
    uni.setNavigationBarColor({
      frontColor: 'black',
      backgroundColor: '#ffffff'
    })
  },
  methods: {
    getTypeList() {
      this.$loading()
      this.$instance.post(`/app/appscorerules/list?status=1&size=100`).then(res => {
        if (res?.data) {
          res.data.records.map((item) => {
            item.status = null
            if(item.type == 1) {
              this.positiveTypeList.push(item)
            }else {
              this.negativeTypeList.push(item)
            }
          })
        }
      }).finally(() => uni.hideLoading())
    },
    getShopDetail() {
      this.$loading()
      this.$instance.post(`/app/appshoparchives/queryDetailById?id=${this.shopId}`).then(res => {
        if (res?.data) {
          this.shopInfo = res.data
          this.shopInfo.date = this.getDate()
        }
      }).finally(() => uni.hideLoading())
    },
    positiveRadioClick(index, val) {
      this.positiveTypeList[index].status = val
    },
    negativeRadioClick(index, val) {
      this.negativeTypeList[index].status = val
    },
    add() {
      var isStatus = true
      this.positiveTypeList.map((item) => {
        if(item.status == null) {
          isStatus = false
        }
      })
      this.negativeTypeList.map((item) => {
        if(item.status == null) {
          isStatus = false
        }
      })

      if(!isStatus) {
        return this.$u.toast('请填写评价清单中所有项内容')
      }
      if(!this.form.remark) {
        return this.$u.toast('请填写评语')
      }
      this.$loading()
      var imgUrlList = []
      if(this.form.file.length) {
        this.form.file.map((item) => {
          imgUrlList.push(item.url)
        })
      }
      var assessTypeList = this.positiveTypeList.concat(this.negativeTypeList)
      this.$instance.post(`/app/appshopassess/addOrUpdate`, {
        ...this.form,
        shopId: this.shopId,
        pictureUrl: imgUrlList.length ? imgUrlList.join(',') : '',
        evaluatorPhone: this.user.phone,
        evaluator: this.user.name ? this.user.name : this.user.nickName,
        evaluatorUrl: this.user.avatarUrl,
        itemList: assessTypeList
      }).then(res => {
        if (res?.data) {
          this.$u.toast('提交成功')
          uni.$emit('updateStore')
          setTimeout(() => {
            uni.navigateBack()
          }, 300)
        }
      }).finally(() => uni.hideLoading())
    },
    getDate() {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;

      return `${year}-${month}-${day}`;
    },
    callPhone(phone) {
      uni.makePhoneCall({ phoneNumber: phone })
    },
  },
}
</script>

<style lang="scss" scoped>
.EvaluateForm {
  padding-bottom: 188px;
  .header-info {
    width: 100%;
    padding: 36px 32px 32px;
    box-sizing: border-box;
    color: #323233;
    background-image: url("https://cdn.cunwuyun.cn/wechat/fd-store/evaluate-form-headerBg.png");
    background-size: 100vw;
    background-repeat: no-repeat;
    .name {
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 36px;
      line-height: 40px;
      word-break: break-all;
      margin-bottom: 16px;
    }
    .time {
      font-family: PingFangSC-Regular;
      font-weight: 400;
      font-size: 28px;
      line-height: 40px;
      margin-bottom: 20px;
      u-icon {
        margin-right: 6px;
      }
    }
    .flex-info {
      width: 100%;
      position: relative;
      .flex-item {
        display: inline-block;
        position: relative;
        font-family: PingFangSC;
        font-size: 24px;
        line-height: 40px;
        box-sizing: border-box;
        p {
          color: #999;
        }
        div {
          color: #222;
        }
        span {
          position: absolute;
          top: 16px;
          left: 0;
          height: 48px;
          border-right: 1px solid #D9D9D9;
        }
      }
      .item-user {
        padding-right: 32px;
      }
      .item-phone {
        padding: 0 32px;
        img {
          width: 40px;
          height: 40px;
          margin-top: 16px;
        }
      }
      .item-type {
        padding: 0 32px;
      }
    }
  }
  .form-info {
    background-color: #fff;
    .form-title {
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 34px;
      color: #333;
      letter-spacing: 0;
      line-height: 40px;
      padding: 20px 0 20px 32px;
      box-sizing: border-box;
      border-bottom: 1px solid #F4F4F4;
    }
    .mini-title {
      font-family: PingFangSC-SNaNpxibold;
      font-weight: 600;
      font-size: 28px;
      color: #333;
      line-height: 40px;
      padding: 20px 0 0 32px;
    }
    .item {
      padding: 32px 32px 24px 32px;
      box-sizing: border-box;
      border-bottom: 1px solid #F4F4F4;
      .label {
        font-family: PingFangSC-Regular;
        font-weight: 400;
        font-size: 28px;
        color: #333;
        line-height: 40px;
        margin-bottom: 44px;
      }
      .value {
        padding-left: 58px;
        font-family: PingFangSC-Regular;
        font-size: 28px;
        color: #323233;
        line-height: 40px;
        .radio {
          display: inline-block;
          width: 25%;
        }
        img {
          width: 32px;
          height: 32px;
          margin-right: 18px;
          vertical-align: middle;
        }
        // .img-no {
        //   margin-left: 138px;
        // }
      }
    }
    .text-area {
      padding: 24px 30px;
      box-sizing: border-box;
      .label {
        font-family: PingFangSC-Regular;
        font-size: 28px;
        color: #333;
        line-height: 34px;
        margin-bottom: 8px;
      }
      p {
        font-family: PingFangSC-Regular;
        font-size: 24px;
        color: #999;
        line-height: 34px;
        text-align: right;
      }
    }
    .upload {
      .label {
        font-family: PingFangSC-Regular;
        font-size: 28px;
        color: #333;
        line-height: 80px;
        padding-left: 30px;
        box-sizing: border-box;
      }
      .upload-info {
        padding: 0 30px;
      }
      p {
        font-family: PingFangSC-Regular;
        font-size: 24px;
        color: #999;
        line-height: 34px;
        padding: 16px 0 24px 30px;
        box-sizing: border-box;
      }
    }
  }
  .line-bg {
    width: 100%;
    height: 32px;
    background-color: #F4F5FA;
  }
  .footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 20px 32px 88px 32px;
    box-sizing: border-box;
    background: #FFF;
    z-index: 999;
    .btn {
      width: 100%;
      height: 80px;
      background: #2D7DFF;
      border-radius: 40px;
      font-family: PingFangSC-Medium;
      font-weight: 500;
      font-size: 34px;
      color: #FFF;
      text-align: center;
      line-height: 80px;
    }
  }
}
</style>