<template>
  <div class="dm-wrap" :loading="loading">
    <p class="title mb30">手工导入群发</p>
    <el-form ref="form" :model="ruleForm" label-width="120px" :rules="rules">
      <el-form-item label="营销场景">
        <span v-if="isInfo">{{ ruleForm.sceneSettingName }}</span>
        <el-select v-else class="w250" v-model="ruleForm.sceneSettingId" placeholder="选择营销场景">
          <el-option v-for="item in sceneSettingIdOptions" :key="item.sceneSettingId" :label="item.sceneName" :value="item.sceneSettingId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="发送时间">
        <el-select class="w250" v-model="ruleForm.sendType">
          <el-option v-for="(v, i) in sendTypeOptions" :key="i" :value="v.value" :label="v.label"></el-option>
        </el-select>
        <el-date-picker class="w250" v-if="ruleForm.sendType" v-model="ruleForm.sendTime" type="datetime" placeholder="选择日期时间" align="right" :picker-options="pickerOptions"></el-date-picker>
      </el-form-item>
      <el-form-item label="上传文件">
        <div>
          <el-button icon="el-icon-upload2" class="dash-btn">点击上传</el-button>
          <el-button type="text" class="ml10">点击下载文件模板</el-button>
        </div>
        <p style="margin-top:8px;color:#909399;font-size:12px;line-height:1;">券码数量单次最多不超过5000条</p>
      </el-form-item>
    </el-form>
    <p class="title mb15 mt40">短信模板设置</p>
    <div class="dm-title__label--tips" style="margin-top:15px;margin-bottom:20px;"><i class="el-icon-warning pr8 warning-color"></i>短信运营商限制：为避免骚扰用户，营销短信只允许在8点到22点发送</div>
    <sms-temp pbSize="pb15" :activeId.sync="ruleForm.smsTemplateId" @emitSmsItemInfo="onSmsItemInfo"></sms-temp>
    <div class="text-center">
      <el-button type="primary">新建群发</el-button>
      <el-button>返回</el-button>
    </div>
  </div>
</template>

<script>
import smsTemp from '@/components/libs/smsTemp';
import { formatDateTimeByType } from '@/utils/index.js';
import { sceneSettingList } from '@/service/api/wechatApi.js';
export default {
  name: 'import-send-form',
  data() {
    return {
      loading: false,
      ruleForm: {
        sceneSettingName: '',
        sceneSettingId: '',
        sendTime: '',
        sendType: 0,
        smsTemplateId: ''
      },
      rules: {},
      sceneSettingIdOptions: [],
      sendTypeOptions: [{ value: 0, label: '立即发送' }, { value: 1, label: '选择时间发送' }], // eslint-disable-line
      isAdd: this.$route.meta.type === 'add',
      isInfo: this.$route.meta.type === 'info'
    };
  },
  components: {
    smsTemp
  },
  methods: {
    formatDateTimeByType,
    onSmsItemInfo(val) {
      this.smsType = val.type;
      console.log(val);
    },
    async sceneSettingList() {
      let res = await sceneSettingList();
      this.sceneSettingIdOptions = res.result || [];
    }
  },
  mounted() {
    this.sceneSettingList();
  },
  created() {
    this.$store.commit('mutations_breadcrumb', [{ name: '营销管理', path: '' }, { name: '短信营销', path: '' }, { name: this.info ? '手工导入群发详情' : '新建导入群发', path: '' }]); // eslint-disable-line
  }
};
</script>

<style lang="scss" scoped>
.mt40 {
  margin-top: 40px;
}
.title {
  font-size: 16px;
  font-weight: 500;
  color: rgba(48, 49, 51, 1);
  line-height: 22px;
}
.dash-btn {
  width: 174px;
  border-style: dashed;
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
}
.dm-title__label--tips {
  background: #fffbe6;
  border-color: #ffe58f;
  margin-right: 0px;
}
</style>
