edit.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view class="container main">
  3. <view class="one">
  4. <view class="list" v-for="(item, index) in investigate" :key="index">
  5. <div class="problem">
  6. <text v-if="item.is_must=='0'" class="t-icon t-icon-xinghao"></text>
  7. <span v-if="item.is_must=='0'">{{item.problem}}</span>
  8. <span style="margin: 0 0 0 2vw;" v-else>{{item.problem}}</span>
  9. </div>
  10. <div class="type" v-if="item.type =='0'">
  11. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  12. <uni-data-checkbox v-model="item.reply" :localdata="item.answer"
  13. :map="{text:'text',value:'text'}" />
  14. </div>
  15. <div class="type" v-if="item.type =='1'">
  16. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  17. <uni-data-checkbox v-model="item.reply" multiple :localdata="item.answer"
  18. :map="{text:'text',value:'text'}" />
  19. </div>
  20. <div class="type" v-if="item.type =='2'">
  21. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  22. <uni-data-select v-model="item.reply" :localdata="item.answer"></uni-data-select>
  23. </div>
  24. <div class="type" v-if="item.type =='3'">
  25. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  26. <uni-easyinput v-model="item.reply" :placeholder="getField(item.problem)"></uni-easyinput>
  27. </div>
  28. <div class="type" v-if="item.type =='4'">
  29. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  30. <uni-easyinput type="textarea" v-model="item.reply"
  31. :placeholder="getField(item.problem)"></uni-easyinput>
  32. </div>
  33. <div class="type" v-if="item.type =='5'">
  34. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  35. <upload class='upload' :list="item.reply" name="reply" :count="1" @uplSuc="uplSuc($event,item)"
  36. @uplDel="uplDel($event,item)">
  37. </upload>
  38. </div>
  39. <div class="type" v-if="item.type =='6'">
  40. <div class="list">
  41. <div v-for="(aa, ina) in item.answer" :key="ina" class="name">{{aa.text}}</div>
  42. </div>
  43. <div class="list" v-for="(gg, inx) in item.reply" :key="inx">
  44. <div v-for="(aa, ina) in item.answer" :key="ina" class="input">
  45. <uni-easyinput v-model="gg[aa.text]" :clearable="false"
  46. :placeholder="getField(aa.text)"></uni-easyinput>
  47. </div>
  48. <uni-icons @tap="toDel(item,gg.sid)" class="icon" type="closeempty" size="20"></uni-icons>
  49. </div>
  50. <div class="add" @tap="toAdd(item)">+新增一行</div>
  51. </div>
  52. <div class="type" v-if="item.type =='7'">
  53. <image class="image" v-if="item.answer&&item.answer.length>0" v-for="(as, img) in item.answer"
  54. :key="img" :src="getUrl(as.url)"></image>
  55. <div class="remark" v-if="item.remark">{{item.remark}}</div>
  56. </div>
  57. </view>
  58. <view class="button">
  59. <button type="warn" @tap="toSave">保存</button>
  60. </view>
  61. </view>
  62. </view>
  63. </template>
  64. <script>
  65. import upload from '../../components/upload/index.vue';
  66. import moment from 'moment';
  67. export default {
  68. components: {
  69. upload
  70. },
  71. data() {
  72. return {
  73. id: '',
  74. user: {},
  75. info: {},
  76. investigate: [],
  77. }
  78. },
  79. onLoad: async function(e) {
  80. const that = this;
  81. that.$set(that, `id`, e && e.id || '');
  82. await that.searchToken();
  83. await that.search();
  84. },
  85. methods: {
  86. // 用户信息
  87. searchToken() {
  88. const that = this;
  89. try {
  90. const res = uni.getStorageSync('token');
  91. if (res) {
  92. const user = that.$jwt(res);
  93. that.$set(that, `user`, user);
  94. }
  95. } catch (e) {}
  96. },
  97. // 查询
  98. async search() {
  99. const that = this;
  100. if (that.id) {
  101. let res;
  102. res = await that.$api(`/matchReg/${that.id}`, 'GET', {})
  103. if (res.errcode == '0') {
  104. that.$set(that, `info`, res.data)
  105. if (res.data.info && res.data.info.length > 0) {
  106. for (let val of res.data.info) {
  107. if (val.type == '2') {
  108. for (let s of val.answer) {
  109. s.value = s.text
  110. }
  111. }
  112. }
  113. that.$set(that, `investigate`, res.data.info)
  114. }
  115. } else {
  116. uni.showToast({
  117. title: res.errmsg,
  118. icon: 'none'
  119. });
  120. }
  121. }
  122. },
  123. getField(data) {
  124. let res = "请输入内容"
  125. if (data) res = `请输入${data}`
  126. return res
  127. },
  128. // 图片处理
  129. getUrl(e) {
  130. const that = this;
  131. if (e) return that.$config.serverFile + e
  132. },
  133. // 图片上传
  134. uplSuc(e, item) {
  135. const that = this;
  136. for (let val of that.investigate) {
  137. if (val.sid == item.sid) val.reply = [e.data]
  138. }
  139. },
  140. // 图片删除
  141. uplDel(e, item) {
  142. const that = this;
  143. for (let val of that.investigate) {
  144. if (val.sid == item.sid) val.reply = []
  145. }
  146. },
  147. // 新增一行
  148. toAdd(item) {
  149. const that = this;
  150. for (let val of that.investigate) {
  151. if (val.sid == item.sid) {
  152. let answer = []
  153. let obj = {
  154. sid: moment().valueOf(),
  155. }
  156. for (let s of val.answer) {
  157. obj[s.text] = '';
  158. }
  159. answer.push(obj)
  160. if (val.reply) val.reply = [...val.reply, ...answer, ]
  161. else val.reply = answer
  162. }
  163. }
  164. },
  165. // 删除一行
  166. toDel(item, sid) {
  167. const that = this;
  168. if (item && item.reply && item.reply.length > 0) {
  169. let answer = item.reply.filter((i) => i.sid != sid)
  170. for (let val of that.investigate) {
  171. if (val.sid == item.sid) {
  172. val.reply = answer
  173. }
  174. }
  175. }
  176. },
  177. async toSave() {
  178. const that = this;
  179. let data = {
  180. id: that.id,
  181. status: '0',
  182. info: that.investigate
  183. }
  184. const res = await that.$api(`/matchReg/${that.id}`, 'POST', data)
  185. if (res.errcode == '0') {
  186. uni.showModal({
  187. content: "调查问卷修改成功!",
  188. showCancel: false
  189. });
  190. uni.navigateBack({
  191. delta: 1
  192. })
  193. } else {
  194. uni.showToast({
  195. title: res.errmsg,
  196. icon: 'none'
  197. });
  198. }
  199. },
  200. }
  201. }
  202. </script>
  203. <style lang="scss" scoped>
  204. .main {
  205. .one {
  206. padding: 2vw;
  207. .list {
  208. .problem {
  209. display: flex;
  210. align-items: center;
  211. .t-icon {
  212. width: 30px !important;
  213. height: 30px !important;
  214. }
  215. }
  216. .type {
  217. padding: 2vw 0 2vw 2vw;
  218. .list {
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. margin: 2vw 0;
  223. .name {
  224. width: 50%;
  225. text-align: center;
  226. }
  227. .input {
  228. margin: 0 1vw 0 0;
  229. .name {
  230. width: 50%;
  231. text-align: center;
  232. margin: 0 0 2vw 0;
  233. }
  234. }
  235. .icon {
  236. display: none;
  237. margin: 1vw 0 0 0;
  238. }
  239. }
  240. .list:hover {
  241. .icon {
  242. display: block;
  243. }
  244. }
  245. .add {
  246. border: 1px solid #e5e5e5;
  247. border-radius: 5px;
  248. text-align: center;
  249. padding: 2vw;
  250. }
  251. .image {
  252. width: 96%;
  253. }
  254. .remark {
  255. margin: 2vw;
  256. font-size: 12px;
  257. color: red;
  258. }
  259. }
  260. }
  261. .button {
  262. margin: 2vw 0 0 0;
  263. padding: 2vw;
  264. text-align: center;
  265. button {
  266. background-color: var(--f3CColor);
  267. font-size: var(--font14Size);
  268. border-radius: 2vw;
  269. }
  270. }
  271. }
  272. }
  273. </style>