Jelajahi Sumber

fix:问卷提交

magic v 4 tahun lalu
induk
melakukan
e3eddda96a

+ 131 - 78
src/pages/FormVolume/Layoutileads1/index.vue

@@ -18,91 +18,100 @@
           <img :src="ImgLeads1" class="il-img2" />
         </div>
       </div>
-      <div class="bl-flex card" column card not-margin>
-        <transition-group name="flip-list" class="volume-content bl-flex" tag="div" column size-md>
-          <div
-            v-for="(item, index) in data.result"
-            :key="index + 1"
-            :class="{ cur: edataItem === item }"
-            @click="$emit('selectItem', item)">
+      <div class="bl-flex card" column card not-margin not-padding>
+        <div margin-bottom-md shadow round padding-bottom-sm padding-top-xs
+          v-for="(combo, comboIndex) in putResult"
+          :key="comboIndex">
+          <div class="bl-flex" flex-wrap items-center between border-bottom padding-md padding-left-lg
+            v-if="combo.id">
+            <div color-warning bold size-sm>{{ combo.name }}</div>
+            <span color active padding-top-xs padding-bottom-xs size-xs v-if="!!comboIndex" @click="copyPrevVal(combo.result, comboIndex)">与上一个内容一致</span>
+          </div>
+          <transition-group name="flip-list" class="volume-content bl-flex" tag="div" column size-sm padding-left-lg padding-right-lg>          
+            <div
+              v-for="(item, index) in combo.result"
+              :key="index + 1"
+              :class="{ cur: edataItem === item }"
+              @click="$emit('selectItem', item)">
 
-            <div class="bl-flex" border-bottom
-              :items-center="item.type != 'textarea'">
-              <label class="f-label" nowrap :padding-top-lg="item.type == 'textarea'">
-                <span v-if="item.required" color-error>*</span>
-                {{ item.title }}
-              </label>
-              <div flex1>
-                <textarea 
-                  v-model="item.val" 
-                  :maxlength="item.max || 200" placeholder="请填写" 
-                  :text-right="(item.layout_align || data.topic.layout_align) === 'right'"
-                  v-if="item.type === 'textarea'" />
+              <div class="bl-flex" border-bottom
+                :items-center="item.type != 'textarea'">
+                <label class="f-label" nowrap :padding-top-lg="item.type == 'textarea'">
+                  <span v-if="item.required" color-error>*</span>
+                  {{ item.title }}
+                </label>
+                <div flex1>
+                  <textarea 
+                    v-model="item.val" 
+                    :maxlength="item.max || 200" placeholder="请填写" 
+                    :text-right="(item.layout_align || data.topic.layout_align) === 'right'"
+                    v-if="item.type === 'textarea'" />
 
-                <input v-model="item.val" 
-                  :maxlength="item.max || 200" 
-                  :text-right="(item.layout_align || data.topic.layout_align) === 'right'"
-                  :placeholder="['input'].includes(item.type) ? '请填写' : '请选择'" 
-                  :readonly="!['input'].includes(item.type) || item.disabled"
-                  v-if="['input', 'select', 'date'].includes(item.type)"
-                  @click="!['input'].includes(item.type) && btnOpen(item)" />
+                  <input v-model="item.val" 
+                    :maxlength="item.max || 200" 
+                    :text-right="(item.layout_align || data.topic.layout_align) === 'right'"
+                    :placeholder="['input'].includes(item.type) ? '请填写' : '请选择'" 
+                    :readonly="!['input'].includes(item.type) || item.disabled"
+                    v-if="['input', 'select', 'date'].includes(item.type)"
+                    @click="!['input'].includes(item.type) && btnOpen(item)" />
 
-                <div class="slider-layout" v-if="item.type === 'slider'">
-                  <div class="val" v-if="item.val">{{ item.val }}</div>
-                  <div class="warn" v-else>拨动滑块选择</div>
-                  <van-slider
-                    v-model="item.sliderVal"
-                    :min="-1" 
-                    :max="item.content.length - 1"
-                    @input="item.val = (item.content[item.sliderVal] || {}).title || ''" />
-                  <div class="ruler-layout">
-                    <div class="ruler-item">
-                      <span></span>
-                    </div>
-                    <div class="ruler-item"
-                      v-for="(it, itIndex) in item.content"
-                      :key="itIndex">
-                      <span v-if="!it.sliderHide">
-                        {{ it.title }}
-                        <br v-if="it.memo" />
-                        {{ it.memo || '' }}
-                      </span>
+                  <div class="slider-layout" v-if="item.type === 'slider'">
+                    <div class="val" v-if="item.val">{{ item.val }}</div>
+                    <div class="warn" v-else>拨动滑块选择</div>
+                    <van-slider
+                      v-model="item.sliderVal"
+                      :min="-1" 
+                      :max="item.content.length - 1"
+                      @input="item.val = (item.content[item.sliderVal] || {}).title || ''" />
+                    <div class="ruler-layout">
+                      <div class="ruler-item">
+                        <span></span>
+                      </div>
+                      <div class="ruler-item"
+                        v-for="(it, itIndex) in item.content"
+                        :key="itIndex">
+                        <span v-if="!it.sliderHide">
+                          {{ it.title }}
+                          <br v-if="it.memo" />
+                          {{ it.memo || '' }}
+                        </span>
+                      </div>
                     </div>
                   </div>
-                </div>
 
-                <van-radio-group padding-top-md padding-bottom-md
-                  v-model="item.val" 
-                  :style="{ justifyContent: (item.layout_align || data.topic.layout_align) === 'right' ? 'flex-end' : 'flex-start' }"
-                  :direction="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
-                  v-if="['radio'].includes(item.type)">
-                  <van-radio
-                    :class="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
-                    :name="it.title" 
-                    v-for="(it, itIndex) in item.content" 
-                    :key="itIndex">{{ it.title }}{{ it.memo && `(${it.memo})` }}</van-radio>
-                </van-radio-group>
+                  <van-radio-group padding-top-sm padding-bottom-sm
+                    v-model="item.val" 
+                    :style="{ justifyContent: (item.layout_align || data.topic.layout_align) === 'right' ? 'flex-end' : 'flex-start' }"
+                    :direction="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
+                    v-if="['radio'].includes(item.type)">
+                    <van-radio
+                      :class="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
+                      :name="it.title" 
+                      v-for="(it, itIndex) in item.content" 
+                      :key="itIndex">{{ it.title }}{{ it.memo && `(${it.memo})` }}</van-radio>
+                  </van-radio-group>
 
-                <van-checkbox-group padding-top-md padding-bottom-md
-                  v-model="item.val"
-                  :style="{ justifyContent: (item.layout_align || data.topic.layout_align) === 'right' ? 'flex-end' : 'flex-start' }"
-                  :direction="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
-                  :max="item.max" 
-                  v-if="item.type === 'checkbox'">
-                  <van-checkbox 
-                    :class="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
-                    :name="it.title" 
-                    v-for="(it, itIndex) in item.content" 
-                    :key="itIndex" 
-                    shape="square">{{ it.title }}{{ it.memo && `(${it.memo})` }}</van-checkbox>
-                </van-checkbox-group>
+                  <van-checkbox-group padding-top-sm padding-bottom-sm
+                    v-model="item.val"
+                    :style="{ justifyContent: (item.layout_align || data.topic.layout_align) === 'right' ? 'flex-end' : 'flex-start' }"
+                    :direction="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
+                    :max="item.max" 
+                    v-if="item.type === 'checkbox'">
+                    <van-checkbox 
+                      :class="(item.layout_inline || data.topic.layout_inline) === 2 ? 'vertical' : 'horizontal'"
+                      :name="it.title" 
+                      v-for="(it, itIndex) in item.content" 
+                      :key="itIndex" 
+                      shape="square">{{ it.title }}{{ it.memo && `(${it.memo})` }}</van-checkbox>
+                  </van-checkbox-group>
+                </div>
+                <i class="font-ileads ileads-icon-jiantou" color-des padding-sm not-padding-right
+                  v-if="['select', 'date'].includes(item.type)"
+                  @click="btnOpen(item)"></i>
               </div>
-              <i class="font-ileads ileads-icon-jiantou" color-des padding-sm not-padding-right
-                v-if="['select', 'date'].includes(item.type)"
-                @click="btnOpen(item)"></i>
             </div>
-          </div>
-        </transition-group>
+          </transition-group>
+        </div>
         <div class="bl-flex" relative between padding-top-lg>
           <div class="l-pie" round-pie bg-color-6></div>
           <div class="r-pie" round-pie bg-color-6></div>
@@ -110,7 +119,7 @@
         <div class="bl-flex" padding-lg padding-left-xl padding-right-xl v-if="!!data.result.length">
           <button class="btn primary" round-pie1
             :disabled="loading.submit || !data.result.length" 
-            @click="$emit('submit')">提交</button>
+            @click="$emit('submit', combos)">提交</button>
         </div>
       </div>
     </div>
@@ -168,7 +177,15 @@ export default {
         title: '',
         currentDate: '',
         data: {}
-      }
+      },
+      combos: []
+    }
+  },
+  computed: {
+    putResult () {
+      return (this.combos && this.combos.length)
+        ? this.combos
+        : [this.data]
     }
   },
   methods: {
@@ -222,7 +239,43 @@ export default {
     },
     onCancelDate () {
       this.show.date = false
+    },
+    inCombos () {
+      let { ids, combos } = this.$route.query
+      let arr_ids = ids && ids.split(',')
+      let arr_combos = combos && combos.split(',')
+      let comboRst = arr_ids && arr_ids.map((id, index) => {
+        return {
+          id,
+          name: arr_combos[index],
+          query: {
+            buyer_id: id
+          },
+          result: JSON.parse(JSON.stringify(this.data.result))
+        }
+      })
+      this.combos = comboRst
+    },
+    // 与上一个内容一致
+    copyPrevVal (result, index) {
+      try {
+        let prevItem = this.combos[index - 1]
+        if (!prevItem) {
+         throw new Error('缺少上一个表单对象')
+        }
+        result.forEach((item, i) => {
+          item.val = prevItem.result[i].val
+        })
+      } catch (err) {
+        this.$toast.fail('引用错误')
+      }
+    },
+    init () {
+      this.inCombos()
     }
+  },
+  created () {
+    this.init()
   }
 }
 </script>

+ 3 - 3
src/pages/FormVolume/Layoutileads1/style.scss

@@ -23,7 +23,7 @@
     width: 100%;
     width: 100%;
     outline: none;
-    padding: $sp-lg 0;
+    padding: $sp-md 0;
   }
   input[readonly] {
     cursor: pointer;
@@ -117,8 +117,8 @@
   height: $size-md;
 }
 .l-pie {
-  margin-left: -($sp-lg + $size-md / 2)
+  margin-left: -($size-md / 2)
 }
 .r-pie {
-  margin-right: -($sp-lg + $size-md / 2)
+  margin-right: -($size-md / 2)
 }

+ 41 - 17
src/pages/FormVolume/mixins/index.js

@@ -106,9 +106,9 @@ export default {
         this.TITLE = title
       }
     },
-    isForm(callback) {
+    isForm(result, callback) {
       return new Promise((resolve, reject) => {
-        let state = this.data.result.some(item => {
+        let state = result.some(item => {
           if (!item.required) {
             return false
           }
@@ -150,8 +150,9 @@ export default {
       data.result.forEach(item => {
         typeof callback === 'function' && callback(item)
 
-        if (new RegExp('手机号码').test(item.title)) {
-          item.val = this.$route.query.patient_mobile || ''
+        let { patient_mobile } = this.$route.query
+        if (new RegExp('手机号码').test(item.title) && patient_mobile) {
+          item.val = patient_mobile
           item.disabled = true
         }
       })
@@ -164,16 +165,20 @@ export default {
         callback && callback()
       })
     },
-    async btnSubmit() {
-      this.loading.submit = true
+    async btnSubmit(datas) {
+      let pm
       let ld = null
+      let edatas = datas || [this.data]
+      this.loading.submit = true
       try {
-        await this.isForm(item => {
-          this.$dialog.alert({
-            title: '必填项',
-            message: `${item.title}`,
+        await Promise.all(edatas.map(data => {
+          return this.isForm(data.result, item => {
+            this.$dialog.alert({
+              title: '必填项',
+              message: `${item.title}`,
+            })
           })
-        })
+        }))
         if (this.isEdit) {
           await this.$dialog.confirm({
             title: '模拟提交',
@@ -189,7 +194,22 @@ export default {
           message: '请确认无误提交?',
         })
         ld = this.$toast.loading({ message: '提交中...', duration: 0 })
-        let result = this.data.result.map(item => {
+        let pms = edatas.map(data => this.btnSubmitItem(data.result, data.query))
+        await Promise.all(pms)
+        this.btnOpenSuccess(() => this.btnLinkBack())
+        pm = Promise.resolve()
+      } catch (error) {
+        pm = Promise.reject()
+      }
+      ld && ld.clear()
+      this.loading.submit = false
+      return pm
+    },
+    async btnSubmitItem(dataResult, option) {
+      let pm
+      dataResult = dataResult || this.data.result
+      try {
+        let result = dataResult.map(item => {
           return {
             detail_id: item.detail_id,
             val: item.val
@@ -207,7 +227,7 @@ export default {
             sight_memo: new RegExp('视力')
           }
           let keys = Object.keys(config)
-          let objs = this.data.result.map(item => {
+          let objs = dataResult.map(item => {
             let rst = { key: '', val: '' }
             keys.some(k => {
               let reg = config[k]
@@ -230,6 +250,7 @@ export default {
 
         let query = {
           ...this.$route.query,
+          ...option,
           ...patient,
           flag: this.data.topic.flag,
           data: JSON.stringify(result)
@@ -237,13 +258,16 @@ export default {
         delete query.replace
         delete query.to
         delete query.go
-        await api.apiPostVolumeInfo(query)
-        this.btnOpenSuccess(() => this.btnLinkBack())
+        delete query.ids
+        delete query.combos
+        
+        let res = await api.apiPostVolumeInfo(query)
+        pm = Promise.resolve(res)
       } catch (error) {
         console.log(error)
+        pm = Promise.reject(res)
       }
-      ld && ld.clear()
-      this.loading.submit = false
+      return pm
     },
     btnLinkBack() {
       clearInterval(this.codeMess.t)