index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="page-container">
  3. <view class="page-body">
  4. <u--form label-width="auto" labelAlign="left"
  5. ref="uForm"
  6. :model="model"
  7. :rules="rules"
  8. :labelStyle="{
  9. fontSize: '28rpx',
  10. fontWeight: '500',
  11. }"
  12. >
  13. <u-cell-group :border="false">
  14. <view class="box">
  15. <template>
  16. <u-cell :border="true" :isLink="true" :clickable="true" class="hidde-cell-title"
  17. @click="$refs.carChooseRef.show()"
  18. >
  19. <view slot="value" class="value">
  20. <u-form-item label="车牌号" prop="form.vehicleId" :required="true">
  21. <u--input
  22. :value="model.form.plate"
  23. placeholder="请选择"
  24. border="none"
  25. inputAlign="right"
  26. :disabled="true"
  27. disabledColor="none"
  28. :customStyle="{
  29. pointerEvents: 'none',
  30. }"
  31. >
  32. </u--input>
  33. </u-form-item>
  34. </view>
  35. </u-cell>
  36. <tq-car-user ref="carChooseRef"
  37. @confirm="(data) => {
  38. model.form.vehicleId = data.id
  39. model.form.plate = data.label
  40. $refs.uForm.validateField('form.vehicleId')
  41. }"
  42. >
  43. </tq-car-user>
  44. </template>
  45. <u-cell :border="false" :isLink="false" :clickable="false" class="hidde-cell-title">
  46. <view slot="value" class="value">
  47. <u-form-item label="备注" labelPosition="top" prop="form.remark" :required="false">
  48. <u--textarea
  49. v-model="model.form.remark"
  50. placeholder="请输入备注"
  51. border="none"
  52. :count="true"
  53. maxlength="200"
  54. >
  55. </u--textarea>
  56. </u-form-item>
  57. </view>
  58. </u-cell>
  59. </view>
  60. <template v-for="(item,index) in model.form.inspectList">
  61. <view class="box" style="padding: 20rpx;" :key="index">
  62. <u-row>
  63. <u-col :span="6">
  64. <view class="font700">{{item.projectName}}</view>
  65. </u-col>
  66. <u-col :span="6">
  67. <view class="disflex">
  68. <text>全选:</text>
  69. <text class="primary">正常</text>
  70. <u-switch
  71. v-model="item.inspectSts"
  72. size="20"
  73. inactiveColor="#007aff"
  74. activeColor="#dd524d"
  75. style="margin: 0 10rpx;"
  76. :active-value="2"
  77. :inactive-value="1"
  78. @change='(e) => {
  79. handleAllChange(item,e)
  80. }'
  81. >
  82. </u-switch>
  83. <text class="error">异常</text>
  84. </view>
  85. </u-col>
  86. </u-row>
  87. <u-row
  88. v-for="(sitem,sindex) in item.itemList"
  89. style="margin: 40rpx 0;">
  90. <u-col :span="6">
  91. <view>{{sitem.itemName}}</view>
  92. </u-col>
  93. <u-col :span="3">
  94. <tq-upload-img
  95. v-model="sitem.pic"
  96. :maxCount="1"
  97. >
  98. </tq-upload-img>
  99. </u-col>
  100. <u-col :span="3">
  101. <u-switch
  102. v-model="sitem.inspectSts"
  103. size="20"
  104. inactiveColor="#007aff"
  105. activeColor="#dd524d"
  106. style="margin: 0 10rpx;"
  107. :active-value="2"
  108. :inactive-value="1"
  109. @change="(e) => {
  110. handleChange(item,e)
  111. }"
  112. >
  113. </u-switch>
  114. </u-col>
  115. </u-row>
  116. </view>
  117. </template>
  118. </u-cell-group>
  119. </u--form>
  120. </view>
  121. <view class="page-footer">
  122. <u-row>
  123. <u-col :span="12" style="padding: 0 0rpx;">
  124. <u-button type="primary" shape="" :custom-style="{
  125. width: '100%',
  126. height: '44px',
  127. borderRadius: '0',
  128. }" @click="handleSubmit">提交
  129. </u-button>
  130. </u-col>
  131. </u-row>
  132. </view>
  133. </view>
  134. </template>
  135. <script>
  136. import {addInspectRec,queryById,queryAllEnableList} from '@/api/vehDispatch/vehInspection.js'
  137. import {clearProps,copyProps} from '@/utils/gdtq.js'
  138. export default {
  139. components: {
  140. },
  141. data() {
  142. return {
  143. model: {
  144. form: {
  145. vehicleId: "",
  146. plate: "",
  147. remark: "",
  148. inspectList: [],
  149. }
  150. },
  151. rules: {
  152. 'form.vehicleId': [
  153. {
  154. type: 'string' ,
  155. required: true,
  156. message: '请选择车辆',
  157. trigger: ['blur', 'change']
  158. },
  159. ],
  160. },
  161. }
  162. },
  163. onLoad({id}) {
  164. // console.log(id,'id')
  165. if(id) {
  166. this.getInfo(id)
  167. } else {
  168. this.getAllEnableList()
  169. }
  170. },
  171. onShow() {
  172. },
  173. onHide() {
  174. },
  175. onReady() {
  176. this.$refs.uForm.setRules(this.rules)
  177. },
  178. methods: {
  179. async getInfo(id) {
  180. let {code,data} = await queryById({id})
  181. if(code == 0) {
  182. copyProps(this.model.form,data)
  183. }
  184. },
  185. async getAllEnableList() {
  186. let {code,data} = await queryAllEnableList({})
  187. if(code == 0) {
  188. this.model.form.inspectList = data
  189. }
  190. },
  191. handleAllChange(item,value) {
  192. item.itemList.forEach((e)=>{
  193. e.inspectSts = value;
  194. })
  195. },
  196. handleChange(item,value) {
  197. let len = item.itemList.length
  198. let nLen = item.itemList.filter(e => e.inspectSts==1).length
  199. item.inspectSts = len == nLen ? 1:2
  200. },
  201. // 提交
  202. async handleSubmit() {
  203. this.$refs.uForm.validate().then(async res => {
  204. let ajaxData = {
  205. ...this.model.form,
  206. }
  207. let { data, code,msg } = await addInspectRec(ajaxData)
  208. if (code == 0) {
  209. uni.showModal({
  210. title: '提示',
  211. content: `提交成功`,
  212. showCancel:false,
  213. confirmText: '好的',
  214. success: function(res) {
  215. if (res.confirm) {
  216. uni.switchTab({url: '/pages/index/index'})
  217. }
  218. }
  219. })
  220. }
  221. }).catch(errors => {
  222. console.log('校验失败',errors)
  223. })
  224. },
  225. }
  226. }
  227. </script>
  228. <style lang="scss" scoped>
  229. .disflex {
  230. display: flex;
  231. }
  232. .font700 {
  233. font-weight: 700;
  234. }
  235. .primary {
  236. color: $uni-color-primary;
  237. }
  238. .error {
  239. color: $uni-color-error;
  240. }
  241. .page-container {
  242. font-size: 28rpx;
  243. min-height: 100%;
  244. position: relative;
  245. // padding-bottom: 60rpx;
  246. .box {
  247. margin: 20rpx;
  248. border-radius: 10rpx;
  249. background: #fff;
  250. }
  251. .page-body {
  252. padding-bottom: 120rpx;
  253. }
  254. .page-footer {
  255. background: #fff;
  256. padding: 0rpx 0;
  257. position: fixed;
  258. width: 100%;
  259. left: 0;
  260. bottom: 0;
  261. }
  262. }
  263. ::v-deep {
  264. .u-cell__body {
  265. .u-cell__body__content {
  266. width: auto;
  267. flex: none;
  268. }
  269. .value {
  270. flex: 1;
  271. .u-form-item__body {
  272. padding: 0;
  273. }
  274. }
  275. .u-form-item__body__right__content__slot {
  276. flex: 1;
  277. justify-content: flex-end;
  278. text-align: right;
  279. }
  280. }
  281. }
  282. </style>